From 5481ece9762174c75114ced9233e55e43a2f5a80 Mon Sep 17 00:00:00 2001 From: Marlon Henry Schweigert Date: Tue, 30 Jan 2018 13:22:15 -0200 Subject: [PATCH] Display set_nodelay to GDScript Pass enabled arg Rename set_nodelay to set_no_delay Add description to the method Change description (cherry picked from commit 87adf9cfbab00a40aad483b4e709518d5f61b6d1) --- core/io/file_access_network.cpp | 2 +- core/io/stream_peer_tcp.cpp | 1 + core/io/stream_peer_tcp.h | 2 +- doc/classes/StreamPeerTCP.xml | 10 ++++++++++ drivers/unix/stream_peer_tcp_posix.cpp | 2 +- drivers/unix/stream_peer_tcp_posix.h | 2 +- drivers/windows/stream_peer_tcp_winsock.cpp | 2 +- drivers/windows/stream_peer_tcp_winsock.h | 2 +- editor/fileserver/editor_file_server.cpp | 2 +- 9 files changed, 18 insertions(+), 7 deletions(-) diff --git a/core/io/file_access_network.cpp b/core/io/file_access_network.cpp index 7b2bccdfec6..ef886cdb3cf 100644 --- a/core/io/file_access_network.cpp +++ b/core/io/file_access_network.cpp @@ -83,7 +83,7 @@ int64_t FileAccessNetworkClient::get_64() { void FileAccessNetworkClient::_thread_func() { - client->set_nodelay(true); + client->set_no_delay(true); while (!quit) { DEBUG_PRINT("SEM WAIT - " + itos(sem->get())); diff --git a/core/io/stream_peer_tcp.cpp b/core/io/stream_peer_tcp.cpp index 9cfa8100348..5d008904ffe 100644 --- a/core/io/stream_peer_tcp.cpp +++ b/core/io/stream_peer_tcp.cpp @@ -55,6 +55,7 @@ void StreamPeerTCP::_bind_methods() { ClassDB::bind_method(D_METHOD("get_connected_host"), &StreamPeerTCP::get_connected_host); ClassDB::bind_method(D_METHOD("get_connected_port"), &StreamPeerTCP::get_connected_port); ClassDB::bind_method(D_METHOD("disconnect_from_host"), &StreamPeerTCP::disconnect_from_host); + ClassDB::bind_method(D_METHOD("set_no_delay", "enabled"), &StreamPeerTCP::set_no_delay); BIND_ENUM_CONSTANT(STATUS_NONE); BIND_ENUM_CONSTANT(STATUS_CONNECTING); diff --git a/core/io/stream_peer_tcp.h b/core/io/stream_peer_tcp.h index fc84525c5f3..8a16d820f28 100644 --- a/core/io/stream_peer_tcp.h +++ b/core/io/stream_peer_tcp.h @@ -65,7 +65,7 @@ public: virtual void disconnect_from_host() = 0; virtual IP_Address get_connected_host() const = 0; virtual uint16_t get_connected_port() const = 0; - virtual void set_nodelay(bool p_enabled) = 0; + virtual void set_no_delay(bool p_enabled) = 0; static Ref create_ref(); static StreamPeerTCP *create(); diff --git a/doc/classes/StreamPeerTCP.xml b/doc/classes/StreamPeerTCP.xml index 37fec62cbc7..73e9b97367a 100644 --- a/doc/classes/StreamPeerTCP.xml +++ b/doc/classes/StreamPeerTCP.xml @@ -29,6 +29,16 @@ Disconnect from host. + + + + + + + Disable Nagle algorithm to improve latency for small packets. + Note that for applications that send large packets, or need to transfer a lot of data, this can reduce total bandwidth. + + diff --git a/drivers/unix/stream_peer_tcp_posix.cpp b/drivers/unix/stream_peer_tcp_posix.cpp index ba9481d36b2..17112e5ab5c 100644 --- a/drivers/unix/stream_peer_tcp_posix.cpp +++ b/drivers/unix/stream_peer_tcp_posix.cpp @@ -304,7 +304,7 @@ Error StreamPeerTCPPosix::read(uint8_t *p_buffer, int p_bytes, int &r_received, return OK; }; -void StreamPeerTCPPosix::set_nodelay(bool p_enabled) { +void StreamPeerTCPPosix::set_no_delay(bool p_enabled) { ERR_FAIL_COND(!is_connected_to_host()); int flag = p_enabled ? 1 : 0; diff --git a/drivers/unix/stream_peer_tcp_posix.h b/drivers/unix/stream_peer_tcp_posix.h index 5770ae48f4d..bcebe577715 100644 --- a/drivers/unix/stream_peer_tcp_posix.h +++ b/drivers/unix/stream_peer_tcp_posix.h @@ -77,7 +77,7 @@ public: virtual Status get_status() const; virtual void disconnect_from_host(); - virtual void set_nodelay(bool p_enabled); + virtual void set_no_delay(bool p_enabled); static void make_default(); diff --git a/drivers/windows/stream_peer_tcp_winsock.cpp b/drivers/windows/stream_peer_tcp_winsock.cpp index d6a320fb5ef..55775fc2318 100644 --- a/drivers/windows/stream_peer_tcp_winsock.cpp +++ b/drivers/windows/stream_peer_tcp_winsock.cpp @@ -332,7 +332,7 @@ Error StreamPeerTCPWinsock::connect_to_host(const IP_Address &p_host, uint16_t p return OK; }; -void StreamPeerTCPWinsock::set_nodelay(bool p_enabled) { +void StreamPeerTCPWinsock::set_no_delay(bool p_enabled) { ERR_FAIL_COND(!is_connected_to_host()); int flag = p_enabled ? 1 : 0; setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int)); diff --git a/drivers/windows/stream_peer_tcp_winsock.h b/drivers/windows/stream_peer_tcp_winsock.h index 9be84148783..a0177d374e5 100644 --- a/drivers/windows/stream_peer_tcp_winsock.h +++ b/drivers/windows/stream_peer_tcp_winsock.h @@ -81,7 +81,7 @@ public: static void make_default(); static void cleanup(); - virtual void set_nodelay(bool p_enabled); + virtual void set_no_delay(bool p_enabled); StreamPeerTCPWinsock(); ~StreamPeerTCPWinsock(); diff --git a/editor/fileserver/editor_file_server.cpp b/editor/fileserver/editor_file_server.cpp index 56fb7633e77..a218070933e 100644 --- a/editor/fileserver/editor_file_server.cpp +++ b/editor/fileserver/editor_file_server.cpp @@ -55,7 +55,7 @@ void EditorFileServer::_subthread_start(void *s) { ClientData *cd = (ClientData *)s; - cd->connection->set_nodelay(true); + cd->connection->set_no_delay(true); uint8_t buf4[8]; Error err = cd->connection->get_data(buf4, 4); if (err != OK) {