diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2021-03-26 17:56:08 +0100 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2021-04-12 21:05:33 +0200 |
commit | 4d5c8e0b1835be586b2d57d7db0953110d166a14 (patch) | |
tree | 45af27cfa43ff2b3a559878d061f04389b9d7242 | |
parent | da8c2310b5b2eae941fa1465495409086397127f (diff) |
This renames PacketPeerUDP.listen to bind.
-rw-r--r-- | core/io/packet_peer_udp.cpp | 8 | ||||
-rw-r--r-- | core/io/packet_peer_udp.h | 4 | ||||
-rw-r--r-- | doc/classes/PacketPeerUDP.xml | 44 | ||||
-rw-r--r-- | doc/classes/UDPServer.xml | 2 | ||||
-rw-r--r-- | thirdparty/enet/godot.cpp | 2 |
5 files changed, 30 insertions, 30 deletions
diff --git a/core/io/packet_peer_udp.cpp b/core/io/packet_peer_udp.cpp index 9ff895657f..40e4ce4f77 100644 --- a/core/io/packet_peer_udp.cpp +++ b/core/io/packet_peer_udp.cpp @@ -159,7 +159,7 @@ int PacketPeerUDP::get_max_packet_size() const { 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_open(), ERR_ALREADY_IN_USE); 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; } -bool PacketPeerUDP::is_listening() const { +bool PacketPeerUDP::is_bound() const { 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() { - 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("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("is_connected_to_host"), &PacketPeerUDP::is_connected_to_host); ClassDB::bind_method(D_METHOD("get_packet_ip"), &PacketPeerUDP::_get_packet_ip); diff --git a/core/io/packet_peer_udp.h b/core/io/packet_peer_udp.h index 877ee0c90b..b9d11c465c 100644 --- a/core/io/packet_peer_udp.h +++ b/core/io/packet_peer_udp.h @@ -70,10 +70,10 @@ protected: public: 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(); 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 void disconnect_shared_socket(); // Used by UDPServer diff --git a/doc/classes/PacketPeerUDP.xml b/doc/classes/PacketPeerUDP.xml index 2ea5c8a0a4..5d059ad3df 100644 --- a/doc/classes/PacketPeerUDP.xml +++ b/doc/classes/PacketPeerUDP.xml @@ -9,11 +9,27 @@ <tutorials> </tutorials> <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=""*""> + </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"> <return type="void"> </return> <description> - Closes the UDP socket the [PacketPeerUDP] is currently listening on. + Closes the [PacketPeerUDP]'s underlying UDP socket. </description> </method> <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]). </description> </method> - <method name="is_connected_to_host" qualifiers="const"> + <method name="is_bound" qualifiers="const"> <return type="bool"> </return> <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> </method> - <method name="is_listening" qualifiers="const"> + <method name="is_connected_to_host" qualifiers="const"> <return type="bool"> </return> <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> </method> <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]. </description> </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=""*""> - </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"> <return type="void"> </return> @@ -129,7 +129,7 @@ <return type="int" enum="Error"> </return> <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: [codeblocks] [gdscript] diff --git a/doc/classes/UDPServer.xml b/doc/classes/UDPServer.xml index 931aa71332..6f3ccb8a17 100644 --- a/doc/classes/UDPServer.xml +++ b/doc/classes/UDPServer.xml @@ -152,7 +152,7 @@ <argument index="1" name="bind_address" type="String" default=""*""> </argument> <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> </method> <method name="poll"> diff --git a/thirdparty/enet/godot.cpp b/thirdparty/enet/godot.cpp index 73fa3c62a2..1c75414be2 100644 --- a/thirdparty/enet/godot.cpp +++ b/thirdparty/enet/godot.cpp @@ -172,7 +172,7 @@ public: } 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) { |