Skip to content

NODERAWSOCKETS: socket fstat and SO_TYPE/SO_LINGER/TCP_MAXSEG options#27306

Open
guybedford wants to merge 1 commit into
emscripten-core:mainfrom
guybedford:sockets
Open

NODERAWSOCKETS: socket fstat and SO_TYPE/SO_LINGER/TCP_MAXSEG options#27306
guybedford wants to merge 1 commit into
emscripten-core:mainfrom
guybedford:sockets

Conversation

@guybedford

Copy link
Copy Markdown
Collaborator

Fills in some missing socket metadata and options for the node:net (-sNODERAWSOCKETS) backend, so more standard socket code behaves as it would on Linux.

  • fstat on a socket now reports S_IFSOCK (previously it fell through to a generic node), via a SOCKFS stream_ops.getattr that plugs into the FS.fstat dispatch already present on main.
  • getsockopt:
    • SO_TYPE reports the type the socket was created with.
    • SO_LINGER round-trips a struct linger.
    • TCP_MAXSEG reports a default MSS. Node exposes no real MSS, so this mirrors Linux: the RFC 879 default (536) before the connection is established, and the (large) loopback-negotiated value once connected.
  • setsockopt SO_LINGER is now honored on close: a zero timeout does an abortive RST close (resetAndDestroy), a positive timeout ends gracefully and forces the connection down once the interval elapses, and otherwise the connection is destroyed as before.

Adds test/sockets/test_socket_options.c (registered as test_noderawsockets_socket_options) covering socket fstat, SO_TYPE, SO_LINGER round-trip, and the pre-connect TCP_MAXSEG default.

Made with AI assistance under my review

Fills in socket metadata and a few socket options for the node:net backend:

* fstat on a socket now reports S_IFSOCK, via a SOCKFS stream_ops.getattr
  (the core FS.fstat already dispatches to stream_ops.getattr).
* getsockopt: SO_TYPE reports the socket type, SO_LINGER round-trips a struct
  linger, and TCP_MAXSEG reports a default MSS (536 pre-connect, the negotiated
  loopback value once connected) since node exposes no real MSS.
* setsockopt SO_LINGER is honored on close: a zero timeout does an abortive
  RST close (resetAndDestroy), a positive timeout ends gracefully and forces
  the connection down once the interval elapses.

Adds test/sockets/test_socket_options.c covering fstat/SO_TYPE/SO_LINGER.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant