diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2021-04-27 15:04:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-27 15:04:30 +0200 |
commit | 72bd64c1d50330f508afc3e6587ec113a8ed7605 (patch) | |
tree | 67afdbb9d2c30c5e6b3e65bc3b0fb5c944f8ff6d /core/io/tcp_server.cpp | |
parent | 2a1f3c494421e1cf1a675be339dbe0227ebe28da (diff) | |
parent | 4d5c8e0b1835be586b2d57d7db0953110d166a14 (diff) | |
download | redot-engine-72bd64c1d50330f508afc3e6587ec113a8ed7605.tar.gz |
Merge pull request #47398 from Faless/feature/network-local-port-salvaged
Diffstat (limited to 'core/io/tcp_server.cpp')
-rw-r--r-- | core/io/tcp_server.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp index 323d2bbd7f..348be66ba4 100644 --- a/core/io/tcp_server.cpp +++ b/core/io/tcp_server.cpp @@ -34,6 +34,7 @@ void TCP_Server::_bind_methods() { ClassDB::bind_method(D_METHOD("listen", "port", "bind_address"), &TCP_Server::listen, DEFVAL("*")); ClassDB::bind_method(D_METHOD("is_connection_available"), &TCP_Server::is_connection_available); ClassDB::bind_method(D_METHOD("is_listening"), &TCP_Server::is_listening); + ClassDB::bind_method(D_METHOD("get_local_port"), &TCP_Server::get_local_port); ClassDB::bind_method(D_METHOD("take_connection"), &TCP_Server::take_connection); ClassDB::bind_method(D_METHOD("stop"), &TCP_Server::stop); } @@ -42,6 +43,7 @@ Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) { 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); + ERR_FAIL_COND_V_MSG(p_port < 0 || p_port > 65535, ERR_INVALID_PARAMETER, "The local port number must be between 0 and 65535 (inclusive)."); Error err; IP::Type ip_type = IP::TYPE_ANY; @@ -74,6 +76,12 @@ Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) { return OK; } +int TCP_Server::get_local_port() const { + uint16_t local_port; + _sock->get_socket_address(nullptr, &local_port); + return local_port; +} + bool TCP_Server::is_listening() const { ERR_FAIL_COND_V(!_sock.is_valid(), false); |