ソースを参照

Add TCP poll function (not exposed).

Used to know if we can read or write without blocking.
Fabio Alessandrelli 5 年 前
コミット
74051c77dc
2 ファイル変更8 行追加0 行削除
  1. 5 0
      core/io/stream_peer_tcp.cpp
  2. 3 0
      core/io/stream_peer_tcp.h

+ 5 - 0
core/io/stream_peer_tcp.cpp

@@ -288,6 +288,11 @@ void StreamPeerTCP::disconnect_from_host() {
 	peer_port = 0;
 }
 
+Error StreamPeerTCP::poll(NetSocket::PollType p_type, int timeout) {
+	ERR_FAIL_COND_V(_sock.is_null() || !_sock->is_open(), ERR_UNAVAILABLE);
+	return _sock->poll(p_type, timeout);
+}
+
 Error StreamPeerTCP::put_data(const uint8_t *p_data, int p_bytes) {
 
 	int total;

+ 3 - 0
core/io/stream_peer_tcp.h

@@ -78,6 +78,9 @@ public:
 
 	void set_no_delay(bool p_enabled);
 
+	// Poll functions (wait or check for writable, readable)
+	Error poll(NetSocket::PollType p_type, int timeout = 0);
+
 	// Read/Write from StreamPeer
 	Error put_data(const uint8_t *p_data, int p_bytes);
 	Error put_partial_data(const uint8_t *p_data, int p_bytes, int &r_sent);