diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2022-03-27 16:31:56 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2022-03-27 16:36:44 +0200 |
commit | 331f1662df41b4e7afff30d2fe4019a413499c1c (patch) | |
tree | fe6d6777ae686494caf08be2f2f2272a81d7260f /core | |
parent | 0e528676683a0df96751fd0daa018e0818baa0e2 (diff) |
[Net] Drop is_connected_to_host for TCP and UDP.
The UDP method is now called `is_socket_connected` to limit confusion
with the actual host connection status which doesn't make sense in UDP.
The TCP method is completly dropped, use get_status instead.
The only one left is the WebSocketPeer one, which should be fine as is
for now.
Diffstat (limited to 'core')
-rw-r--r-- | core/io/packet_peer_udp.cpp | 4 | ||||
-rw-r--r-- | core/io/packet_peer_udp.h | 2 | ||||
-rw-r--r-- | core/io/stream_peer_tcp.cpp | 9 | ||||
-rw-r--r-- | core/io/stream_peer_tcp.h | 1 |
4 files changed, 5 insertions, 11 deletions
diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index 503eb17cae..84d1f3ebd4 100644 --- a/core/io/packet_peer_udp.cpp +++ b/core/io/packet_peer_udp.cpp @@ -242,7 +242,7 @@ Error PacketPeerUDP::connect_to_host(const IPAddress &p_host, int p_port) { return OK; } -bool PacketPeerUDP::is_connected_to_host() const { +bool PacketPeerUDP::is_socket_connected() const { return connected; } @@ -348,7 +348,7 @@ void PacketPeerUDP::_bind_methods() { ClassDB::bind_method(D_METHOD("wait"), &PacketPeerUDP::wait); ClassDB::bind_method(D_METHOD("is_bound"), &PacketPeerUDP::is_bound); ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port"), &PacketPeerUDP::connect_to_host); - ClassDB::bind_method(D_METHOD("is_connected_to_host"), &PacketPeerUDP::is_connected_to_host); + ClassDB::bind_method(D_METHOD("is_socket_connected"), &PacketPeerUDP::is_socket_connected); ClassDB::bind_method(D_METHOD("get_packet_ip"), &PacketPeerUDP::_get_packet_ip); ClassDB::bind_method(D_METHOD("get_packet_port"), &PacketPeerUDP::get_packet_port); ClassDB::bind_method(D_METHOD("get_local_port"), &PacketPeerUDP::get_local_port); diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h index 444a6dd5ba..a174cf5347 100644 --- a/core/io/packet_peer_udp.h +++ b/core/io/packet_peer_udp.h @@ -79,7 +79,7 @@ public: void disconnect_shared_socket(); // Used by UDPServer 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; + bool is_socket_connected() const; IPAddress get_packet_address() const; int get_packet_port() const; diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index 6c3313b73b..c5c2021e6e 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -184,7 +184,7 @@ Error StreamPeerTCP::write(const uint8_t *p_data, int p_bytes, int &r_sent, bool } Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool p_block) { - if (!is_connected_to_host()) { + if (status != STATUS_CONNECTED) { return FAILED; } @@ -237,14 +237,10 @@ Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool } void StreamPeerTCP::set_no_delay(bool p_enabled) { - ERR_FAIL_COND(!is_connected_to_host()); + ERR_FAIL_COND(!_sock.is_valid() || !_sock->is_open()); _sock->set_tcp_no_delay_enabled(p_enabled); } -bool StreamPeerTCP::is_connected_to_host() const { - return _sock.is_valid() && _sock->is_open() && (status == STATUS_CONNECTED || status == STATUS_CONNECTING); -} - StreamPeerTCP::Status StreamPeerTCP::get_status() const { return status; } @@ -319,7 +315,6 @@ Error StreamPeerTCP::_connect(const String &p_address, int p_port) { void StreamPeerTCP::_bind_methods() { ClassDB::bind_method(D_METHOD("bind", "port", "host"), &StreamPeerTCP::bind, DEFVAL("*")); ClassDB::bind_method(D_METHOD("connect_to_host", "host", "port"), &StreamPeerTCP::_connect); - ClassDB::bind_method(D_METHOD("is_connected_to_host"), &StreamPeerTCP::is_connected_to_host); ClassDB::bind_method(D_METHOD("poll"), &StreamPeerTCP::poll); ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerTCP::get_status); ClassDB::bind_method(D_METHOD("get_connected_host"), &StreamPeerTCP::get_connected_host); diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h index 5fe1734faa..f9eefb0604 100644 --- a/core/io/stream_peer_tcp.h +++ b/core/io/stream_peer_tcp.h @@ -66,7 +66,6 @@ public: 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; IPAddress get_connected_host() const; int get_connected_port() const; int get_local_port() const; |