casaroli opened a new pull request, #22441: URL: https://github.com/apache/nuttx/pull/22441
## Summary `setsockopt(IPPROTO_TCP, TCP_CORK, 1)` fails with `ENOSYS`. HTTP servers set `TCP_CORK` around a response that they send with `sendfile()`, and some end the response with an error when the call fails. The stack has no Nagle algorithm and sends each write at once. So `TCP_CORK` can only be a hint here: `setsockopt()` now stores the value per connection and `getsockopt()` reports it. No segment is held back. This is what a program can see on Linux too: a corked partial segment goes out at the latest after 200 ms, and when the cork is removed. The data and its order do not change. `TCP_NODELAY` 0 is still refused. Commit 1 only fixes the nxstyle errors of `tcp_getsockopt.c` and `tcp_setsockopt.c` (blank lines and indentation, `git diff -w` shows blank lines only), so that the CI style check of the touched files passes. ## Impact `setsockopt()`/`getsockopt()` of `TCP_CORK` (with `CONFIG_NET_TCPPROTO_OPTIONS`). Before: `TCP_CORK` 1 failed with `ENOSYS`, 0 was accepted, `getsockopt()` gave 0. Now: both are accepted and `getsockopt()` gives the value back. No API or ABI change, no new Kconfig option. The new `bool` field of `struct tcp_conn_s` fills a padding hole: the size of the structure does not change (`nm -S` of `g_tcp_connections_buffer`: 0xec8 bytes on qemu-armv8a:knsh before and after; +20 bytes of text). Common network code: the same in flat, protected and kernel builds and on all architectures. ## Testing New case `test_tcp_cork` in `cmocka_net_tcp` (apache/nuttx-apps#NNNN): `TCP_CORK` 1 and 0 are accepted, `getsockopt()` gives them back, and a byte sent while the socket is corked reaches the peer when the cork is removed. | qemu-armv8a:nsh (flat), QEMU TCG, CI image (gcc 12.3), 3 boots | master 24f2db7fe8d | this PR | |---|---|---| | `test_tcp_cork` | FAIL 3 of 3: `setsockopt(TCP_CORK, 1)` gives `ENOSYS` | PASS 3 of 3 | Whole `cmocka_net_tcp` (1 boot each, `CONFIG_NET_TCP_PREALLOC_CONNS=32`, with the cases of this PR and of the backlog RST PR #22440): master fails `test_tcp_cork`, `test_tcp_backlog_close_reset` and `test_tcp_reset_send`; with the fixes only `test_tcp_reset_send` fails (37 of 38 pass). `test_tcp_reset_send` fails on master too in a flat build (`SIGPIPE` goes to another thread). With the default 8 connections the race cases of the same file can fail on both sides with `socket()` errors: the earlier cases leave connections in TIME_WAIT. Builds with `-Werror` in the CI image (gcc 12.3): qemu-armv8a:nsh (flat, with `cmocka_net_tcp`) and qemu-armv8a:knsh (kernel), rv-virt:netnsh64 (flat, with `cmocka_net_tcp`) and rv-virt:knetnsh64 (kernel), with `CONFIG_NET_TCPPROTO_OPTIONS`; no new warning. Protected build: not built (common network code, no build-mode test). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
