瀏覽代碼

This renames PacketPeerUDP.listen to bind.

Fabio Alessandrelli 4 年之前
父節點
當前提交
4d5c8e0b18
共有 5 個文件被更改,包括 30 次插入30 次删除
  1. 4 4
      core/io/packet_peer_udp.cpp
  2. 2 2
      core/io/packet_peer_udp.h
  3. 22 22
      doc/classes/PacketPeerUDP.xml
  4. 1 1
      doc/classes/UDPServer.xml
  5. 1 1
      thirdparty/enet/godot.cpp

+ 4 - 4
core/io/packet_peer_udp.cpp

@@ -159,7 +159,7 @@ int PacketPeerUDP::get_max_packet_size() const {
 	return 512; // uhm maybe not
 	return 512; // uhm maybe not
 }
 }
 
 
-Error PacketPeerUDP::listen(int p_port, const IP_Address &p_bind_address, int p_recv_buffer_size) {
+Error PacketPeerUDP::bind(int p_port, const IP_Address &p_bind_address, int p_recv_buffer_size) {
 	ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
 	ERR_FAIL_COND_V(!_sock.is_valid(), ERR_UNAVAILABLE);
 	ERR_FAIL_COND_V(_sock->is_open(), ERR_ALREADY_IN_USE);
 	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);
 	ERR_FAIL_COND_V(!p_bind_address.is_valid() && !p_bind_address.is_wildcard(), ERR_INVALID_PARAMETER);
@@ -318,7 +318,7 @@ Error PacketPeerUDP::store_packet(IP_Address p_ip, uint32_t p_port, uint8_t *p_b
 	return OK;
 	return OK;
 }
 }
 
 
-bool PacketPeerUDP::is_listening() const {
+bool PacketPeerUDP::is_bound() const {
 	return _sock.is_valid() && _sock->is_open();
 	return _sock.is_valid() && _sock->is_open();
 }
 }
 
 
