jingfei195887 opened a new pull request, #21755:
URL: https://github.com/apache/nuttx/pull/21755

   ## Summary
   
   Two fixes in the socket file layer.
   
   - **fs/socket: add readv and writev to the socket file operations.** The
     socket file operations had no readv or writev method, so `readv()` and
     `writev()` on a socket fell back to one read or write per iovec. On a
     datagram socket `writev()` sent each buffer as its own datagram, and
     `readv()` truncated a datagram to the first buffer. They now go through
     `psock_recvmsg()`/`psock_sendmsg()` with the whole iovec, and `writev()`
     raises SIGPIPE like `write()`.
   - **fs/socket: release the listening socket when accept() is canceled.**
     `accept4()` holds a reference to the listening socket while it waits. An
     asynchronous cancel there tears the thread down before `file_put()`, so
     the listening socket is never released and a new `bind()` to the same
     address fails with EADDRINUSE. A cleanup handler now drops the reference.
   
   ## Impact
   
   `readv()`/`writev()` on a socket keep message boundaries, as on other
   systems. The cleanup handler only has an effect with
   `CONFIG_TLS_NCLEANUP > 0`; without it the push and pop compile away.
   
   ## Testing
   
   Host: Ubuntu x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0, master 
72c45233a0 (rebased onto 72c45233a0; no new
   commit touches fs/socket), `sim:nsh` with `CONFIG_NET_LOOPBACK`,
   `CONFIG_NET_TCP`, `CONFIG_NET_UDP`, `CONFIG_CANCELLATION_POINTS` and
   `CONFIG_TLS_NCLEANUP=4`. A small test program on 127.0.0.1:
   
   | step | master | this PR |
   |---|---|---|
   | UDP `writev()` of 2 x 4 bytes | 2 datagrams of 4 bytes | 1 datagram of 8 
bytes |
   | non-blocking `readv()` of an 8-byte datagram into 2 x 4 bytes | 4, "1234" 
"" | 8, "1234" "5678" |
   | thread blocked in `accept()`, deferred cancel, close, `bind()` again | ok 
| ok |
   | same with asynchronous cancel | EADDRINUSE | ok |
   
   - `./tools/checkpatch.sh -g master..HEAD`: all checks pass.
   - Make and CMake builds pass with no warnings in the changed files;
     `ostest` exits with status 0.
   


-- 
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]

  • [PR] fs/socket: add readv/wri... jingfei195887 (via GitHub) via commits

Reply via email to