* worker-build: update emscripten builds to Emscripten 7 and the Tokio tick event loop Tokio's hosted event loop (tokio-rs/tokio#8484) now waits on the epoll readiness listeners released in Emscripten 6.0.12, and wasm-bindgen drives it through LocalEventLoop::tick. The pin moves to 7.0.0, dropping the listener and source map backports it contains, and listener callbacks are delivered as a microtask of the notifying task so that concurrent inbound connections are each served in their own request. * examples: update the tokio patchset tag commit * Update wasm-bindgen to the EventLoop tokio API (wasm-bindgen#5467) |
History
|
|
|---|---|---|
| .. | ||
| src | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| README.md | ||
| rust-toolchain.toml | ||
| wrangler.toml | ||
Emscripten TCP example
Experimental Preview
git clone --recurse-submodules https://github.com/cloudflare/workers-rs
cd workers-rs/examples/emscripten-tcp
npx wrangler dev
Raw TCP from a Worker with tokio::net, using the Emscripten Tokio patchset
(the guybedford/tokio tag pinned in Cargo.toml, tokio-rs/tokio#8484).
Building on the emscripten-tokio example, the Worker
connects to port 80 of a host, sends an HTTP HEAD request and returns the
reply.
npx wrangler dev
curl 'http://localhost:8787/?host=example.com'
TcpStream::connect((host, 80)), write_all and read_to_string are the
ordinary Tokio API, under a tokio::time::timeout. The socket is backed by
the Workers connect() API through Emscripten's -sNODERAWSOCKETS, and
readiness flows through the same event loop that drives the handler. The
hostname resolves through Emscripten's asynchronous getaddrinfo
(emscripten#27742,
applied by worker-build), which Tokio's ToSocketAddrs uses on this target.
What's Next
See the emscripten-incoming-tcp example for using a native accept to receive a TCP connection.