emscripten-core / emscripten-core/emscripten
Getting networking asynchrony to work with Emscripten
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
In the company I work for, we're building an Emscripten binding over a custom, low-level, C networking library. Our JS/TS binding used to be done with Node-API; but that came with a clunky, hard to maintain, intermediary NodeJS server that was the most vulnerable layer in our stack. We're now close to having a working Emscripten binding (and getting rid of the NodeJS layer), but are having problems implementing asynchrony.
There are a bunch of important use cases where we want multiple *C-level* network calls to function concurrently (real-time notification subscribers; call batching for data retrieval...). Our previous/current NodeJS layer could leverage asynchrony via the built-in Node-API tools that rely (like Node) on libuv for asynchrony. We did try to build libuv with Emscripten, but are blocked because of the use of "poll" (or cross-platform equivalent) in the libuv source, and so instead have opted to go with Asyncify. However, the recent issue [here](https://github.com/emscripten-core/emscripten/issues/16066) leads me to believe that we're going to have trouble with this as well.
How would you recommend doing this ?
Is there any tutorial, or example file, for how to produce truly async C-level networking behavior with Emscripten ? ie, multiple concurrent call to `socket.h` `send()` and `recv()` (or equivalent `SSL_Write` or `SSL_Read` for the SSL lib of your choice), perhaps leveraging fibers, or some multithreaded mechanism ? Or are we doomed to having a single synchronous C stack with Emscripten at this point, and no workaround ?
Alternatively, if that's off the table, do you think getting libuv to work with Emscripten is possible ?
Contributor guide
Assessment
This issue has not been assessed yet.