diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-07-04 15:55:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-04 15:55:33 +0200 |
commit | 550f436f8fbea86984a845c821270fba78189143 (patch) | |
tree | 93985664212af0602cea06547273015ee580acc2 /core/io | |
parent | 7b569e91c0c6b84965cad416b8e86dcfdacbcfc4 (diff) | |
parent | 3380dc963895d1f97d4f06c3a71fe15d1c04d9fe (diff) |
Merge pull request #30263 from Faless/ws/wslay_pr
Use wslay as a WebSocket library
Diffstat (limited to 'core/io')
-rw-r--r-- | core/io/stream_peer_tcp.cpp | 5 | ||||
-rw-r--r-- | core/io/tcp_server.cpp | 7 | ||||
-rw-r--r-- | core/io/tcp_server.h | 1 |
3 files changed, 13 insertions, 0 deletions
diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index bcdae343b8..a8dd263484 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -217,6 +217,11 @@ Error StreamPeerTCP::read(uint8_t *p_buffer, int p_bytes, int &r_received, bool to_read -= read; total_read += read; + + if (!p_block) { + r_received = total_read; + return OK; + } } } 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(); |