zhhyu7 opened a new pull request, #21418: URL: https://github.com/apache/nuttx/pull/21418
## Summary
Two changes to AF_LOCAL `SOCK_DGRAM` sockets, both lifting an `-ENOSYS`.
`net/local: add poll support for SOCK_DGRAM local sockets` —
`local_pollsetup()`
and `local_pollteardown()` returned `-ENOSYS` for DGRAM because the receiver
FIFO was opened only for the duration of each `recvfrom()`, so there was no
persistent `lc_infile` to hand to `file_poll()`. Create and open the
receiver
FIFO in `psock_local_bind()` instead, and forward poll setup/teardown to
`file_poll()`.
`net/local: add connect support for DGRAM sockets` — POSIX lets `connect()`
on
a datagram socket record a default peer so that plain `send()` works.
`local_connect()` returned `-ENOSYS`. Store the peer in a new
`lc_daddr` field, allow `local_sendto()` to run in `LOCAL_STATE_CONNECTED`
(connect only records an address, it does not open a FIFO), and have
`local_send()` on a DGRAM socket forward to `local_sendto()` with the stored
address. `local_send()` is moved below `local_sendto()` so it can call it.
Files: `net/local/{local.h,local_bind.c,local_conn.c,local_netpoll.c,
local_sendmsg.c,local_sockif.c}`.
## Impact
AF_LOCAL DGRAM only; stream sockets are untouched apart from `local_send()`
no longer sharing its body with the DGRAM case. `bind()` now allocates the
receiver FIFO, so a DGRAM socket that is bound but never read holds a FIFO
for its whole lifetime, and `bind()` can now fail with the errors
`local_create_halfduplex()`/`local_open_receiver()` report.
## Testing
`sim:udgram` (`CONFIG_NET_LOCAL_DGRAM=y`, `CONFIG_MM_KASAN=y`), a test app
covering the two new capabilities plus the behaviour they must not break:
=== unbound socket must look unnamed
getsockname -> zero-length sun_path OK ret=0 addrlen=2
=== two unbound sockets must not collide on bind
bind first OK
bind second (not EADDRINUSE) OK
=== bind + poll
bind receiver OK
poll, no data -> timeout not ENOSYS OK
=== connect + send
bind sender OK
connect to receiver (was ENOSYS) OK
send() with no address OK
poll reports POLLIN after send OK
recv gets the payload OK hello
=== AF_UNSPEC dissolves the association
connect(AF_UNSPEC) OK
send() now EDESTADDRREQ OK
=== AF_UNSPEC with a short addrlen
connect(AF_UNSPEC, addrlen=2) OK
=== connect with a short addrlen
connect(addrlen < sockaddr_un) OK
send() after short connect OK
RESULT: PASS (failures=0)
Both commits build individually, and `tools/checkpatch.sh -c -u -m -g
apache/master..HEAD` passes.
--
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]
