emscripten-core / emscripten-core/emscripten

Alternative SOCKFS in Node.js environment + synchronous socket calls using JSPI

Đang mở
#26,041 18 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
C++
Star
27.6k
Fork
3.6k
Merge trung bình
1 ngày 16 giờ
Pull request đã merge (30 ngày)
117

Mô tả

## Proposal

We (Pyodide and Cloudflare workers) would like to enable socket support without relying on the websocket proxy.
This would allow us to run existing Python code that relies on sockets (e.g., HTTP clients, database clients, etc) without any modification both in client and server.

This is impossible in a Web environment (unless Direct Socket proposal is accepted https://github.com/emscripten-core/emscripten/issues/16737) as sockets are not supported.
However, in Node.js (or other JS runtimes such as Deno, Bun, or Cloudflare Workers), we can take advantage of it's [native socket APIs](https://nodejs.org/api/net.html).

Also, while the Node.js socket APIs are asynchronous, Asyncify (JSPI), can be used to pause the JS function calls to make it compatible to existing socket APIs that expects blocking on select, poll, or recv.

## How is would look like

1. Add a flag such as `-sUSE_NODESOCKET` that replaces the current [SOCKFS implementation](https://github.com/emscripten-core/emscripten/blob/main/src/lib/libsockfs.js)
with a new implementation when the runtime environment is detected as Node.js.

2. Update the socket syscalls (e.g., listen, recv, send, etc) to use JSPI or Asyncify (when available)
to block the calls until the underlying Node.js socket APIs complete.

## Discussion Topics & Concerns

1. Ideally, it would be great to detect the JSPI availability at runtime, so that either the synchronous version or the asynchronous version is selected at runtime. But I guess currently Asyncify does not support that.

---

I would be happy to implement and contribute this feature is it makes sense.
Pyodide can patch Emscripten locally for our use case, but it would be great to have this feature available upstream so that other projects can benefit from it as well.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Start with src/lib/libsockfs.js and the socket syscalls named in the proposal, including listen, recv, and send. Review how JSPI or Asyncify could pause these calls for Node.js socket APIs; done means a Node.js SOCKFS path and synchronous-compatible socket operations are available without the websocket proxy.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
node.js, wasm
Lĩnh vực
compilers, networking
Loại issue
Tính năng
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.