diff options
author | Roman Zeyde <me@romanzey.de> | 2024-08-18 18:17:24 +0300 |
---|---|---|
committer | Roman Zeyde <me@romanzey.de> | 2024-08-25 09:23:49 +0300 |
commit | 03d49d0f25ab5660524d5ddd171de677a808b984 (patch) | |
tree | d17569a708df05c2bf3a5b52bfe48774c6689dc7 /src | |
parent | 27a770b34b8f1dbb84760f442edb3e23a0c2420b (diff) | |
download | bitcoin-03d49d0f25ab5660524d5ddd171de677a808b984.tar.xz |
http: set TCP_NODELAY when creating HTTP server
Otherwise, the default HTTP server config may result in high latency.
[1] https://www.extrahop.com/blog/tcp-nodelay-nagle-quickack-best-practices
[2] https://eklitzke.org/the-caveats-of-tcp-nodelay
Diffstat (limited to 'src')
-rw-r--r-- | src/httpserver.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/httpserver.cpp b/src/httpserver.cpp index b6c6db8b35..7a8f0c0768 100644 --- a/src/httpserver.cpp +++ b/src/httpserver.cpp @@ -388,6 +388,12 @@ static bool HTTPBindAddresses(struct evhttp* http) if (i->first.empty() || (addr.has_value() && addr->IsBindAny())) { LogPrintf("WARNING: the RPC server is not safe to expose to untrusted networks such as the public internet\n"); } + // Set the no-delay option (disable Nagle's algorithm) on the TCP socket. + evutil_socket_t fd = evhttp_bound_socket_get_fd(bind_handle); + int one = 1; + if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (sockopt_arg_type)&one, sizeof(one)) == SOCKET_ERROR) { + LogInfo("WARNING: Unable to set TCP_NODELAY on RPC server socket, continuing anyway\n"); + } boundSockets.push_back(bind_handle); } else { LogPrintf("Binding RPC on address %s port %i failed.\n", i->first, i->second); |