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 | |
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.
-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 | ||||
-rw-r--r-- | doc/classes/PacketPeerUDP.xml | 2 | ||||
-rw-r--r-- | doc/classes/StreamPeerTCP.xml | 6 | ||||
-rw-r--r-- | modules/mbedtls/packet_peer_mbed_dtls.cpp | 2 | ||||
-rw-r--r-- | modules/websocket/wsl_client.cpp | 2 |
8 files changed, 8 insertions, 20 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; diff --git a/doc/classes/PacketPeerUDP.xml b/doc/classes/PacketPeerUDP.xml index 580bf60518..7c6622be3c 100644 --- a/doc/classes/PacketPeerUDP.xml +++ b/doc/classes/PacketPeerUDP.xml @@ -61,7 +61,7 @@ Returns whether this [PacketPeerUDP] is bound to an address and can receive packets. </description> </method> - <method name="is_connected_to_host" qualifiers="const"> + <method name="is_socket_connected" qualifiers="const"> <return type="bool" /> <description> Returns [code]true[/code] if the UDP socket is open and has been connected to a remote address. See [method connect_to_host]. diff --git a/doc/classes/StreamPeerTCP.xml b/doc/classes/StreamPeerTCP.xml index 033982ea40..f06cf5c7a2 100644 --- a/doc/classes/StreamPeerTCP.xml +++ b/doc/classes/StreamPeerTCP.xml @@ -57,12 +57,6 @@ Returns the status of the connection, see [enum Status]. </description> </method> - <method name="is_connected_to_host" qualifiers="const"> - <return type="bool" /> - <description> - Returns [code]true[/code] if this peer is currently connected or is connecting to a host, [code]false[/code] otherwise. - </description> - </method> <method name="poll"> <return type="int" enum="Error" /> <description> diff --git a/modules/mbedtls/packet_peer_mbed_dtls.cpp b/modules/mbedtls/packet_peer_mbed_dtls.cpp index 2a5eaa0109..9676f16b2d 100644 --- a/modules/mbedtls/packet_peer_mbed_dtls.cpp +++ b/modules/mbedtls/packet_peer_mbed_dtls.cpp @@ -115,7 +115,7 @@ Error PacketPeerMbedDTLS::_do_handshake() { } Error PacketPeerMbedDTLS::connect_to_peer(Ref<PacketPeerUDP> p_base, bool p_validate_certs, const String &p_for_hostname, Ref<X509Certificate> p_ca_certs) { - ERR_FAIL_COND_V(!p_base.is_valid() || !p_base->is_connected_to_host(), ERR_INVALID_PARAMETER); + ERR_FAIL_COND_V(!p_base.is_valid() || !p_base->is_socket_connected(), ERR_INVALID_PARAMETER); base = p_base; int ret = 0; diff --git a/modules/websocket/wsl_client.cpp b/modules/websocket/wsl_client.cpp index 96763037e7..58c329f043 100644 --- a/modules/websocket/wsl_client.cpp +++ b/modules/websocket/wsl_client.cpp @@ -337,7 +337,7 @@ MultiplayerPeer::ConnectionStatus WSLClient::get_connection_status() const { return CONNECTION_CONNECTED; } - if (_tcp->is_connected_to_host() || _resolver_id != IP::RESOLVER_INVALID_ID) { + if (_tcp->get_status() == StreamPeerTCP::STATUS_CONNECTING || _resolver_id != IP::RESOLVER_INVALID_ID) { return CONNECTION_CONNECTING; } |