Skip to content

Conversation

@rvolosatovs
Copy link
Member

@rvolosatovs rvolosatovs commented Jul 21, 2025

Implement wasip3 wasi:sockets.

I've refactored FutureWriter::write a little bit to allow for non-blocking send

Refs bytecodealliance/wasip3-prototyping#228
Closes bytecodealliance/wasip3-prototyping#226 (note the addition of yield from the guest)
I was not able to reproduce bytecodealliance/wasip3-prototyping#44 with:

while cargo test --features p3 p3_sockets_udp_sample_application; do :; done

on MacOS

@rvolosatovs rvolosatovs force-pushed the feat/wasip3-sockets branch from 22c03af to cfeb70e Compare July 21, 2025 18:13
@rvolosatovs rvolosatovs marked this pull request as ready for review July 21, 2025 19:39
@rvolosatovs rvolosatovs requested review from a team as code owners July 21, 2025 19:39
@rvolosatovs rvolosatovs requested review from dicej and removed request for a team July 21, 2025 19:39
@github-actions github-actions bot added the wasi Issues pertaining to WASI label Jul 21, 2025
@rvolosatovs
Copy link
Member Author

FYI: I'm currently working on reusing most of the socket utilities across p2 and p3 to avoid duplication

@rvolosatovs rvolosatovs force-pushed the feat/wasip3-sockets branch from e81d4fa to d8c7a50 Compare July 22, 2025 20:58
Comment on lines +16 to +24
fn get_socket_addr_check<T>(store: &Accessor<T, WasiSockets>) -> SocketAddrCheck {
store.with(|mut view| view.get().ctx.socket_addr_check.clone())
}

async fn is_addr_allowed<T>(
store: &Accessor<T, WasiSockets>,
addr: SocketAddr,
reason: SocketAddrUse,
) -> bool {
get_socket_addr_check(store)(addr, reason).await
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing we may want to keep an eye out for in the future is some sort of fast path here to avoid the Arc::clone in the typical case.

pull in `wasi:sockets` from
WebAssembly/wasi-sockets#126

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
@rvolosatovs rvolosatovs force-pushed the feat/wasip3-sockets branch from 56be6a4 to ad674a2 Compare July 29, 2025 07:14
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
prtest:full

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
@rvolosatovs rvolosatovs force-pushed the feat/wasip3-sockets branch from ad674a2 to 2d23d4b Compare July 29, 2025 07:42
@rvolosatovs rvolosatovs marked this pull request as draft July 29, 2025 07:55
@rvolosatovs rvolosatovs force-pushed the feat/wasip3-sockets branch from 87cb14b to b69e53c Compare July 29, 2025 08:31
@rvolosatovs rvolosatovs force-pushed the feat/wasip3-sockets branch from b69e53c to 2d23d4b Compare July 29, 2025 09:13
@alexcrichton alexcrichton marked this pull request as ready for review July 29, 2025 21:58
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to update the REUSEADDR test a bit more and I'll file a follow-up issue for that (EDIT #11342), but otherwise this all looks good to me.

@alexcrichton alexcrichton added this pull request to the merge queue Jul 29, 2025
Merged via the queue into bytecodealliance:main with commit 7074afb Jul 30, 2025
167 checks passed
bongjunj pushed a commit to prosyslab/wasmtime that referenced this pull request Oct 20, 2025
* chore(wasip3): update `wasi:sockets` WIT

pull in `wasi:sockets` from
WebAssembly/wasi-sockets#126

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* refactor: rearrange Ctx/View

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* refactor: name modules after packages

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* refactor: move `Network` to `p2`

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* feat(wasip3): implement `wasi:sockets`

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* refactor: reuse socket utilities

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* test(wasip3): allow name resolution to fail

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* fix: expect macos-only var to be unused on other OSes

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* refactor: whole buffer is written for UDP

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* undo non-blocking write

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* extract buf capacity const, refactor tcp receive

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* introduce container struct for TCP non-inherited opts

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* handle `listen` receiver close

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* refactor: clean up

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* adapt to API changes

prtest:full

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* refactor: check for listen receiver close each iteration

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>

* Try to make test less flaky

* Cut down on `#[cfg]` required for wasi:sockets

* Fix test for real this time

---------

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Co-authored-by: Alex Crichton <alex@alexcrichton.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasi Issues pertaining to WASI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

REUSEADDR tests are broken

3 participants