This renames PacketPeerUDP.listen to bind.

This commit is contained in:
Fabio Alessandrelli 2021-03-26 17:56:08 +01:00
parent da8c2310b5
commit 4d5c8e0b18
5 changed files with 33 additions and 33 deletions

View File

@ -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);

View File

@ -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

View File

@ -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="&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">
<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,6 +65,13 @@
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_bound" qualifiers="const">
<return type="bool">
</return>
<description>
Returns whether this [PacketPeerUDP] is bound to an address and can receive packets.
</description>
</method>
<method name="is_connected_to_host" qualifiers="const">
<return type="bool">
</return>
@ -56,13 +79,6 @@
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="is_listening" qualifiers="const">
<return type="bool">
</return>
<description>
Returns whether this [PacketPeerUDP] is listening.
</description>
</method>
<method name="join_multicast_group">
<return type="int" enum="Error">
</return>
@ -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="&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">
<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]

View File

@ -152,7 +152,7 @@
<argument index="1" name="bind_address" type="String" default="&quot;*&quot;">
</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">

View File

@ -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) {