Sarthak-Pandey commented on PR #20702:
URL: https://github.com/apache/nuttx/pull/20702#issuecomment-6605953077
Hi @casaroli,
Thank you for the thorough and insightful review! I have addressed all of
your feedback and pushed an updated commit to the branch:
### 1. Code Fixes (`net/local/local_recvmsg.c`)
- **Non-blocking lock contention (`lc_recvlock` + `MSG_DONTWAIT`):**
When `flags & MSG_DONTWAIT` (or `_SS_ISNONBLOCK(conn->lc_conn.s_flags)`)
is set, we now acquire `lc_recvlock` using
`nxmutex_trylock(&conn->lc_recvlock)`. If the lock is held by a concurrent
thread, it returns `-EAGAIN` immediately without blocking.
- **Next `iov` boundary blocking:**
Before reading into subsequent `iov` buffers (`total_recv > 0 && !(flags &
MSG_WAITALL)`), we check available FIFO bytes using
`file_ioctl(&conn->lc_infile, FIONREAD, &data_len)`. If `data_len == 0`, the
loop breaks immediately and returns `total_recv` rather than blocking inside
`local_fifo_read()`.
- **Preserve error code when `from != NULL`:**
Added guard `if (total_recv == 0 && ret < 0) goto errout_with_lock;`
before calling `local_getaddr()`. This ensures that errors (such as `-EAGAIN`
on empty non-blocking sockets) are not overwritten to `0` by `local_getaddr()`.
### 2. Commit Message
- Restored the `Assisted-by: Gemini:gemini-3.8-flash` tag right above
`Signed-off-by` per `CONTRIBUTING.md` Section 1.5.
### 3. PR Description & Documentation Alignment
- **Local DGRAM clarification:** Explicitly noted in the summary and impact
sections that `local SOCK_DGRAM` remains unchanged and continues to return
`-ENOTSUP` for `msg_iovlen > 1` (scatter-gather is supported for Local stream
sockets).
- **Summary clean-up:** Removed Item 3 from "Why change is necessary" which
referred to an earlier PR iteration's race rather than master.
- **Concurrent Reader Test Log:** Added a 4th test run log in the PR
description demonstrating two concurrent reader threads on an `AF_LOCAL` stream
socket:
1. Thread 1 holds `lc_recvlock` waiting for stream data.
2. Thread 2 attempts `recvmsg(MSG_DONTWAIT)` and returns `-EAGAIN`
immediately without blocking on the lock.
3. Inbound stream data is read atomically by Thread 1 across all 4
`iovec`s without interleaving.
All modified files pass `tools/nxstyle` cleanly with 0 errors and 0
warnings. Please take another look!
--
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]