Rename IP_Unix, IP_Address and TCP_Server to remove underscores
This commit is contained in:
@ -75,8 +75,8 @@
|
||||
#include <net/if.h> // Order is important on OpenBSD, leave as last
|
||||
#endif
|
||||
|
||||
static IP_Address _sockaddr2ip(struct sockaddr *p_addr) {
|
||||
IP_Address ip;
|
||||
static IPAddress _sockaddr2ip(struct sockaddr *p_addr) {
|
||||
IPAddress ip;
|
||||
|
||||
if (p_addr->sa_family == AF_INET) {
|
||||
struct sockaddr_in *addr = (struct sockaddr_in *)p_addr;
|
||||
@ -89,7 +89,7 @@ static IP_Address _sockaddr2ip(struct sockaddr *p_addr) {
|
||||
return ip;
|
||||
};
|
||||
|
||||
IP_Address IP_Unix::_resolve_hostname(const String &p_hostname, Type p_type) {
|
||||
IPAddress IPUnix::_resolve_hostname(const String &p_hostname, Type p_type) {
|
||||
struct addrinfo hints;
|
||||
struct addrinfo *result = nullptr;
|
||||
|
||||
@ -108,7 +108,7 @@ IP_Address IP_Unix::_resolve_hostname(const String &p_hostname, Type p_type) {
|
||||
int s = getaddrinfo(p_hostname.utf8().get_data(), nullptr, &hints, &result);
|
||||
if (s != 0) {
|
||||
ERR_PRINT("getaddrinfo failed! Cannot resolve hostname.");
|
||||
return IP_Address();
|
||||
return IPAddress();
|
||||
};
|
||||
|
||||
if (result == nullptr || result->ai_addr == nullptr) {
|
||||
@ -116,10 +116,10 @@ IP_Address IP_Unix::_resolve_hostname(const String &p_hostname, Type p_type) {
|
||||
if (result) {
|
||||
freeaddrinfo(result);
|
||||
}
|
||||
return IP_Address();
|
||||
return IPAddress();
|
||||
};
|
||||
|
||||
IP_Address ip = _sockaddr2ip(result->ai_addr);
|
||||
IPAddress ip = _sockaddr2ip(result->ai_addr);
|
||||
|
||||
freeaddrinfo(result);
|
||||
|
||||
@ -130,7 +130,7 @@ IP_Address IP_Unix::_resolve_hostname(const String &p_hostname, Type p_type) {
|
||||
|
||||
#if defined(UWP_ENABLED)
|
||||
|
||||
void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const {
|
||||
void IPUnix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const {
|
||||
using namespace Windows::Networking;
|
||||
using namespace Windows::Networking::Connectivity;
|
||||
|
||||
@ -156,14 +156,14 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co
|
||||
|
||||
Interface_Info &info = E->get();
|
||||
|
||||
IP_Address ip = IP_Address(hostname->CanonicalName->Data());
|
||||
IPAddress ip = IPAddress(hostname->CanonicalName->Data());
|
||||
info.ip_addresses.push_front(ip);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const {
|
||||
void IPUnix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const {
|
||||
ULONG buf_size = 1024;
|
||||
IP_ADAPTER_ADDRESSES *addrs;
|
||||
|
||||
@ -211,7 +211,7 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co
|
||||
|
||||
#else // UNIX
|
||||
|
||||
void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const {
|
||||
void IPUnix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const {
|
||||
struct ifaddrs *ifAddrStruct = nullptr;
|
||||
struct ifaddrs *ifa = nullptr;
|
||||
int family;
|
||||
@ -249,15 +249,15 @@ void IP_Unix::get_local_interfaces(Map<String, Interface_Info> *r_interfaces) co
|
||||
}
|
||||
#endif
|
||||
|
||||
void IP_Unix::make_default() {
|
||||
void IPUnix::make_default() {
|
||||
_create = _create_unix;
|
||||
}
|
||||
|
||||
IP *IP_Unix::_create_unix() {
|
||||
return memnew(IP_Unix);
|
||||
IP *IPUnix::_create_unix() {
|
||||
return memnew(IPUnix);
|
||||
}
|
||||
|
||||
IP_Unix::IP_Unix() {
|
||||
IPUnix::IPUnix() {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -35,10 +35,10 @@
|
||||
|
||||
#if defined(UNIX_ENABLED) || defined(WINDOWS_ENABLED)
|
||||
|
||||
class IP_Unix : public IP {
|
||||
GDCLASS(IP_Unix, IP);
|
||||
class IPUnix : public IP {
|
||||
GDCLASS(IPUnix, IP);
|
||||
|
||||
virtual IP_Address _resolve_hostname(const String &p_hostname, IP::Type p_type) override;
|
||||
virtual IPAddress _resolve_hostname(const String &p_hostname, IP::Type p_type) override;
|
||||
|
||||
static IP *_create_unix();
|
||||
|
||||
@ -46,7 +46,7 @@ public:
|
||||
virtual void get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const override;
|
||||
|
||||
static void make_default();
|
||||
IP_Unix();
|
||||
IPUnix();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -95,7 +95,7 @@
|
||||
|
||||
#endif
|
||||
|
||||
size_t NetSocketPosix::_set_addr_storage(struct sockaddr_storage *p_addr, const IP_Address &p_ip, uint16_t p_port, IP::Type p_ip_type) {
|
||||
size_t NetSocketPosix::_set_addr_storage(struct sockaddr_storage *p_addr, const IPAddress &p_ip, uint16_t p_port, IP::Type p_ip_type) {
|
||||
memset(p_addr, 0, sizeof(struct sockaddr_storage));
|
||||
if (p_ip_type == IP::TYPE_IPV6 || p_ip_type == IP::TYPE_ANY) { // IPv6 socket
|
||||
|
||||
@ -130,7 +130,7 @@ size_t NetSocketPosix::_set_addr_storage(struct sockaddr_storage *p_addr, const
|
||||
}
|
||||
}
|
||||
|
||||
void NetSocketPosix::_set_ip_port(struct sockaddr_storage *p_addr, IP_Address *r_ip, uint16_t *r_port) {
|
||||
void NetSocketPosix::_set_ip_port(struct sockaddr_storage *p_addr, IPAddress *r_ip, uint16_t *r_port) {
|
||||
if (p_addr->ss_family == AF_INET) {
|
||||
struct sockaddr_in *addr4 = (struct sockaddr_in *)p_addr;
|
||||
if (r_ip) {
|
||||
@ -233,7 +233,7 @@ NetSocketPosix::NetError NetSocketPosix::_get_socket_error() const {
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
bool NetSocketPosix::_can_use_ip(const IP_Address &p_ip, const bool p_for_bind) const {
|
||||
bool NetSocketPosix::_can_use_ip(const IPAddress &p_ip, const bool p_for_bind) const {
|
||||
if (p_for_bind && !(p_ip.is_valid() || p_ip.is_wildcard())) {
|
||||
return false;
|
||||
} else if (!p_for_bind && !p_ip.is_valid()) {
|
||||
@ -244,7 +244,7 @@ bool NetSocketPosix::_can_use_ip(const IP_Address &p_ip, const bool p_for_bind)
|
||||
return !(_ip_type != IP::TYPE_ANY && !p_ip.is_wildcard() && _ip_type != type);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ Error NetSocketPosix::_change_multicast_group(IP_Address p_ip, String p_if_name, bool p_add) {
|
||||
_FORCE_INLINE_ Error NetSocketPosix::_change_multicast_group(IPAddress p_ip, String p_if_name, bool p_add) {
|
||||
ERR_FAIL_COND_V(!is_open(), ERR_UNCONFIGURED);
|
||||
ERR_FAIL_COND_V(!_can_use_ip(p_ip, false), ERR_INVALID_PARAMETER);
|
||||
|
||||
@ -254,7 +254,7 @@ _FORCE_INLINE_ Error NetSocketPosix::_change_multicast_group(IP_Address p_ip, St
|
||||
int level = type == IP::TYPE_IPV4 ? IPPROTO_IP : IPPROTO_IPV6;
|
||||
int ret = -1;
|
||||
|
||||
IP_Address if_ip;
|
||||
IPAddress if_ip;
|
||||
uint32_t if_v6id = 0;
|
||||
Map<String, IP::Interface_Info> if_info;
|
||||
IP::get_singleton()->get_local_interfaces(&if_info);
|
||||
@ -269,7 +269,7 @@ _FORCE_INLINE_ Error NetSocketPosix::_change_multicast_group(IP_Address p_ip, St
|
||||
break; // IPv6 uses index.
|
||||
}
|
||||
|
||||
for (List<IP_Address>::Element *F = c.ip_addresses.front(); F; F = F->next()) {
|
||||
for (List<IPAddress>::Element *F = c.ip_addresses.front(); F; F = F->next()) {
|
||||
if (!F->get().is_ipv4()) {
|
||||
continue; // Wrong IP type
|
||||
}
|
||||
@ -395,7 +395,7 @@ void NetSocketPosix::close() {
|
||||
_is_stream = false;
|
||||
}
|
||||
|
||||
Error NetSocketPosix::bind(IP_Address p_addr, uint16_t p_port) {
|
||||
Error NetSocketPosix::bind(IPAddress p_addr, uint16_t p_port) {
|
||||
ERR_FAIL_COND_V(!is_open(), ERR_UNCONFIGURED);
|
||||
ERR_FAIL_COND_V(!_can_use_ip(p_addr, true), ERR_INVALID_PARAMETER);
|
||||
|
||||
@ -425,7 +425,7 @@ Error NetSocketPosix::listen(int p_max_pending) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error NetSocketPosix::connect_to_host(IP_Address p_host, uint16_t p_port) {
|
||||
Error NetSocketPosix::connect_to_host(IPAddress p_host, uint16_t p_port) {
|
||||
ERR_FAIL_COND_V(!is_open(), ERR_UNCONFIGURED);
|
||||
ERR_FAIL_COND_V(!_can_use_ip(p_host, false), ERR_INVALID_PARAMETER);
|
||||
|
||||
@ -559,7 +559,7 @@ Error NetSocketPosix::recv(uint8_t *p_buffer, int p_len, int &r_read) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error NetSocketPosix::recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IP_Address &r_ip, uint16_t &r_port, bool p_peek) {
|
||||
Error NetSocketPosix::recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IPAddress &r_ip, uint16_t &r_port, bool p_peek) {
|
||||
ERR_FAIL_COND_V(!is_open(), ERR_UNCONFIGURED);
|
||||
|
||||
struct sockaddr_storage from;
|
||||
@ -616,7 +616,7 @@ Error NetSocketPosix::send(const uint8_t *p_buffer, int p_len, int &r_sent) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
Error NetSocketPosix::sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP_Address p_ip, uint16_t p_port) {
|
||||
Error NetSocketPosix::sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IPAddress p_ip, uint16_t p_port) {
|
||||
ERR_FAIL_COND_V(!is_open(), ERR_UNCONFIGURED);
|
||||
|
||||
struct sockaddr_storage addr;
|
||||
@ -735,7 +735,7 @@ int NetSocketPosix::get_available_bytes() const {
|
||||
return len;
|
||||
}
|
||||
|
||||
Error NetSocketPosix::get_socket_address(IP_Address *r_ip, uint16_t *r_port) const {
|
||||
Error NetSocketPosix::get_socket_address(IPAddress *r_ip, uint16_t *r_port) const {
|
||||
ERR_FAIL_COND_V(!is_open(), FAILED);
|
||||
|
||||
struct sockaddr_storage saddr;
|
||||
@ -749,7 +749,7 @@ Error NetSocketPosix::get_socket_address(IP_Address *r_ip, uint16_t *r_port) con
|
||||
return OK;
|
||||
}
|
||||
|
||||
Ref<NetSocket> NetSocketPosix::accept(IP_Address &r_ip, uint16_t &r_port) {
|
||||
Ref<NetSocket> NetSocketPosix::accept(IPAddress &r_ip, uint16_t &r_port) {
|
||||
Ref<NetSocket> out;
|
||||
ERR_FAIL_COND_V(!is_open(), out);
|
||||
|
||||
@ -770,11 +770,11 @@ Ref<NetSocket> NetSocketPosix::accept(IP_Address &r_ip, uint16_t &r_port) {
|
||||
return Ref<NetSocket>(ns);
|
||||
}
|
||||
|
||||
Error NetSocketPosix::join_multicast_group(const IP_Address &p_multi_address, String p_if_name) {
|
||||
Error NetSocketPosix::join_multicast_group(const IPAddress &p_multi_address, String p_if_name) {
|
||||
return _change_multicast_group(p_multi_address, p_if_name, true);
|
||||
}
|
||||
|
||||
Error NetSocketPosix::leave_multicast_group(const IP_Address &p_multi_address, String p_if_name) {
|
||||
Error NetSocketPosix::leave_multicast_group(const IPAddress &p_multi_address, String p_if_name) {
|
||||
return _change_multicast_group(p_multi_address, p_if_name, false);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -61,35 +61,35 @@ private:
|
||||
|
||||
NetError _get_socket_error() const;
|
||||
void _set_socket(SOCKET_TYPE p_sock, IP::Type p_ip_type, bool p_is_stream);
|
||||
_FORCE_INLINE_ Error _change_multicast_group(IP_Address p_ip, String p_if_name, bool p_add);
|
||||
_FORCE_INLINE_ Error _change_multicast_group(IPAddress p_ip, String p_if_name, bool p_add);
|
||||
_FORCE_INLINE_ void _set_close_exec_enabled(bool p_enabled);
|
||||
|
||||
protected:
|
||||
static NetSocket *_create_func();
|
||||
|
||||
bool _can_use_ip(const IP_Address &p_ip, const bool p_for_bind) const;
|
||||
bool _can_use_ip(const IPAddress &p_ip, const bool p_for_bind) const;
|
||||
|
||||
public:
|
||||
static void make_default();
|
||||
static void cleanup();
|
||||
static void _set_ip_port(struct sockaddr_storage *p_addr, IP_Address *r_ip, uint16_t *r_port);
|
||||
static size_t _set_addr_storage(struct sockaddr_storage *p_addr, const IP_Address &p_ip, uint16_t p_port, IP::Type p_ip_type);
|
||||
static void _set_ip_port(struct sockaddr_storage *p_addr, IPAddress *r_ip, uint16_t *r_port);
|
||||
static size_t _set_addr_storage(struct sockaddr_storage *p_addr, const IPAddress &p_ip, uint16_t p_port, IP::Type p_ip_type);
|
||||
|
||||
virtual Error open(Type p_sock_type, IP::Type &ip_type);
|
||||
virtual void close();
|
||||
virtual Error bind(IP_Address p_addr, uint16_t p_port);
|
||||
virtual Error bind(IPAddress p_addr, uint16_t p_port);
|
||||
virtual Error listen(int p_max_pending);
|
||||
virtual Error connect_to_host(IP_Address p_host, uint16_t p_port);
|
||||
virtual Error connect_to_host(IPAddress p_host, uint16_t p_port);
|
||||
virtual Error poll(PollType p_type, int timeout) const;
|
||||
virtual Error recv(uint8_t *p_buffer, int p_len, int &r_read);
|
||||
virtual Error recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IP_Address &r_ip, uint16_t &r_port, bool p_peek = false);
|
||||
virtual Error recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IPAddress &r_ip, uint16_t &r_port, bool p_peek = false);
|
||||
virtual Error send(const uint8_t *p_buffer, int p_len, int &r_sent);
|
||||
virtual Error sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP_Address p_ip, uint16_t p_port);
|
||||
virtual Ref<NetSocket> accept(IP_Address &r_ip, uint16_t &r_port);
|
||||
virtual Error sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IPAddress p_ip, uint16_t p_port);
|
||||
virtual Ref<NetSocket> accept(IPAddress &r_ip, uint16_t &r_port);
|
||||
|
||||
virtual bool is_open() const;
|
||||
virtual int get_available_bytes() const;
|
||||
virtual Error get_socket_address(IP_Address *r_ip, uint16_t *r_port) const;
|
||||
virtual Error get_socket_address(IPAddress *r_ip, uint16_t *r_port) const;
|
||||
|
||||
virtual Error set_broadcasting_enabled(bool p_enabled);
|
||||
virtual void set_blocking_enabled(bool p_enabled);
|
||||
@ -97,8 +97,8 @@ public:
|
||||
virtual void set_tcp_no_delay_enabled(bool p_enabled);
|
||||
virtual void set_reuse_address_enabled(bool p_enabled);
|
||||
virtual void set_reuse_port_enabled(bool p_enabled);
|
||||
virtual Error join_multicast_group(const IP_Address &p_multi_address, String p_if_name);
|
||||
virtual Error leave_multicast_group(const IP_Address &p_multi_address, String p_if_name);
|
||||
virtual Error join_multicast_group(const IPAddress &p_multi_address, String p_if_name);
|
||||
virtual Error leave_multicast_group(const IPAddress &p_multi_address, String p_if_name);
|
||||
|
||||
NetSocketPosix();
|
||||
~NetSocketPosix();
|
||||
|
||||
@ -129,7 +129,7 @@ void OS_Unix::initialize_core() {
|
||||
|
||||
#ifndef NO_NETWORK
|
||||
NetSocketPosix::make_default();
|
||||
IP_Unix::make_default();
|
||||
IPUnix::make_default();
|
||||
#endif
|
||||
|
||||
_setup_clock();
|
||||
|
||||
Reference in New Issue
Block a user