Use tcp_nodelay on socket server#537
Conversation
The sockets we use in this library should be optimized for real-time communication, not for throughput. Therefore, they should use tcp_nodelay by default.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #537 +/- ##
==========================================
- Coverage 79.16% 78.71% -0.46%
==========================================
Files 115 115
Lines 6769 6775 +6
Branches 2991 3000 +9
==========================================
- Hits 5359 5333 -26
- Misses 1040 1069 +29
- Partials 370 373 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit dbe5e74. Configure here.
michal-milkowski
left a comment
There was a problem hiding this comment.
Is nodelay also set on client socket?
| } | ||
|
|
||
| int flag = 1; | ||
| ur_setsockopt(client_fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int)); |
There was a problem hiding this comment.
- check return value. Warn if option can't be set.
- it's better to use sizeof(flag) instead.
- this could be attempted on closed socket on line 260. either check if accepted == true or move flag set somewhere up
There was a problem hiding this comment.
Thank you for the comments. I implemented those in c73d273
| } | ||
| } | ||
|
|
||
| int flag = 1; |
There was a problem hiding this comment.
can be constexpr
| int flag = 1; | |
| constexpr int flag = 1; |
Yes, it is: I've updated that to use the |

The sockets we use in this library should be optimized for real-time communication, not for throughput. Therefore, they should use tcp_nodelay by default.
Note
Low Risk
Low-latency TCP tuning and non-fatal logging around setsockopt; no auth or data-model changes.
Overview
TCP sockets are tuned for lower latency by enabling
TCP_NODELAYon each accepted server connection (client outbound paths already set it inTCPSocket::setupOptions).Socket option setup is centralized in
setSocketOptionAndWarnOnError, which logs a warning whensetsockoptfails instead of ignoring errors. Listen socket options (SO_REUSEADDR,SO_KEEPALIVE) and client options (TCP_NODELAY,TCP_QUICKACK,SO_RCVTIMEO) now go through that helper.Reviewed by Cursor Bugbot for commit 21bab87. Bugbot is set up for automated code reviews on this repo. Configure here.