@@ -343,10 +343,10 @@ void PacketPeerUDP::set_dest_address(const IP_Address &p_address, int p_port) {
 }
 }
 
 
 void PacketPeerUDP::_bind_methods() {
 void PacketPeerUDP::_bind_methods() {
-	ClassDB::bind_method(D_METHOD("listen", "port", "bind_address", "recv_buf_size"), &PacketPeerUDP::listen, DEFVAL("*"), DEFVAL(65536));
+	ClassDB::bind_method(D_METHOD("bind", "port", "bind_address", "recv_buf_size"), &PacketPeerUDP::bind, DEFVAL("*"), DEFVAL(65536));
 	ClassDB::bind_method(D_METHOD("close"), &PacketPeerUDP::close);
 	ClassDB::bind_method(D_METHOD("close"), &PacketPeerUDP::close);
 	ClassDB::bind_method(D_METHOD("wait"), &PacketPeerUDP::wait);
 	ClassDB::bind_method(D_METHOD("wait"), &PacketPeerUDP::wait);
-	ClassDB::bind_method(D_METHOD("is_listening"), &PacketPeerUDP::is_listening);
+	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_connected_to_host"), &PacketPeerUDP::is_connected_to_host);
 	ClassDB::bind_method(D_METHOD("get_packet_ip"), &PacketPeerUDP::_get_packet_ip);
 	ClassDB::bind_method(D_METHOD("get_packet_ip"), &PacketPeerUDP::_get_packet_ip);

+ 2 - 2
core/io/packet_peer_udp.h

@@ -70,10 +70,10 @@ protected:
 public:
 public:
 	void set_blocking_mode(bool p_enable);
 	void set_blocking_mode(bool p_enable);
 
 
-	Error listen(int p_port, const IP_Address &p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536);
+	Error bind(int p_port, const IP_Address &p_bind_address = IP_Address("*"), int p_recv_buffer_size = 65536);
 	void close();
 	void close();
 	Error wait();
 	Error wait();
-	bool is_listening() const;
+	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, IP_Address p_ip, uint16_t p_port, UDPServer *ref); // Used by UDPServer
 	void disconnect_shared_socket(); // Used by UDPServer
 	void disconnect_shared_socket(); // Used by UDPServer

+ 22 - 22
doc/classes/PacketPeerUDP.xml

@@ -9,11 +9,27 @@
 	<tutorials>
 	<tutorials>
 	</tutorials>
 	</tutorials>
 	<methods>
 	<methods>
+		<method name="bind">
+			<return type="int" enum="Error">
+			</return>
+			<argument index="0" name="port" type="int">
+			</argument>
+			<argument index="1" name="bind_address" type="String" default="&quot;*&quot;">
+			</argument>
+			<argument index="2" name="recv_buf_size" type="int" default="65536">
+			</argument>
+			<description>
+				Binds this [PacketPeerUDP] to the specified [code]port[/code] and [code]address[/code] with a buffer size [code]recv_buf_size[/code], allowing it to receive incoming packets.
+				If [code]address[/code] is set to [code]"*"[/code] (default), the peer will be bound on all available addresses (both IPv4 and IPv6).
+				If [code]address[/code] is set to [code]"0.0.0.0"[/code] (for IPv4) or [code]"::"[/code] (for IPv6), the peer will be bound to all available addresses matching that IP type.
+				If [code]address[/code] is set to any valid address (e.g. [code]"192.168.1.101"[/code], [code]"::1"[/code], etc), the peer will only be bound to the interface with that addresses (or fail if no interface with the given address exists).
+			</description>
+		</method>
 		<method name="close">
 		<method name="close">
 			<return type="void">
 			<return type="void">
 			</return>
 			</return>
 			<description>
 			<description>
-				Closes the UDP socket the [PacketPeerUDP] is currently listening on.
+				Closes the [PacketPeerUDP]'s underlying UDP socket.
 			</description>
 			</description>
 		</method>
 		</method>
 		<method name="connect_to_host">
 		<method name="connect_to_host">
@@ -49,18 +65,18 @@
 				Returns the port of the remote peer that sent the last packet(that was received with [method PacketPeer.get_packet] or [method PacketPeer.get_var]).
 				Returns the port of the remote peer that sent the last packet(that was received with [method PacketPeer.get_packet] or [method PacketPeer.get_var]).
 			</description>
 			</description>
 		</method>
 		</method>
-		<method name="is_connected_to_host" qualifiers="const">
+		<method name="is_bound" qualifiers="const">
 			<return type="bool">
 			<return type="bool">
 			</return>
 			</return>
 			<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 whether this [PacketPeerUDP] is bound to an address and can receive packets.
 			</description>
 			</description>
 		</method>
 		</method>
-		<method name="is_listening" qualifiers="const">
+		<method name="is_connected_to_host" qualifiers="const">
 			<return type="bool">
 			<return type="bool">
 			</return>
 			</return>
 			<description>
 			<description>
-				Returns whether this [PacketPeerUDP] is listening.
+				Returns [code]true[/code] if the UDP socket is open and has been connected to a remote address. See [method connect_to_host].
 			</description>
 			</description>
 		</method>
 		</method>
 		<method name="join_multicast_group">
 		<method name="join_multicast_group">
@@ -87,22 +103,6 @@
 				Removes the interface identified by [code]interface_name[/code] from the multicast group specified by [code]multicast_address[/code].
 				Removes the interface identified by [code]interface_name[/code] from the multicast group specified by [code]multicast_address[/code].
 			</description>
 			</description>
 		</method>
 		</method>
-		<method name="listen">
-			<return type="int" enum="Error">
-			</return>
-			<argument index="0" name="port" type="int">
-			</argument>
-			<argument index="1" name="bind_address" type="String" default="&quot;*&quot;">
-			</argument>
-			<argument index="2" name="recv_buf_size" type="int" default="65536">
-			</argument>
-			<description>
-				Makes this [PacketPeerUDP] listen on the [code]port[/code] binding to [code]bind_address[/code] with a buffer size [code]recv_buf_size[/code].
-				If [code]bind_address[/code] is set to [code]"*"[/code] (default), the peer will listen on all available addresses (both IPv4 and IPv6).
-				If [code]bind_address[/code] is set to [code]"0.0.0.0"[/code] (for IPv4) or [code]"::"[/code] (for IPv6), the peer will listen on all available addresses matching that IP type.
-				If [code]bind_address[/code] is set to any valid address (e.g. [code]"192.168.1.101"[/code], [code]"::1"[/code], etc), the peer will only listen on the interface with that addresses (or fail if no interface with the given address exists).
-			</description>
-		</method>
 		<method name="set_broadcast_enabled">
 		<method name="set_broadcast_enabled">
 			<return type="void">
 			<return type="void">
 			</return>
 			</return>
@@ -129,7 +129,7 @@
 			<return type="int" enum="Error">
 			<return type="int" enum="Error">
 			</return>
 			</return>
 			<description>
 			<description>
-				Waits for a packet to arrive on the listening port. See [method listen].
+				Waits for a packet to arrive on the bound address. See [method bind].
 				[b]Note:[/b] [method wait] can't be interrupted once it has been called. This can be worked around by allowing the other party to send a specific "death pill" packet like this:
 				[b]Note:[/b] [method wait] can't be interrupted once it has been called. This can be worked around by allowing the other party to send a specific "death pill" packet like this:
 		[codeblocks]
 		[codeblocks]
 		[gdscript]
 		[gdscript]

+ 1 - 1
doc/classes/UDPServer.xml

@@ -152,7 +152,7 @@
 			<argument index="1" name="bind_address" type="String" default="&quot;*&quot;">
 			<argument index="1" name="bind_address" type="String" default="&quot;*&quot;">
 			</argument>
 			</argument>
 			<description>
 			<description>
-				Starts the server by opening a UDP socket listening on the given port. You can optionally specify a [code]bind_address[/code] to only listen for packets sent to that address. See also [method PacketPeerUDP.listen].
+				Starts the server by opening a UDP socket listening on the given port. You can optionally specify a [code]bind_address[/code] to only listen for packets sent to that address. See also [method PacketPeerUDP.bind].
 			</description>
 			</description>
 		</method>
 		</method>
 		<method name="poll">
 		<method name="poll">

+ 1 - 1
thirdparty/enet/godot.cpp

@@ -172,7 +172,7 @@ public:
 	}
 	}
 
 
 	Error bind(IP_Address p_ip, uint16_t p_port) {
 	Error bind(IP_Address p_ip, uint16_t p_port) {
-		return udp->listen(p_port, p_ip);
+		return udp->bind(p_port, p_ip);
 	}
 	}
 
 
 	Error sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP_Address p_ip, uint16_t p_port) {
 	Error sendto(const uint8_t *p_buffer, int p_len, int &r_sent, IP_Address p_ip, uint16_t p_port) {