Add Direct Sockets API support for Isolated Web Apps (-sDIRECT_SOCKETS)#26374
Open
maceip wants to merge 10 commits intoemscripten-core:mainfrom
Open
Add Direct Sockets API support for Isolated Web Apps (-sDIRECT_SOCKETS)#26374maceip wants to merge 10 commits intoemscripten-core:mainfrom
maceip wants to merge 10 commits intoemscripten-core:mainfrom
Conversation
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.
replaces the websocket-to-posix-socket proxy with chromes Direct Sockets API (TCPSocket TCPServerSocket UDPSocket) for real tcp/udp networking from wasm in isolated web apps
context on changes from #26344
rewrite that incorporates all review feedback from #26344 and expands scope to fully support the direct socket api - driven by A) young jedis annoying me about web transport and B) the archive org folks asking about tor-in-wasm this past weekend in berlin - with my janky syscall wiring plus this patch you get unbelievable perf across udp [incl session tickets] and tcp - shout outs to emscripten core devs and blink/v8 devs this shouldnt be possible
feedback addressed from #26344
key architectural change: SOCKFS pattern
the original pr used a private fd allocator (nextFd: 100) - this version registers socket fds in emscriptens FS using FS.createNode() + FS.createStream() with custom stream_ops the same pattern SOCKFS uses for websocket-backed sockets - this means write(fd) and read(fd) route through direct sockets which is reqd by openssl (its socket BIO uses write()/read() not send()/recv())
stream_ops must be synchronous bc theyre called from js to js (FS.write -> stream_ops.write) not wasm to js so JSPI cant suspend:
new syscalls (beyond #26344)
files changed
usage
emcc -sDIRECT_SOCKETS -sASYNCIFY -sPROXY_TO_PTHREAD -pthread app.c -o app.js
notes
testing
https://github.com/maceip/tor.iwa
https://github.com/maceip/socket.iwa
web demo
demo.mp4