Repository navigation
NODERAWSOCKETS: make setsockopt/getsockopt symmetric - #27921
Merged
Merged
Conversation
sbc100
reviewed
Oct 8, 2026
sbc100
reviewed
Oct 8, 2026
sbc100
reviewed
Oct 8, 2026
sbc100
reviewed
Oct 8, 2026
sbc100
reviewed
Oct 8, 2026
sbc100
approved these changes
Oct 8, 2026
sbc100
reviewed
Oct 8, 2026
sbc100
reviewed
Oct 8, 2026
Store and report SO_RCVTIMEO/SO_SNDTIMEO (struct timeval); report SO_ACCEPTCONN, SO_DOMAIN and SO_PROTOCOL; reject options that are not modelled with ENOPROTOOPT instead of accepting them silently. SO_REUSEADDR/SO_REUSEPORT are now actually applied to UDP binds so datagram sockets can share a port. Fixes emscripten-core#27888
sbc100
approved these changes
Oct 8, 2026
sbc100
enabled auto-merge (squash)
October 8, 2026 22:04
guybedford
added a commit
that referenced
this pull request
Nov 3, 2026
This adds UDP multicast group membership to `-sNODERAWSOCKETS`. Since #27921, `setsockopt` rejects options it doesn't model, so `IP_ADD_MEMBERSHIP` and its IPv6 equivalent now fail with `ENOPROTOOPT`. Before, they were silently accepted and had no effect. Group membership is now modelled on both the dgram and udp_wrap backends, which both expose `addMembership`/`dropMembership`: * `IP_ADD_MEMBERSHIP`/`IP_DROP_MEMBERSHIP` (`struct ip_mreq`, or `ip_mreqn` with an interface address) and `IPV6_JOIN_GROUP`/`IPV6_LEAVE_GROUP` * a join made before `bind()` is applied once the socket is bound, since otherwise libuv would auto-bind it to an ephemeral port * groups are joined again on the new socket that a UDP re-connect swaps in (#28146) * node picks the interface by address (IPv4) or by name (IPv6), so an interface given only by index returns `ENODEV` * as on Linux, the options are set-only, and `getsockopt` rejects them `test_noderawsockets_udp_multicast_membership` covers join and leave, the kernel's `EADDRINUSE` on a duplicate join and `EADDRNOTAVAIL` on leaving a group that wasn't joined, a join before `bind()`, and a short `optlen`. The IPv6 part is skipped on hosts without an IPv6 multicast route.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This makes
setsockoptandgetsockoptconsistent under-sNODERAWSOCKETS, resolves #27888.Previously
setsockoptaccepted any unknown option silently whilegetsockoptreturnedENOPROTOOPTfor it, so a value that had just been set successfully could not be read back (e.g.SO_RCVTIMEO).SO_REUSEADDRalso always read back as 1 but was never actually applied to UDP binds.SO_RCVTIMEO/SO_SNDTIMEOare stored and reported as astruct timeval, validated as the kernel does (EINVALon a short length,EDOMon an out-of-rangetv_usec). Nothing blocks in this backend, so this matches kernel semantics for anO_NONBLOCKsocket, where the timeout is stored but never fires.SO_REUSEADDRandSO_REUSEPORTare now passed to the UDP bind (both the publicdgramandudp_wrappaths), so datagram sockets can share a port.IPV6_V6ONLYis passed through for UDP too.SO_ACCEPTCONN,SO_DOMAINandSO_PROTOCOLare reported.ENOPROTOOPTinsetsockoptas well, so everything accepted can be read back.test_socket_options.cis extended to cover the above and a newtest_udp_reuseaddr.cchecks that two UDP sockets with the option can bind the same port while a third without it getsEADDRINUSE. Both tests also pass natively on Linux.Made with AI assistance under my review