Skip to content

Commit

Permalink
Rename IP_Unix, IP_Address and TCP_Server to remove underscores
Browse files Browse the repository at this point in the history
  • Loading branch information
Calinou committed May 6, 2021
1 parent 758bccf commit 3f078c9
Show file tree
Hide file tree
Showing 60 changed files with 253 additions and 253 deletions.
2 changes: 1 addition & 1 deletion core/debugger/remote_debugger_peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void RemoteDebuggerPeerTCP::_read_in() {
}

Error RemoteDebuggerPeerTCP::connect_to_host(const String &p_host, uint16_t p_port) {
IP_Address ip;
IPAddress ip;
if (p_host.is_valid_ip_address()) {
ip = p_host;
} else {
Expand Down
2 changes: 1 addition & 1 deletion core/io/file_access_network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ void FileAccessNetworkClient::_thread_func(void *s) {
}

Error FileAccessNetworkClient::connect(const String &p_host, int p_port, const String &p_password) {
IP_Address ip;
IPAddress ip;

if (p_host.is_valid_ip_address()) {
ip = p_host;
Expand Down
4 changes: 2 additions & 2 deletions core/io/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Error HTTPClient::connect_to_host(const String &p_host, int p_port, bool p_ssl,

if (conn_host.is_valid_ip_address()) {
// Host contains valid IP
Error err = tcp_connection->connect_to_host(IP_Address(conn_host), p_port);
Error err = tcp_connection->connect_to_host(IPAddress(conn_host), p_port);
if (err) {
status = STATUS_CANT_CONNECT;
return err;
Expand Down Expand Up @@ -328,7 +328,7 @@ Error HTTPClient::poll() {
return OK; // Still resolving

case IP::RESOLVER_STATUS_DONE: {
IP_Address host = IP::get_singleton()->get_resolve_item_address(resolving);
IPAddress host = IP::get_singleton()->get_resolve_item_address(resolving);
Error err = tcp_connection->connect_to_host(host, conn_port);
IP::get_singleton()->erase_resolve_item(resolving);
resolving = IP::RESOLVER_INVALID_ID;
Expand Down
30 changes: 15 additions & 15 deletions core/io/ip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ VARIANT_ENUM_CAST(IP::ResolverStatus);
struct _IP_ResolverPrivate {
struct QueueItem {
SafeNumeric<IP::ResolverStatus> status;
IP_Address response;
IPAddress response;
String hostname;
IP::Type type;

void clear() {
status.set(IP::RESOLVER_STATUS_NONE);
response = IP_Address();
response = IPAddress();
type = IP::TYPE_NONE;
hostname = "";
};
Expand Down Expand Up @@ -101,23 +101,23 @@ struct _IP_ResolverPrivate {
}
}

HashMap<String, IP_Address> cache;
HashMap<String, IPAddress> cache;

static String get_cache_key(String p_hostname, IP::Type p_type) {
return itos(p_type) + p_hostname;
}
};

IP_Address IP::resolve_hostname(const String &p_hostname, IP::Type p_type) {
IPAddress IP::resolve_hostname(const String &p_hostname, IP::Type p_type) {
MutexLock lock(resolver->mutex);

String key = _IP_ResolverPrivate::get_cache_key(p_hostname, p_type);
if (resolver->cache.has(key) && resolver->cache[key].is_valid()) {
IP_Address res = resolver->cache[key];
IPAddress res = resolver->cache[key];
return res;
}

IP_Address res = _resolve_hostname(p_hostname, p_type);
IPAddress res = _resolve_hostname(p_hostname, p_type);
resolver->cache[key] = res;
return res;
}
Expand All @@ -139,7 +139,7 @@ IP::ResolverID IP::resolve_hostname_queue_item(const String &p_hostname, IP::Typ
resolver->queue[id].response = resolver->cache[key];
resolver->queue[id].status.set(IP::RESOLVER_STATUS_DONE);
} else {
resolver->queue[id].response = IP_Address();
resolver->queue[id].response = IPAddress();
resolver->queue[id].status.set(IP::RESOLVER_STATUS_WAITING);
if (resolver->thread.is_started()) {
resolver->sem.post();
Expand All @@ -164,15 +164,15 @@ IP::ResolverStatus IP::get_resolve_item_status(ResolverID p_id) const {
return resolver->queue[p_id].status.get();
}

IP_Address IP::get_resolve_item_address(ResolverID p_id) const {
ERR_FAIL_INDEX_V(p_id, IP::RESOLVER_MAX_QUERIES, IP_Address());
IPAddress IP::get_resolve_item_address(ResolverID p_id) const {
ERR_FAIL_INDEX_V(p_id, IP::RESOLVER_MAX_QUERIES, IPAddress());

MutexLock lock(resolver->mutex);

if (resolver->queue[p_id].status.get() != IP::RESOLVER_STATUS_DONE) {
ERR_PRINT("Resolve of '" + resolver->queue[p_id].hostname + "'' didn't complete yet.");
resolver->mutex.unlock();
return IP_Address();
return IPAddress();
}

return resolver->queue[p_id].response;
Expand Down Expand Up @@ -201,9 +201,9 @@ void IP::clear_cache(const String &p_hostname) {

Array IP::_get_local_addresses() const {
Array addresses;
List<IP_Address> ip_addresses;
List<IPAddress> ip_addresses;
get_local_addresses(&ip_addresses);
for (List<IP_Address>::Element *E = ip_addresses.front(); E; E = E->next()) {
for (List<IPAddress>::Element *E = ip_addresses.front(); E; E = E->next()) {
addresses.push_back(E->get());
}

Expand All @@ -222,7 +222,7 @@ Array IP::_get_local_interfaces() const {
rc["index"] = c.index;

Array ips;
for (const List<IP_Address>::Element *F = c.ip_addresses.front(); F; F = F->next()) {
for (const List<IPAddress>::Element *F = c.ip_addresses.front(); F; F = F->next()) {
ips.push_front(F->get());
}
rc["addresses"] = ips;
Expand All @@ -233,11 +233,11 @@ Array IP::_get_local_interfaces() const {
return results;
}

void IP::get_local_addresses(List<IP_Address> *r_addresses) const {
void IP::get_local_addresses(List<IPAddress> *r_addresses) const {
Map<String, Interface_Info> interfaces;
get_local_interfaces(&interfaces);
for (Map<String, Interface_Info>::Element *E = interfaces.front(); E; E = E->next()) {
for (const List<IP_Address>::Element *F = E->get().ip_addresses.front(); F; F = F->next()) {
for (const List<IPAddress>::Element *F = E->get().ip_addresses.front(); F; F = F->next()) {
r_addresses->push_front(F->get());
}
}
Expand Down
10 changes: 5 additions & 5 deletions core/io/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class IP : public Object {
static IP *singleton;
static void _bind_methods();

virtual IP_Address _resolve_hostname(const String &p_hostname, Type p_type = TYPE_ANY) = 0;
virtual IPAddress _resolve_hostname(const String &p_hostname, Type p_type = TYPE_ANY) = 0;
Array _get_local_addresses() const;
Array _get_local_interfaces() const;

Expand All @@ -80,15 +80,15 @@ class IP : public Object {
String name;
String name_friendly;
String index;
List<IP_Address> ip_addresses;
List<IPAddress> ip_addresses;
};

IP_Address resolve_hostname(const String &p_hostname, Type p_type = TYPE_ANY);
IPAddress resolve_hostname(const String &p_hostname, Type p_type = TYPE_ANY);
// async resolver hostname
ResolverID resolve_hostname_queue_item(const String &p_hostname, Type p_type = TYPE_ANY);
ResolverStatus get_resolve_item_status(ResolverID p_id) const;
IP_Address get_resolve_item_address(ResolverID p_id) const;
virtual void get_local_addresses(List<IP_Address> *r_addresses) const;
IPAddress get_resolve_item_address(ResolverID p_id) const;
virtual void get_local_addresses(List<IPAddress> *r_addresses) const;
virtual void get_local_interfaces(Map<String, Interface_Info> *r_interfaces) const = 0;
void erase_resolve_item(ResolverID p_id);

Expand Down
24 changes: 12 additions & 12 deletions core/io/ip_address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@

#include "ip_address.h"
/*
IP_Address::operator Variant() const {
IPAddress::operator Variant() const {
return operator String();
}*/

#include <stdio.h>
#include <string.h>

IP_Address::operator String() const {
IPAddress::operator String() const {
if (wildcard) {
return "*";
}
Expand Down Expand Up @@ -90,7 +90,7 @@ static void _parse_hex(const String &p_string, int p_start, uint8_t *p_dst) {
p_dst[1] = ret & 0xff;
}

void IP_Address::_parse_ipv6(const String &p_string) {
void IPAddress::_parse_ipv6(const String &p_string) {
static const int parts_total = 8;
int parts[parts_total] = { 0 };
int parts_count = 0;
Expand Down Expand Up @@ -146,7 +146,7 @@ void IP_Address::_parse_ipv6(const String &p_string) {
}
}

void IP_Address::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret) {
void IPAddress::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret) {
String ip;
if (p_start != 0) {
ip = p_string.substr(p_start, p_string.length() - p_start);
Expand All @@ -161,41 +161,41 @@ void IP_Address::_parse_ipv4(const String &p_string, int p_start, uint8_t *p_ret
}
}

void IP_Address::clear() {
void IPAddress::clear() {
memset(&field8[0], 0, sizeof(field8));
valid = false;
wildcard = false;
}

bool IP_Address::is_ipv4() const {
bool IPAddress::is_ipv4() const {
return (field32[0] == 0 && field32[1] == 0 && field16[4] == 0 && field16[5] == 0xffff);
}

const uint8_t *IP_Address::get_ipv4() const {
const uint8_t *IPAddress::get_ipv4() const {
ERR_FAIL_COND_V_MSG(!is_ipv4(), &(field8[12]), "IPv4 requested, but current IP is IPv6."); // Not the correct IPv4 (it's an IPv6), but we don't want to return a null pointer risking an engine crash.
return &(field8[12]);
}

void IP_Address::set_ipv4(const uint8_t *p_ip) {
void IPAddress::set_ipv4(const uint8_t *p_ip) {
clear();
valid = true;
field16[5] = 0xffff;
field32[3] = *((const uint32_t *)p_ip);
}

const uint8_t *IP_Address::get_ipv6() const {
const uint8_t *IPAddress::get_ipv6() const {
return field8;
}

void IP_Address::set_ipv6(const uint8_t *p_buf) {
void IPAddress::set_ipv6(const uint8_t *p_buf) {
clear();
valid = true;
for (int i = 0; i < 16; i++) {
field8[i] = p_buf[i];
}
}

IP_Address::IP_Address(const String &p_string) {
IPAddress::IPAddress(const String &p_string) {
clear();

if (p_string == "*") {
Expand Down Expand Up @@ -225,7 +225,7 @@ _FORCE_INLINE_ static void _32_to_buf(uint8_t *p_dst, uint32_t p_n) {
p_dst[3] = (p_n >> 0) & 0xff;
}

IP_Address::IP_Address(uint32_t p_a, uint32_t p_b, uint32_t p_c, uint32_t p_d, bool is_v6) {
IPAddress::IPAddress(uint32_t p_a, uint32_t p_b, uint32_t p_c, uint32_t p_d, bool is_v6) {
clear();
valid = true;
if (!is_v6) {
Expand Down
12 changes: 6 additions & 6 deletions core/io/ip_address.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#include "core/string/ustring.h"

struct IP_Address {
struct IPAddress {
private:
union {
uint8_t field8[16];
Expand All @@ -50,7 +50,7 @@ struct IP_Address {

public:
//operator Variant() const;
bool operator==(const IP_Address &p_ip) const {
bool operator==(const IPAddress &p_ip) const {
if (p_ip.valid != valid) {
return false;
}
Expand All @@ -65,7 +65,7 @@ struct IP_Address {
return true;
}

bool operator!=(const IP_Address &p_ip) const {
bool operator!=(const IPAddress &p_ip) const {
if (p_ip.valid != valid) {
return true;
}
Expand All @@ -91,9 +91,9 @@ struct IP_Address {
void set_ipv6(const uint8_t *p_buf);

operator String() const;
IP_Address(const String &p_string);
IP_Address(uint32_t p_a, uint32_t p_b, uint32_t p_c, uint32_t p_d, bool is_v6 = false);
IP_Address() { clear(); }
IPAddress(const String &p_string);
IPAddress(uint32_t p_a, uint32_t p_b, uint32_t p_c, uint32_t p_d, bool is_v6 = false);
IPAddress() { clear(); }
};

#endif // IP_ADDRESS_H
16 changes: 8 additions & 8 deletions core/io/net_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,27 @@ class NetSocket : public Reference {

virtual Error open(Type p_type, IP::Type &ip_type) = 0;
virtual void close() = 0;
virtual Error bind(IP_Address p_addr, uint16_t p_port) = 0;
virtual Error bind(IPAddress p_addr, uint16_t p_port) = 0;
virtual Error listen(int p_max_pending) = 0;
virtual Error connect_to_host(IP_Address p_addr, uint16_t p_port) = 0;
virtual Error connect_to_host(IPAddress p_addr, uint16_t p_port) = 0;
virtual Error poll(PollType p_type, int timeout) const = 0;
virtual Error recv(uint8_t *p_buffer, int p_len, int &r_read) = 0;
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) = 0;
virtual Error recvfrom(uint8_t *p_buffer, int p_len, int &r_read, IPAddress &r_ip, uint16_t &r_port, bool p_peek = false) = 0;
virtual Error send(const uint8_t *p_buffer, int p_len, int &r_sent) = 0;
virtual Error sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP_Address p_ip, uint16_t p_port) = 0;
virtual Ref<NetSocket> accept(IP_Address &r_ip, uint16_t &r_port) = 0;
virtual Error sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IPAddress p_ip, uint16_t p_port) = 0;
virtual Ref<NetSocket> accept(IPAddress &r_ip, uint16_t &r_port) = 0;

virtual bool is_open() const = 0;
virtual int get_available_bytes() const = 0;
virtual Error get_socket_address(IP_Address *r_ip, uint16_t *r_port) const = 0;
virtual Error get_socket_address(IPAddress *r_ip, uint16_t *r_port) const = 0;

virtual Error set_broadcasting_enabled(bool p_enabled) = 0; // Returns OK if the socket option has been set successfully.
virtual void set_blocking_enabled(bool p_enabled) = 0;
virtual void set_ipv6_only_enabled(bool p_enabled) = 0;
virtual void set_tcp_no_delay_enabled(bool p_enabled) = 0;
virtual void set_reuse_address_enabled(bool p_enabled) = 0;
virtual Error join_multicast_group(const IP_Address &p_multi_address, String p_if_name) = 0;
virtual Error leave_multicast_group(const IP_Address &p_multi_address, String p_if_name) = 0;
virtual Error join_multicast_group(const IPAddress &p_multi_address, String p_if_name) = 0;
virtual Error leave_multicast_group(const IPAddress &p_multi_address, String p_if_name) = 0;
};

#endif // NET_SOCKET_H
Loading

0 comments on commit 3f078c9

Please sign in to comment.