zhhyu7 opened a new pull request, #21632:
URL: https://github.com/apache/nuttx/pull/21632
## Summary
This series brings a batch of net/local (AF_LOCAL / Unix domain socket)
fixes up to date and reworks the SOCK_DGRAM send path so a datagram is
published to the FIFO as a single atomic frame.
Fixes and small features:
- add si_mmap for local socket
- remove extra lock to avoid deadlock
- fix: Resolve mutex recursive lock deadlock in local socket release
- Add a check to see if conn is in a listening state
- Fixed lc_type and lc_proto in the local socket client were overwritten by
the server
- set lc_peer in local_socketpair
- resolve Tasking warning W545 missing return
- give the default DGRAM rcvsize room for the preamble
Atomic-frame DGRAM (two layers):
- **drivers/pipes**: add pipecommon_writev() registered on the .writev fop,
byte-stream by default. A new PIPEIOC_ATOMICWRITE ioctl makes a writev() land
all-or-nothing under one d_bflock, returning
-EMSGSIZE for a request larger than the buffer.
- **net/local**: replace the old three-part preamble write with
local_send_frame(), which gathers [pathlen][pktlen][path][payload] into one
file_writev() on an atomic-mode FIFO. This closes a framing bug
where a reader woken by POLLIN could consume the preamble before its payload
existed and then desync the FIFO.
## Impact
- PIPEIOC_ATOMICWRITE and pipecommon_writev() are additive; the existing
pipecommon_write() byte-stream behavior is unchanged when atomic mode is not
enabled, so non-pipe/fifo users and existing pipe
users are unaffected.
- AF_LOCAL SOCK_DGRAM now enables atomic-write on the sender FIFO; the old
POLLIN-threshold workaround in local_open_receiver() is removed.
- Whole-frame size (preamble + path + payload) is checked against the peer's
lc_rcvsize before any write, so an oversized datagram is rejected with
-EMSGSIZE instead of partially overrunning the FIFO.
- local_send_frame() validates the incoming iovec count at runtime
(msg_iovlen is caller-controlled up to IOV_MAX): a request needing more than
LOCAL_FRAME_NIOV segments is rejected with -EMSGSIZE rather
than overrunning the on-stack iovec.
- Adapted to the current apache tree: the pipe locking uses rmutex_t
(nxrmutex_lock/unlock) rather than the spinlock the original internal change
assumed.
## Testing
Platform: sim (host gcc, x86_64).
Build:
./tools/configure.sh sim:nsh
# + CONFIG_NET=y, CONFIG_NET_LOCAL=y, CONFIG_NET_LOCAL_STREAM=y,
# CONFIG_NET_LOCAL_DGRAM=y
make
Compiles and links cleanly. nxstyle/checkpatch -g is clean on every one of
the 10 commits (verified per-commit).
Functional test (apps/examples/local_loopback, 6 cases) run on sim:
local_loopback: start (AF_LOCAL functional test)
[1/6] stream_socketpair
socketpair: round-trip OK (19 bytes)
[2/6] stream_large
stream_large: 4096 bytes transferred intact
[3/6] dgram_basic
dgram_basic: round-trip OK (19 bytes)
[4/6] dgram_multi_iov
dgram_multi_iov: 3 segments gathered into one frame OK
[5/6] dgram_too_many_iov
dgram_too_many_iov: rejected with EMSGSIZE as expected
[6/6] dgram_oversize
dgram_oversize: oversized datagram rejected with EMSGSIZE
local_loopback: 6/6 passed
local_loopback: PASS
--
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]