godot/drivers/unix/net_socket_posix.cpp

/**************************************************************************/
/*  net_socket_posix.cpp                                                  */
/**************************************************************************/
/*                         This file is part of:                          */
/*                             GODOT ENGINE                               */
/*                        https://godotengine.org                         */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */
/*                                                                        */
/* Permission is hereby granted, free of charge, to any person obtaining  */
/* a copy of this software and associated documentation files (the        */
/* "Software"), to deal in the Software without restriction, including    */
/* without limitation the rights to use, copy, modify, merge, publish,    */
/* distribute, sublicense, and/or sell copies of the Software, and to     */
/* permit persons to whom the Software is furnished to do so, subject to  */
/* the following conditions:                                              */
/*                                                                        */
/* The above copyright notice and this permission notice shall be         */
/* included in all copies or substantial portions of the Software.        */
/*                                                                        */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */
/**************************************************************************/

#include "net_socket_posix.h"

// Some proprietary Unix-derived platforms don't expose Unix sockets
// so this allows skipping this file to reimplement this API differently.
#ifndef UNIX_SOCKET_UNAVAILABLE

#if defined(UNIX_ENABLED)

#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>

#ifdef WEB_ENABLED
#include <arpa/inet.h>
#endif

// BSD calls this flag IPV6_JOIN_GROUP
#if !defined(IPV6_ADD_MEMBERSHIP) && defined(IPV6_JOIN_GROUP)
#define IPV6_ADD_MEMBERSHIP
#endif
#if !defined(IPV6_DROP_MEMBERSHIP) && defined(IPV6_LEAVE_GROUP)
#define IPV6_DROP_MEMBERSHIP
#endif

// Some custom defines to minimize ifdefs
#define SOCK_EMPTY
#define SOCK_BUF(x)
#define SOCK_CBUF(x)
#define SOCK_IOCTL
#define SOCK_FIONREAD_LEN_TYPE
#define SOCK_CLOSE
#define SOCK_CONNECT(p_sock, p_addr, p_addr_len)

/* Windows */
#elif defined(WINDOWS_ENABLED)
#include <winsock2.h>
#include <ws2tcpip.h>

#include <mswsock.h>
// Some custom defines to minimize ifdefs
#define SOCK_EMPTY
#define SOCK_BUF
#define SOCK_CBUF
#define SOCK_IOCTL
#define SOCK_FIONREAD_LEN_TYPE
#define SOCK_CLOSE
// connect is broken on windows under certain conditions, reasons unknown:
// See https://github.com/godotengine/webrtc-native/issues/6
#define SOCK_CONNECT

// Workaround missing flag in MinGW
#if defined(__MINGW32__) && !defined(SIO_UDP_NETRESET)
#define SIO_UDP_NETRESET
#endif

#endif // UNIX_ENABLED

size_t NetSocketPosix::_set_addr_storage(struct sockaddr_storage *p_addr, const IPAddress &p_ip, uint16_t p_port, IP::Type p_ip_type) {}

void NetSocketPosix::_set_ip_port(struct sockaddr_storage *p_addr, IPAddress *r_ip, uint16_t *r_port) {}

NetSocket *NetSocketPosix::_create_func() {}

void NetSocketPosix::make_default() {}

void NetSocketPosix::cleanup() {}

NetSocketPosix::NetSocketPosix() :{}

NetSocketPosix::~NetSocketPosix() {}

// Silence a warning reported in GH-27594.
// EAGAIN and EWOULDBLOCK have the same value on most platforms, but it's not guaranteed.
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wlogical-op"
#endif

NetSocketPosix::NetError NetSocketPosix::_get_socket_error() const {}

#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif

bool NetSocketPosix::_can_use_ip(const IPAddress &p_ip, const bool p_for_bind) const {}

_FORCE_INLINE_ Error NetSocketPosix::_change_multicast_group(IPAddress p_ip, String p_if_name, bool p_add) {}

void NetSocketPosix::_set_socket(SOCKET_TYPE p_sock, IP::Type p_ip_type, bool p_is_stream) {}

void NetSocketPosix::_set_close_exec_enabled(bool p_enabled) {}

Error NetSocketPosix::open(Type p_sock_type, IP::Type &ip_type) {}

void NetSocketPosix::close() {}

Error NetSocketPosix::bind(IPAddress p_addr, uint16_t p_port) {}

Error NetSocketPosix::listen(int p_max_pending) {}

Error NetSocketPosix::connect_to_host(IPAddress p_host, uint16_t p_port) {}

Error NetSocketPosix::poll(PollType p_type, int p_timeout) const {}

Error NetSocketPosix::recv(uint8_t *p_buffer, int p_len, int &r_read) {}

Error NetSocketPosix::recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IPAddress &r_ip, uint16_t &r_port, bool p_peek) {}

Error NetSocketPosix::send(const uint8_t *p_buffer, int p_len, int &r_sent) {}

Error NetSocketPosix::sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IPAddress p_ip, uint16_t p_port) {}

Error NetSocketPosix::set_broadcasting_enabled(bool p_enabled) {}

void NetSocketPosix::set_blocking_enabled(bool p_enabled) {}

void NetSocketPosix::set_ipv6_only_enabled(bool p_enabled) {}

void NetSocketPosix::set_tcp_no_delay_enabled(bool p_enabled) {}

void NetSocketPosix::set_reuse_address_enabled(bool p_enabled) {}

void NetSocketPosix::set_reuse_port_enabled(bool p_enabled) {}

bool NetSocketPosix::is_open() const {}

int NetSocketPosix::get_available_bytes() const {}

Error NetSocketPosix::get_socket_address(IPAddress *r_ip, uint16_t *r_port) const {}

Ref<NetSocket> NetSocketPosix::accept(IPAddress &r_ip, uint16_t &r_port) {}

Error NetSocketPosix::join_multicast_group(const IPAddress &p_multi_address, const String &p_if_name) {}

Error NetSocketPosix::leave_multicast_group(const IPAddress &p_multi_address, const String &p_if_name) {}

#endif // UNIX_SOCKET_UNAVAILABLE