Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions site/source/docs/tools_reference/settings_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,34 @@ sockets calls from browser to native world.

Default value: false

.. _noderawsockets:

NODERAWSOCKETS
==============

If enabled, the POSIX sockets API is backed by Node.js's ``node:net``
module, giving real non-blocking outgoing TCP sockets with no WebSockets,
proxy process or pthreads. This is the sockets counterpart to NODERAWFS:
where NODERAWFS gives direct access to the host filesystem, this gives
direct access to host sockets. It only works under node and is ignored
elsewhere.

It supports full TCP (outgoing connect plus bind, listen and accept for
servers) and UDP. TCP clients use the public node:net API when possible,
falling back to the private tcp_wrap/udp_wrap handles on older Node.js.

It is event-driven. Socket readiness comes through the same
``emscripten_set_socket_*_callback`` hooks the WebSocket backend uses, so it
works with existing readiness reactors. It cannot be combined with the
WebSocket emulation, PROXY_POSIX_SOCKETS or SOCKET_WEBRTC.

It works under -pthread with PROXY_TO_PTHREAD, where main() and every socket
syscall run on a single worker alongside the node handles and their event
loop. As with the WebSocket backend, sharing a socket across threads under a
plain -pthread build (without PROXY_TO_PTHREAD) is not supported.

Default value: false

.. _websocket_subprotocol:

WEBSOCKET_SUBPROTOCOL
Expand Down
1 change: 1 addition & 0 deletions src/lib/libsigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ sigs = {
__syscall_rmdir__sig: 'ip',
__syscall_sendmsg__sig: 'iipiiii',
__syscall_sendto__sig: 'iippipi',
__syscall_setsockopt__sig: 'iiiipii',
__syscall_shutdown__sig: 'iiiiiii',
__syscall_socket__sig: 'iiiiiii',
__syscall_stat64__sig: 'ipp',
Expand Down
18 changes: 14 additions & 4 deletions src/lib/libsockfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ addToLibrary({
$SOCKFS__postset: () => {
addAtInit('SOCKFS.root = FS.mount(SOCKFS, {}, null);');
},
$SOCKFS__deps: ['$FS'],
$SOCKFS__deps: ['$FS',
#if NODERAWSOCKETS
'$nodeSockOps',
#endif
],
$SOCKFS: {
#if expectToReceiveOnModule('websocket')
websocketArgs: {},
Expand Down Expand Up @@ -44,8 +48,12 @@ addToLibrary({
return FS.createNode(null, '/', {{{ cDefs.S_IFDIR | 0o777 }}}, 0);
},
createSocket(family, type, protocol) {
// Emscripten only supports AF_INET
if (family != {{{ cDefs.AF_INET }}}) {
if (family != {{{ cDefs.AF_INET }}}
#if NODERAWSOCKETS
// The node:net backend supports IPv6; other backends are IPv4 only.
&& family != {{{ cDefs.AF_INET6 }}}
#endif
) {
throw new FS.ErrnoError({{{ cDefs.EAFNOSUPPORT }}});
}
type &= ~{{{ cDefs.SOCK_CLOEXEC | cDefs.SOCK_NONBLOCK }}}; // Some applications may pass it; it makes no sense for a single process.
Expand All @@ -69,6 +77,8 @@ addToLibrary({
pending: [],
recv_queue: [],
#if SOCKET_WEBRTC
#elif NODERAWSOCKETS
sock_ops: nodeSockOps
#else
sock_ops: SOCKFS.websocket_sock_ops
#endif
Expand Down Expand Up @@ -726,7 +736,7 @@ addToLibrary({

return res;
}
}
},
},

/*
Expand Down
Loading
Loading