summaryrefslogtreecommitdiff
path: root/core/io
diff options
context:
space:
mode:
Diffstat (limited to 'core/io')
-rw-r--r--core/io/file_access_network.cpp2
-rw-r--r--core/io/http_client.cpp4
-rw-r--r--core/io/ip.cpp30
-rw-r--r--core/io/ip.h10
-rw-r--r--core/io/ip_address.cpp24
-rw-r--r--core/io/ip_address.h12
-rw-r--r--core/io/net_socket.h16
-rw-r--r--core/io/packed_data_container.cpp5
-rw-r--r--core/io/packet_peer_udp.cpp20
-rw-r--r--core/io/packet_peer_udp.h20
-rw-r--r--core/io/resource_loader.cpp11
-rw-r--r--core/io/stream_peer_tcp.cpp12
-rw-r--r--core/io/stream_peer_tcp.h10
-rw-r--r--core/io/tcp_server.cpp32
-rw-r--r--core/io/tcp_server.h10
-rw-r--r--core/io/udp_server.cpp6
-rw-r--r--core/io/udp_server.h6
17 files changed, 117 insertions, 113 deletions
diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp
index 31b7d658d0..4cc73bcd22 100644
--- a/core/io/file_access_network.cpp
+++ b/core/io/file_access_network.cpp
@@ -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;
diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp
index 4b053d576c..0cf870e7e7 100644
--- a/core/io/http_client.cpp
+++ b/core/io/http_client.cpp
@@ -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;
@@ -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;
diff --git a/core/io/ip.cpp b/core/io/ip.cpp
index e1d9c19f10..eb7814054b 100644
--- a/core/io/ip.cpp
+++ b/core/io/ip.cpp
@@ -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 = "";
};
@@ -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;
}
@@ -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();
@@ -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;
@@ -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());
}
@@ -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;
@@ -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());
}
}
diff --git a/core/io/ip.h b/core/io/ip.h
index ae080b8e26..0c4a83257d 100644
--- a/core/io/ip.h
+++ b/core/io/ip.h
@@ -69,7 +69,7 @@ protected:
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;
@@ -80,15 +80,15 @@ public:
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);
diff --git a/core/io/ip_address.cpp b/core/io/ip_address.cpp
index 5f98eb69e8..1c1ac8a88f 100644
--- a/core/io/ip_address.cpp
+++ b/core/io/ip_address.cpp
@@ -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 "*";
}
@@ -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;
@@ -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);
@@ -161,33 +161,33 @@ 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++) {
@@ -195,7 +195,7 @@ void IP_Address::set_ipv6(const uint8_t *p_buf) {
}
}
-IP_Address::IP_Address(const String &p_string) {
+IPAddress::IPAddress(const String &p_string) {
clear();
if (p_string == "*") {
@@ -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) {
diff --git a/core/io/ip_address.h b/core/io/ip_address.h
index 49bf83d72f..05da675704 100644
--- a/core/io/ip_address.h
+++ b/core/io/ip_address.h
@@ -33,7 +33,7 @@
#include "core/string/ustring.h"
-struct IP_Address {
+struct IPAddress {
private:
union {
uint8_t field8[16];
@@ -50,7 +50,7 @@ protected:
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;
}
@@ -65,7 +65,7 @@ public:
return true;
}
- bool operator!=(const IP_Address &p_ip) const {
+ bool operator!=(const IPAddress &p_ip) const {
if (p_ip.valid != valid) {
return true;
}
@@ -91,9 +91,9 @@ public:
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
diff --git a/core/io/net_socket.h b/core/io/net_socket.h
index a632ad2ea7..98ff9562d9 100644
--- a/core/io/net_socket.h
+++ b/core/io/net_socket.h
@@ -55,27 +55,27 @@ public:
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
diff --git a/core/io/packed_data_container.cpp b/core/io/packed_data_container.cpp
index c6354b11b7..52169987fd 100644
--- a/core/io/packed_data_container.cpp
+++ b/core/io/packed_data_container.cpp
@@ -123,6 +123,7 @@ Variant PackedDataContainer::_get_at_ofs(uint32_t p_ofs, const uint8_t *p_buf, b
uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const {
const uint8_t *rd = data.ptr();
+ ERR_FAIL_COND_V(!rd, 0);
const uint8_t *r = &rd[p_ofs];
uint32_t type = decode_uint32(r);
@@ -149,6 +150,10 @@ int PackedDataContainer::_size(uint32_t p_ofs) const {
Variant PackedDataContainer::_key_at_ofs(uint32_t p_ofs, const Variant &p_key, bool &err) const {
const uint8_t *rd = data.ptr();
+ if (!rd) {
+ err = true;
+ ERR_FAIL_COND_V(!rd, Variant());
+ }
const uint8_t *r = &rd[p_ofs];
uint32_t type = decode_uint32(r);
diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp
index 40e4ce4f77..f951a5158c 100644
--- a/core/io/packet_peer_udp.cpp
+++ b/core/io/packet_peer_udp.cpp
@@ -45,7 +45,7 @@ void PacketPeerUDP::set_broadcast_enabled(bool p_enabled) {
}
}
-Error PacketPeerUDP::join_multicast_group(IP_Address p_multi_address, String p_if_name) {
+Error PacketPeerUDP::join_multicast_group(IPAddress p_multi_address, String p_if_name) {
ERR_FAIL_COND_V(udp_server, ERR_LOCKED);
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(!p_multi_address.is_valid(), ERR_INVALID_PARAMETER);
@@ -60,7 +60,7 @@ Error PacketPeerUDP::join_multicast_group(IP_Address p_multi_address, String p_i
return _sock->join_multicast_group(p_multi_address, p_if_name);
}
-Error PacketPeerUDP::leave_multicast_group(IP_Address p_multi_address, String p_if_name) {
+Error PacketPeerUDP::leave_multicast_group(IPAddress p_multi_address, String p_if_name) {
ERR_FAIL_COND_V(udp_server, ERR_LOCKED);
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(!_sock->is_open(), ERR_UNCONFIGURED);
@@ -72,7 +72,7 @@ String PacketPeerUDP::_get_packet_ip() const {
}
Error PacketPeerUDP::_set_dest_address(const String &p_address, int p_port) {
- IP_Address ip;
+ IPAddress ip;
if (p_address.is_valid_ip_address()) {
ip = p_address;
} else {
@@ -159,7 +159,7 @@ int PacketPeerUDP::get_max_packet_size() const {
return 512; // uhm maybe not
}
-Error PacketPeerUDP::bind(int p_port, const IP_Address &p_bind_address, int p_recv_buffer_size) {
+Error PacketPeerUDP::bind(int p_port, const IPAddress &p_bind_address, int p_recv_buffer_size) {
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE);
ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER);
@@ -190,7 +190,7 @@ Error PacketPeerUDP::bind(int p_port, const IP_Address &p_bind_address, int p_re
return OK;
}
-Error PacketPeerUDP::connect_shared_socket(Ref<NetSocket> p_sock, IP_Address p_ip, uint16_t p_port, UDPServer *p_server) {
+Error PacketPeerUDP::connect_shared_socket(Ref<NetSocket> p_sock, IPAddress p_ip, uint16_t p_port, UDPServer *p_server) {
udp_server = p_server;
connected = true;
_sock = p_sock;
@@ -207,7 +207,7 @@ void PacketPeerUDP::disconnect_shared_socket() {
close();
}
-Error PacketPeerUDP::connect_to_host(const IP_Address &p_host, int p_port) {
+Error PacketPeerUDP::connect_to_host(const IPAddress &p_host, int p_port) {
ERR_FAIL_COND_V(udp_server, ERR_LOCKED);
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(!p_host.is_valid(), ERR_INVALID_PARAMETER);
@@ -276,7 +276,7 @@ Error PacketPeerUDP::_poll() {
Error err;
int read;
- IP_Address ip;
+ IPAddress ip;
uint16_t port;
while (true) {
@@ -306,7 +306,7 @@ Error PacketPeerUDP::_poll() {
return OK;
}
-Error PacketPeerUDP::store_packet(IP_Address p_ip, uint32_t p_port, uint8_t *p_buf, int p_buf_size) {
+Error PacketPeerUDP::store_packet(IPAddress p_ip, uint32_t p_port, uint8_t *p_buf, int p_buf_size) {
if (rb.space_left() < p_buf_size + 24) {
return ERR_OUT_OF_MEMORY;
}
@@ -322,7 +322,7 @@ bool PacketPeerUDP::is_bound() const {
return _sock.is_valid() && _sock->is_open();
}
-IP_Address PacketPeerUDP::get_packet_address() const {
+IPAddress PacketPeerUDP::get_packet_address() const {
return packet_ip;
}
@@ -336,7 +336,7 @@ int PacketPeerUDP::get_local_port() const {
return local_port;
}
-void PacketPeerUDP::set_dest_address(const IP_Address &p_address, int p_port) {
+void PacketPeerUDP::set_dest_address(const IPAddress &p_address, int p_port) {
ERR_FAIL_COND_MSG(connected, "Destination address cannot be set for connected sockets");
peer_addr = p_address;
peer_port = p_port;
diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h
index b9d11c465c..40d3c44e40 100644
--- a/core/io/packet_peer_udp.h
+++ b/core/io/packet_peer_udp.h
@@ -48,11 +48,11 @@ protected:
RingBuffer<uint8_t> rb;
uint8_t recv_buffer[PACKET_BUFFER_SIZE];
uint8_t packet_buffer[PACKET_BUFFER_SIZE];
- IP_Address packet_ip;
+ IPAddress packet_ip;
int packet_port = 0;
int queue_count = 0;
- IP_Address peer_addr;
+ IPAddress peer_addr;
int peer_port = 0;
bool connected = false;
bool blocking = true;
@@ -70,29 +70,29 @@ protected:
public:
void set_blocking_mode(bool p_enable);
- Error bind(int p_port, const IP_Address &p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536);
+ Error bind(int p_port, const IPAddress &p_bind_address = IPAddress("*"), int p_recv_buffer_size = 65536);
void close();
Error wait();
bool is_bound() const;
- Error connect_shared_socket(Ref<NetSocket> p_sock, IP_Address p_ip, uint16_t p_port, UDPServer *ref); // Used by UDPServer
+ Error connect_shared_socket(Ref<NetSocket> p_sock, IPAddress p_ip, uint16_t p_port, UDPServer *ref); // Used by UDPServer
void disconnect_shared_socket(); // Used by UDPServer
- Error store_packet(IP_Address p_ip, uint32_t p_port, uint8_t *p_buf, int p_buf_size); // Used internally and by UDPServer
- Error connect_to_host(const IP_Address &p_host, int p_port);
+ Error store_packet(IPAddress p_ip, uint32_t p_port, uint8_t *p_buf, int p_buf_size); // Used internally and by UDPServer
+ Error connect_to_host(const IPAddress &p_host, int p_port);
bool is_connected_to_host() const;
- IP_Address get_packet_address() const;
+ IPAddress get_packet_address() const;
int get_packet_port() const;
int get_local_port() const;
- void set_dest_address(const IP_Address &p_address, int p_port);
+ void set_dest_address(const IPAddress &p_address, int p_port);
Error put_packet(const uint8_t *p_buffer, int p_buffer_size) override;
Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) override;
int get_available_packet_count() const override;
int get_max_packet_size() const override;
void set_broadcast_enabled(bool p_enabled);
- Error join_multicast_group(IP_Address p_multi_address, String p_if_name);
- Error leave_multicast_group(IP_Address p_multi_address, String p_if_name);
+ Error join_multicast_group(IPAddress p_multi_address, String p_if_name);
+ Error leave_multicast_group(IPAddress p_multi_address, String p_if_name);
PacketPeerUDP();
~PacketPeerUDP();
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp
index dcf71bb4a9..040e55b9db 100644
--- a/core/io/resource_loader.cpp
+++ b/core/io/resource_loader.cpp
@@ -114,25 +114,24 @@ void ResourceFormatLoader::get_recognized_extensions(List<String> *p_extensions)
}
RES ResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
+ // Check user-defined loader if there's any. Hard fail if it returns an error.
if (get_script_instance() && get_script_instance()->has_method("load")) {
Variant res = get_script_instance()->call("load", p_path, p_original_path, p_use_sub_threads, p_cache_mode);
- if (res.get_type() == Variant::INT) {
+ if (res.get_type() == Variant::INT) { // Error code, abort.
if (r_error) {
*r_error = (Error)res.operator int64_t();
}
-
- } else {
+ return RES();
+ } else { // Success, pass on result.
if (r_error) {
*r_error = OK;
}
return res;
}
-
- return res;
}
- ERR_FAIL_V_MSG(RES(), "Failed to load resource '" + p_path + "', ResourceFormatLoader::load was not implemented for this resource type.");
+ ERR_FAIL_V_MSG(RES(), "Failed to load resource '" + p_path + "'. ResourceFormatLoader::load was not implemented for this resource type.");
}
void ResourceFormatLoader::get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types) {
diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp
index 9906b9e4c3..5b794274ca 100644
--- a/core/io/stream_peer_tcp.cpp
+++ b/core/io/stream_peer_tcp.cpp
@@ -56,7 +56,7 @@ Error StreamPeerTCP::_poll_connection() {
return ERR_CONNECTION_ERROR;
}
-void StreamPeerTCP::accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint16_t p_port) {
+void StreamPeerTCP::accept_socket(Ref<NetSocket> p_sock, IPAddress p_host, uint16_t p_port) {
_sock = p_sock;
_sock->set_blocking_enabled(false);
@@ -67,7 +67,7 @@ void StreamPeerTCP::accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint
peer_port = p_port;
}
-Error StreamPeerTCP::bind(int p_port, const IP_Address &p_host) {
+Error StreamPeerTCP::bind(int p_port, const IPAddress &p_host) {
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE);
ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive).");
@@ -84,7 +84,7 @@ Error StreamPeerTCP::bind(int p_port, const IP_Address &p_host) {
return _sock->bind(p_host, p_port);
}
-Error StreamPeerTCP::connect_to_host(const IP_Address &p_host, int p_port) {
+Error StreamPeerTCP::connect_to_host(const IPAddress &p_host, int p_port) {
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(status != STATUS_NONE, ERR_ALREADY_IN_USE);
ERR_FAIL_COND_V(!p_host.is_valid(), ERR_INVALID_PARAMETER);
@@ -283,7 +283,7 @@ void StreamPeerTCP::disconnect_from_host() {
timeout = 0;
status = STATUS_NONE;
- peer_host = IP_Address();
+ peer_host = IPAddress();
peer_port = 0;
}
@@ -315,7 +315,7 @@ int StreamPeerTCP::get_available_bytes() const {
return _sock->get_available_bytes();
}
-IP_Address StreamPeerTCP::get_connected_host() const {
+IPAddress StreamPeerTCP::get_connected_host() const {
return peer_host;
}
@@ -330,7 +330,7 @@ int StreamPeerTCP::get_local_port() const {
}
Error StreamPeerTCP::_connect(const String &p_address, int p_port) {
- IP_Address ip;
+ IPAddress ip;
if (p_address.is_valid_ip_address()) {
ip = p_address;
} else {
diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h
index 3bc7b252dc..a2a7f447d8 100644
--- a/core/io/stream_peer_tcp.h
+++ b/core/io/stream_peer_tcp.h
@@ -52,7 +52,7 @@ protected:
Ref<NetSocket> _sock;
uint64_t timeout = 0;
Status status = STATUS_NONE;
- IP_Address peer_host;
+ IPAddress peer_host;
uint16_t peer_port = 0;
Error _connect(const String &p_address, int p_port);
@@ -63,12 +63,12 @@ protected:
static void _bind_methods();
public:
- void accept_socket(Ref<NetSocket> p_sock, IP_Address p_host, uint16_t p_port);
+ void accept_socket(Ref<NetSocket> p_sock, IPAddress p_host, uint16_t p_port);
- Error bind(int p_port, const IP_Address &p_host);
- Error connect_to_host(const IP_Address &p_host, int p_port);
+ Error bind(int p_port, const IPAddress &p_host);
+ Error connect_to_host(const IPAddress &p_host, int p_port);
bool is_connected_to_host() const;
- IP_Address get_connected_host() const;
+ IPAddress get_connected_host() const;
int get_connected_port() const;
int get_local_port() const;
void disconnect_from_host();
diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp
index 348be66ba4..b760a9ef80 100644
--- a/core/io/tcp_server.cpp
+++ b/core/io/tcp_server.cpp
@@ -30,16 +30,16 @@
#include "tcp_server.h"
-void TCP_Server::_bind_methods() {
- ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &TCP_Server::listen, DEFVAL("*"));
- ClassDB::bind_method(D_METHOD("is_connection_available"), &TCP_Server::is_connection_available);
- ClassDB::bind_method(D_METHOD("is_listening"), &TCP_Server::is_listening);
- ClassDB::bind_method(D_METHOD("get_local_port"), &TCP_Server::get_local_port);
- ClassDB::bind_method(D_METHOD("take_connection"), &TCP_Server::take_connection);
- ClassDB::bind_method(D_METHOD("stop"), &TCP_Server::stop);
+void TCPServer::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &TCPServer::listen, DEFVAL("*"));
+ ClassDB::bind_method(D_METHOD("is_connection_available"), &TCPServer::is_connection_available);
+ ClassDB::bind_method(D_METHOD("is_listening"), &TCPServer::is_listening);
+ ClassDB::bind_method(D_METHOD("get_local_port"), &TCPServer::get_local_port);
+ ClassDB::bind_method(D_METHOD("take_connection"), &TCPServer::take_connection);
+ ClassDB::bind_method(D_METHOD("stop"), &TCPServer::stop);
}
-Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) {
+Error TCPServer::listen(uint16_t p_port, const IPAddress &p_bind_address) {
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE);
ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER);
@@ -76,19 +76,19 @@ Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) {
return OK;
}
-int TCP_Server::get_local_port() const {
+int TCPServer::get_local_port() const {
uint16_t local_port;
_sock->get_socket_address(nullptr, &local_port);
return local_port;
}
-bool TCP_Server::is_listening() const {
+bool TCPServer::is_listening() const {
ERR_FAIL_COND_V(!_sock.is_valid(), false);
return _sock->is_open();
}
-bool TCP_Server::is_connection_available() const {
+bool TCPServer::is_connection_available() const {
ERR_FAIL_COND_V(!_sock.is_valid(), false);
if (!_sock->is_open()) {
@@ -99,14 +99,14 @@ bool TCP_Server::is_connection_available() const {
return (err == OK);
}
-Ref<StreamPeerTCP> TCP_Server::take_connection() {
+Ref<StreamPeerTCP> TCPServer::take_connection() {
Ref<StreamPeerTCP> conn;
if (!is_connection_available()) {
return conn;
}
Ref<NetSocket> ns;
- IP_Address ip;
+ IPAddress ip;
uint16_t port = 0;
ns = _sock->accept(ip, port);
if (!ns.is_valid()) {
@@ -118,16 +118,16 @@ Ref<StreamPeerTCP> TCP_Server::take_connection() {
return conn;
}
-void TCP_Server::stop() {
+void TCPServer::stop() {
if (_sock.is_valid()) {
_sock->close();
}
}
-TCP_Server::TCP_Server() :
+TCPServer::TCPServer() :
_sock(Ref<NetSocket>(NetSocket::create())) {
}
-TCP_Server::~TCP_Server() {
+TCPServer::~TCPServer() {
stop();
}
diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h
index 58c04d87ec..abefa53c6f 100644
--- a/core/io/tcp_server.h
+++ b/core/io/tcp_server.h
@@ -36,8 +36,8 @@
#include "core/io/stream_peer.h"
#include "core/io/stream_peer_tcp.h"
-class TCP_Server : public Reference {
- GDCLASS(TCP_Server, Reference);
+class TCPServer : public Reference {
+ GDCLASS(TCPServer, Reference);
protected:
enum {
@@ -48,7 +48,7 @@ protected:
static void _bind_methods();
public:
- Error listen(uint16_t p_port, const IP_Address &p_bind_address = IP_Address("*"));
+ Error listen(uint16_t p_port, const IPAddress &p_bind_address = IPAddress("*"));
int get_local_port() const;
bool is_listening() const;
bool is_connection_available() const;
@@ -56,8 +56,8 @@ public:
void stop(); // Stop listening
- TCP_Server();
- ~TCP_Server();
+ TCPServer();
+ ~TCPServer();
};
#endif // TCP_SERVER_H
diff --git a/core/io/udp_server.cpp b/core/io/udp_server.cpp
index 99642f4af4..6a1af0c2a9 100644
--- a/core/io/udp_server.cpp
+++ b/core/io/udp_server.cpp
@@ -50,7 +50,7 @@ Error UDPServer::poll() {
}
Error err;
int read;
- IP_Address ip;
+ IPAddress ip;
uint16_t port;
while (true) {
err = _sock->recvfrom(recv_buffer, sizeof(recv_buffer), read, ip, port);
@@ -87,7 +87,7 @@ Error UDPServer::poll() {
return OK;
}
-Error UDPServer::listen(uint16_t p_port, const IP_Address &p_bind_address) {
+Error UDPServer::listen(uint16_t p_port, const IPAddress &p_bind_address) {
ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE);
ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER);
@@ -168,7 +168,7 @@ Ref<PacketPeerUDP> UDPServer::take_connection() {
return peer.peer;
}
-void UDPServer::remove_peer(IP_Address p_ip, int p_port) {
+void UDPServer::remove_peer(IPAddress p_ip, int p_port) {
Peer peer;
peer.ip = p_ip;
peer.port = p_port;
diff --git a/core/io/udp_server.h b/core/io/udp_server.h
index 298d4d4b63..60d03f37f0 100644
--- a/core/io/udp_server.h
+++ b/core/io/udp_server.h
@@ -44,7 +44,7 @@ protected:
struct Peer {
PacketPeerUDP *peer;
- IP_Address ip;
+ IPAddress ip;
uint16_t port = 0;
bool operator==(const Peer &p_other) const {
@@ -61,8 +61,8 @@ protected:
static void _bind_methods();
public:
- void remove_peer(IP_Address p_ip, int p_port);
- Error listen(uint16_t p_port, const IP_Address &p_bind_address = IP_Address("*"));
+ void remove_peer(IPAddress p_ip, int p_port);
+ Error listen(uint16_t p_port, const IPAddress &p_bind_address = IPAddress("*"));
Error poll();
int get_local_port() const;
bool is_listening() const;