diff options
author | B. Stack <bgstack15@gmail.com> | 2024-06-23 16:51:52 -0400 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2024-06-23 16:51:52 -0400 |
commit | 994ec9e1cba547bed6eef02f996ca2a7beaf777a (patch) | |
tree | c6bdfb8c2096a1c579d3603e050d5f697d2306e0 /zen/socket.h | |
parent | add upstream 13.6 (diff) | |
download | FreeFileSync-994ec9e1cba547bed6eef02f996ca2a7beaf777a.tar.gz FreeFileSync-994ec9e1cba547bed6eef02f996ca2a7beaf777a.tar.bz2 FreeFileSync-994ec9e1cba547bed6eef02f996ca2a7beaf777a.zip |
add upstream 13.713.7
Diffstat (limited to 'zen/socket.h')
-rw-r--r-- | zen/socket.h | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/zen/socket.h b/zen/socket.h index 0a311d01..461226d0 100644 --- a/zen/socket.h +++ b/zen/socket.h @@ -141,16 +141,6 @@ public: } setNonBlocking(testSocket, false); //throw SysError - //----------------------------------------------------------- - - int noDelay = 1; //disable Nagle algorithm: https://brooker.co.za/blog/2024/05/09/nagle.html - //e.g. test case "website sync": 23% shorter comparison time! - if (::setsockopt(testSocket, //_In_ SOCKET s - IPPROTO_TCP, //_In_ int level - TCP_NODELAY, //_In_ int optname - reinterpret_cast<char*>(&noDelay), //_In_ const char* optval - sizeof(noDelay)) != 0) //_In_ int optlen - THROW_LAST_SYS_ERROR_WSA("setsockopt(TCP_NODELAY)"); return testSocket; }; @@ -163,11 +153,26 @@ public: try { socket_ = getConnectedSocket(*si); //throw SysError; pass ownership - return; + firstError = std::nullopt; + break; } catch (const SysError& e) { if (!firstError) firstError = e; } - throw* firstError; //list was not empty, so there must have been an error! + if (firstError) + throw* firstError; + assert(socket_ != invalidSocket); //list was non-empty, so there's either an error, or a valid socket + ZEN_ON_SCOPE_FAIL(closeSocket(socket_)); + //----------------------------------------------------------- + //configure *after* selecting appropriate socket: cfg-failure should not discard otherwise fine connection! + + int noDelay = 1; //disable Nagle algorithm: https://brooker.co.za/blog/2024/05/09/nagle.html + //e.g. test case "website sync": 23% shorter comparison time! + if (::setsockopt(socket_, //_In_ SOCKET s + IPPROTO_TCP, //_In_ int level + TCP_NODELAY, //_In_ int optname + reinterpret_cast<const char*>(&noDelay), //_In_ const char* optval + sizeof(noDelay)) != 0) //_In_ int optlen + THROW_LAST_SYS_ERROR_WSA("setsockopt(TCP_NODELAY)"); } ~Socket() { closeSocket(socket_); } |