mirror of
				https://github.com/godotengine/godot.git
				synced 2025-10-30 21:21:10 +00:00 
			
		
		
		
	[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.
This commit is contained in:
		
							parent
							
								
									0e52867668
								
							
						
					
					
						commit
						331f1662df
					
				
					 8 changed files with 8 additions and 20 deletions
				
			
		|  | @ -242,7 +242,7 @@ Error PacketPeerUDP::connect_to_host(const IPAddress &p_host, int p_port) { | ||||||
| 	return OK; | 	return OK; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| bool PacketPeerUDP::is_connected_to_host() const { | bool PacketPeerUDP::is_socket_connected() const { | ||||||
| 	return connected; | 	return connected; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -348,7 +348,7 @@ void PacketPeerUDP::_bind_methods() { | ||||||
| 	ClassDB::bind_method(D_METHOD("wait"), &PacketPeerUDP::wait); | 	ClassDB::bind_method(D_METHOD("wait"), &PacketPeerUDP::wait); | ||||||
| 	ClassDB::bind_method(D_METHOD("is_bound"), &PacketPeerUDP::is_bound); | 	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("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_ip"), &PacketPeerUDP::_get_packet_ip); | ||||||
| 	ClassDB::bind_method(D_METHOD("get_packet_port"), &PacketPeerUDP::get_packet_port); | 	ClassDB::bind_method(D_METHOD("get_packet_port"), &PacketPeerUDP::get_packet_port); | ||||||
| 	ClassDB::bind_method(D_METHOD("get_local_port"), &PacketPeerUDP::get_local_port); | 	ClassDB::bind_method(D_METHOD("get_local_port"), &PacketPeerUDP::get_local_port); | ||||||
|  |  | ||||||
|  | @ -79,7 +79,7 @@ public: | ||||||
| 	void disconnect_shared_socket(); // Used by UDPServer
 | 	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 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); | 	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; | 	IPAddress get_packet_address() const; | ||||||
| 	int get_packet_port() const; | 	int get_packet_port() const; | ||||||
|  |  | ||||||
|  | @ -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) { | 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; | 		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) { | 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); | 	_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 { | StreamPeerTCP::Status StreamPeerTCP::get_status() const { | ||||||
| 	return status; | 	return status; | ||||||
| } | } | ||||||
|  | @ -319,7 +315,6 @@ Error StreamPeerTCP::_connect(const String &p_address, int p_port) { | ||||||
| void StreamPeerTCP::_bind_methods() { | void StreamPeerTCP::_bind_methods() { | ||||||
| 	ClassDB::bind_method(D_METHOD("bind", "port", "host"), &StreamPeerTCP::bind, DEFVAL("*")); | 	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("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("poll"), &StreamPeerTCP::poll); | ||||||
| 	ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerTCP::get_status); | 	ClassDB::bind_method(D_METHOD("get_status"), &StreamPeerTCP::get_status); | ||||||
| 	ClassDB::bind_method(D_METHOD("get_connected_host"), &StreamPeerTCP::get_connected_host); | 	ClassDB::bind_method(D_METHOD("get_connected_host"), &StreamPeerTCP::get_connected_host); | ||||||
|  |  | ||||||
|  | @ -66,7 +66,6 @@ public: | ||||||
| 
 | 
 | ||||||
| 	Error bind(int p_port, const IPAddress &p_host); | 	Error bind(int p_port, const IPAddress &p_host); | ||||||
| 	Error connect_to_host(const IPAddress &p_host, int p_port); | 	Error connect_to_host(const IPAddress &p_host, int p_port); | ||||||
| 	bool is_connected_to_host() const; |  | ||||||
| 	IPAddress get_connected_host() const; | 	IPAddress get_connected_host() const; | ||||||
| 	int get_connected_port() const; | 	int get_connected_port() const; | ||||||
| 	int get_local_port() const; | 	int get_local_port() const; | ||||||
|  |  | ||||||
|  | @ -61,7 +61,7 @@ | ||||||
| 				Returns whether this [PacketPeerUDP] is bound to an address and can receive packets. | 				Returns whether this [PacketPeerUDP] is bound to an address and can receive packets. | ||||||
| 			</description> | 			</description> | ||||||
| 		</method> | 		</method> | ||||||
| 		<method name="is_connected_to_host" qualifiers="const"> | 		<method name="is_socket_connected" qualifiers="const"> | ||||||
| 			<return type="bool" /> | 			<return type="bool" /> | ||||||
| 			<description> | 			<description> | ||||||
| 				Returns [code]true[/code] if the UDP socket is open and has been connected to a remote address. See [method connect_to_host]. | 				Returns [code]true[/code] if the UDP socket is open and has been connected to a remote address. See [method connect_to_host]. | ||||||
|  |  | ||||||
|  | @ -57,12 +57,6 @@ | ||||||
| 				Returns the status of the connection, see [enum Status]. | 				Returns the status of the connection, see [enum Status]. | ||||||
| 			</description> | 			</description> | ||||||
| 		</method> | 		</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"> | 		<method name="poll"> | ||||||
| 			<return type="int" enum="Error" /> | 			<return type="int" enum="Error" /> | ||||||
| 			<description> | 			<description> | ||||||
|  |  | ||||||
|  | @ -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) { | 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; | 	base = p_base; | ||||||
| 	int ret = 0; | 	int ret = 0; | ||||||
|  |  | ||||||
|  | @ -337,7 +337,7 @@ MultiplayerPeer::ConnectionStatus WSLClient::get_connection_status() const { | ||||||
| 		return CONNECTION_CONNECTED; | 		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; | 		return CONNECTION_CONNECTING; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Fabio Alessandrelli
						Fabio Alessandrelli