Skip to content

Use tcp_nodelay on socket server#537

Merged
urfeex merged 5 commits into
UniversalRobots:masterfrom
urfeex:use_tcp_nodelay
Jul 10, 2026
Merged

Use tcp_nodelay on socket server#537
urfeex merged 5 commits into
UniversalRobots:masterfrom
urfeex:use_tcp_nodelay

Conversation

@urfeex

@urfeex urfeex commented Jul 10, 2026

Copy link
Copy Markdown
Member

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_NODELAY on each accepted server connection (client outbound paths already set it in TCPSocket::setupOptions).

Socket option setup is centralized in setSocketOptionAndWarnOnError, which logs a warning when setsockopt fails 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.

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.
@urfeex
urfeex requested a review from a team July 10, 2026 07:12
@urfeex
urfeex marked this pull request as draft July 10, 2026 07:14
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.71%. Comparing base (b437116) to head (21bab87).

Files with missing lines Patch % Lines
include/ur_client_library/comm/socket_t.h 40.00% 2 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
check_version_ur10-3.15.8 11.82% <40.00%> (-0.21%) ⬇️
check_version_ur10e-10.11.0 11.12% <40.00%> (+0.01%) ⬆️
check_version_ur10e-5.15.2 11.12% <40.00%> (-0.22%) ⬇️
check_version_ur12e-10.12.1 11.12% <40.00%> (-0.03%) ⬇️
check_version_ur12e-5.25.1 11.12% <40.00%> (-0.17%) ⬇️
check_version_ur15-10.12.1 11.12% <40.00%> (-0.08%) ⬇️
check_version_ur15-5.25.1 11.12% <40.00%> (-0.22%) ⬇️
check_version_ur16e-10.12.1 11.12% <40.00%> (-0.03%) ⬇️
check_version_ur16e-5.25.1 11.31% <40.00%> (-0.03%) ⬇️
check_version_ur18-10.12.1 11.12% <40.00%> (-0.08%) ⬇️
check_version_ur18-5.25.1 11.12% <40.00%> (+0.01%) ⬆️
check_version_ur20-10.12.1 11.17% <40.00%> (-0.03%) ⬇️
check_version_ur20-5.25.1 11.12% <40.00%> (-0.03%) ⬇️
check_version_ur3-3.14.3 11.17% <40.00%> (-0.28%) ⬇️
check_version_ur30-10.12.1 11.12% <40.00%> (-0.03%) ⬇️
check_version_ur30-5.25.1 11.31% <40.00%> (+0.04%) ⬆️
check_version_ur3e-10.11.0 11.12% <40.00%> (-0.03%) ⬇️
check_version_ur3e-5.9.4 11.88% <40.00%> (+0.73%) ⬆️
check_version_ur5-3.15.8 10.56% <40.00%> (-1.06%) ⬇️
check_version_ur5e-10.11.0 11.12% <40.00%> (+0.01%) ⬆️
check_version_ur5e-5.12.8 11.17% <40.00%> (-0.35%) ⬇️
check_version_ur7e-10.11.0 11.12% <40.00%> (-0.08%) ⬇️
check_version_ur7e-5.22.2 11.12% <40.00%> (-0.75%) ⬇️
check_version_ur8long-10.12.1 11.12% <40.00%> (-0.08%) ⬇️
check_version_ur8long-5.25.1 11.12% <40.00%> (-0.17%) ⬇️
python_scripts 75.90% <ø> (ø)
start_ursim 82.48% <ø> (-2.67%) ⬇️
ur5-3.14.3 74.60% <80.00%> (-0.07%) ⬇️
ur5e-10.11.0 69.16% <80.00%> (-0.09%) ⬇️
ur5e-10.12.0 70.30% <80.00%> (-0.20%) ⬇️
ur5e-10.7.0 68.57% <80.00%> (-0.42%) ⬇️
ur5e-5.9.4 75.19% <80.00%> (-0.25%) ⬇️
ur7e-10.13.0 70.34% <80.00%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit dbe5e74. Configure here.

Comment thread src/comm/tcp_server.cpp Outdated
@urfeex
urfeex marked this pull request as ready for review July 10, 2026 07:23
@urfeex
urfeex requested a review from michal-milkowski July 10, 2026 07:25

@michal-milkowski michal-milkowski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is nodelay also set on client socket?

Comment thread src/comm/tcp_server.cpp Outdated
}

int flag = 1;
ur_setsockopt(client_fd, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. check return value. Warn if option can't be set.
  2. it's better to use sizeof(flag) instead.
  3. this could be attempted on closed socket on line 260. either check if accepted == true or move flag set somewhere up

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the comments. I implemented those in c73d273

Comment thread src/comm/tcp_server.cpp Outdated
}
}

int flag = 1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be constexpr

Suggested change
int flag = 1;
constexpr int flag = 1;

@urfeex

urfeex commented Jul 10, 2026

Copy link
Copy Markdown
Member Author

Is nodelay also set on client socket?

Yes, it is:

ur_setsockopt(socket_fd_, IPPROTO_TCP, TCP_NODELAY, &flag, sizeof(int));

I've updated that to use the setSocketOptionAndWarnOnError function, as well.

@urfeex
urfeex requested a review from michal-milkowski July 10, 2026 09:12
@urfeex
urfeex merged commit 84d65c7 into UniversalRobots:master Jul 10, 2026
88 of 98 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants