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; TCP servers use a
low-level tcp_wrap handle for a synchronous bind, and UDP uses a udp_wrap
handle for the same reason.

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 (including PROXY_TO_PTHREAD): like the rest of the
JS filesystem, socket syscalls are proxied to the main thread, where the
node handles and their event loop live.

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 @@ -270,6 +270,7 @@ sigs = {
__syscall_rmdir__sig: 'ip',
__syscall_sendmsg__sig: 'iipippi',
__syscall_sendto__sig: 'iippipp',
__syscall_setsockopt__sig: 'iiiippi',
__syscall_shutdown__sig: 'iiiiiii',
__syscall_socket__sig: 'iiiiiii',
__syscall_stat64__sig: 'ipp',
Expand Down
10 changes: 8 additions & 2 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 @@ -69,6 +73,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 +732,7 @@ addToLibrary({

return res;
}
}
},
},

/*
Expand Down
Loading
Loading