summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2019-06-30 19:28:13 +0200
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2019-07-03 18:42:46 +0200
commitc13be7959439edd03b3fabf8a73a301784bce2b6 (patch)
treee4068697fcaf027c222a7b59ad653af77f8535f5
parent24c52f1c2e6a9726142bc816a79339e99bebd862 (diff)
Add TCP Server is_listening method
-rw-r--r--core/io/tcp_server.cpp7
-rw-r--r--core/io/tcp_server.h1
-rw-r--r--doc/classes/TCP_Server.xml7
3 files changed, 15 insertions, 0 deletions
diff --git a/core/io/tcp_server.cpp b/core/io/tcp_server.cpp
index be87f47d50..a2756164bc 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("take_connection"), &TCP_Server::take_connection);
ClassDB::bind_method(D_METHOD("stop"), &TCP_Server::stop);
}
@@ -75,6 +76,12 @@ Error TCP_Server::listen(uint16_t p_port, const IP_Address &p_bind_address) {
return OK;
}
+bool TCP_Server::is_listening() const {
+ ERR_FAIL_COND_V(!_sock.is_valid(), false);
+
+ return _sock->is_open();
+}
+
bool TCP_Server::is_connection_available() const {
ERR_FAIL_COND_V(!_sock.is_valid(), false);
diff --git a/core/io/tcp_server.h b/core/io/tcp_server.h
index 538db175ad..ef64044599 100644
--- a/core/io/tcp_server.h
+++ b/core/io/tcp_server.h
@@ -50,6 +50,7 @@ protected:
public:
Error listen(uint16_t p_port, const IP_Address &p_bind_address = IP_Address("*"));
+ bool is_listening() const;
bool is_connection_available() const;
Ref<StreamPeerTCP> take_connection();
diff --git a/doc/classes/TCP_Server.xml b/doc/classes/TCP_Server.xml
index 432d83f25b..cac3a0b082 100644
--- a/doc/classes/TCP_Server.xml
+++ b/doc/classes/TCP_Server.xml
@@ -16,6 +16,13 @@
Returns [code]true[/code] if a connection is available for taking.
</description>
</method>
+ <method name="is_listening" qualifiers="const">
+ <return type="bool">
+ </return>
+ <description>
+ Returns [code]true[/code] if the server is currently listening for connections.
+ </description>
+ </method>
<method name="listen">
<return type="int" enum="Error">
</return>