Skip to content

Commit 7f610a2

Browse files
committed
[WS] Fix set_no_delay on Windows
Windows socket implementation is, as usual, broken in many ways. This includes `setsockopt` failing to set `TCP_NODELAY` if the socket is still in a connecting state. This also means we need to keep polling the IP resolver until the socket reaches the CONNECTED state (so it can set the TCP_NODELAY after the connection is successful).
1 parent eabeafd commit 7f610a2

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

modules/websocket/wsl_peer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ void WSLPeer::Resolver::try_next_candidate(Ref<StreamPeerTCP> &p_tcp) {
9999
p_tcp->poll();
100100
StreamPeerTCP::Status status = p_tcp->get_status();
101101
if (status == StreamPeerTCP::STATUS_CONNECTED) {
102+
// On Windows, setting TCP_NODELAY may fail if the socket is still connecting.
103+
p_tcp->set_no_delay(true);
102104
ip_candidates.clear();
103105
return;
104106
} else if (status == StreamPeerTCP::STATUS_CONNECTING) {
@@ -112,7 +114,6 @@ void WSLPeer::Resolver::try_next_candidate(Ref<StreamPeerTCP> &p_tcp) {
112114
while (ip_candidates.size()) {
113115
Error err = p_tcp->connect_to_host(ip_candidates.pop_front(), port);
114116
if (err == OK) {
115-
p_tcp->set_no_delay(true);
116117
return;
117118
} else {
118119
p_tcp->disconnect_from_host();
@@ -311,7 +312,7 @@ void WSLPeer::_do_client_handshake() {
311312
ERR_FAIL_COND(tcp.is_null());
312313

313314
// Try to connect to candidates.
314-
if (resolver.has_more_candidates()) {
315+
if (resolver.has_more_candidates() || tcp->get_status() == StreamPeerTCP::STATUS_CONNECTING) {
315316
resolver.try_next_candidate(tcp);
316317
if (resolver.has_more_candidates()) {
317318
return; // Still pending.

0 commit comments

Comments
 (0)