Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Udp #2

Closed
wants to merge 46 commits into from
Closed

Udp #2

wants to merge 46 commits into from

Conversation

badeend
Copy link

@badeend badeend commented Oct 9, 2023

The original provision was added to align with preview3 streams that may only fail once. However, after discussing with Dan Gohman, we came to the conclusion that a stream of result<> could do the trick fine too.

Fixes: WebAssembly/wasi-sockets#22
There is no cross-platform way to know the distinction between them
and just document it to be always possible.
They were unnecessarily detailed and mostly have no standardized equivalent in POSIX, so wasi-libc will probably just map them all back into a single EOPNOTSUPP or EINVAL or ...

EISCONN/ENOTCONN can be derived in wasi-libc based on context and/or by checking `remote-address`. For example, `shutdown` can only be called on connected sockets, so if it returns `invalid-state` it can be unambiguously mapped to ENOTCONN.
These stem from back when the entire wasi-sockets proposal was one big single thing. In this day and age, when an implementation doesn't want to support TCP and/or UDP, it can simply _not_ implement that interface, rather than returning an error at runtime.
There is a myriad of reasons why an argument might be invalid or an operation might be not supported. But there is few cross platform consistency in which of those error cases result in which error codes.

The error codes that have been removed were fairly specific, but:
- Were still missing error cases. So additional error codes would have needed to be created.
- Implementations would have to bend over backwards to make it work cross platform, especially beyond just Win/Mac/Linux.
- Didn't all have an equivalent in POSIX, so they would map back into a generic EINVAL anyways.
- Ad-hoc skeleton implementation of resources.
- Add blocking wrappers around async operations.
Because I need the family for input validation.
And the resulting code is more straightforward.
All platforms supported by wasmtime also support dualstack sockets.
…nto tcp-error-checking

# Conflicts:
#	crates/test-programs/wasi-sockets-tests/src/bin/tcp_v4.rs
#	crates/test-programs/wasi-sockets-tests/src/bin/tcp_v6.rs
#	crates/test-programs/wasi-sockets-tests/src/lib.rs
#	crates/wasi/src/preview2/host/tcp.rs
#	crates/wasi/src/preview2/tcp.rs
#	crates/wasi/wit/deps/sockets/tcp.wit
#	crates/wasi/wit/deps/sockets/udp.wit
…nto tcp-error-checking

# Conflicts:
#	crates/test-programs/wasi-sockets-tests/src/lib.rs
#	crates/wasi/src/preview2/host/network.rs
#	crates/wasi/src/preview2/host/tcp.rs
#	crates/wasi/src/preview2/tcp.rs
badeend and others added 16 commits October 5, 2023 21:20
I suspect that these changes apply to any BSD platform, but I can't test that.
- This provides cross-platform behaviour for `ipv6-only`
- This eliminates the syscall in `validate_address_family`
This is based on TCP implementation

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
This introduces quite a few changes compared to TCP, which should most probably be integrated there as well

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
…nto tcp-error-checking

# Conflicts:
#	crates/wasi-http/wit/deps/sockets/ip-name-lookup.wit
#	crates/wasi-http/wit/deps/sockets/network.wit
#	crates/wasi-http/wit/deps/sockets/tcp-create-socket.wit
#	crates/wasi-http/wit/deps/sockets/tcp.wit
#	crates/wasi-http/wit/deps/sockets/udp-create-socket.wit
#	crates/wasi-http/wit/deps/sockets/udp.wit
#	crates/wasi/src/preview2/host/network.rs
#	crates/wasi/src/preview2/host/tcp.rs
#	crates/wasi/wit/deps/sockets/ip-name-lookup.wit
#	crates/wasi/wit/deps/sockets/network.wit
#	crates/wasi/wit/deps/sockets/tcp-create-socket.wit
#	crates/wasi/wit/deps/sockets/tcp.wit
#	crates/wasi/wit/deps/sockets/udp-create-socket.wit
#	crates/wasi/wit/deps/sockets/udp.wit
On UDP sockets, `connect` never blocks.
…smtime into udp

# Conflicts:
#	crates/test-programs/wasi-sockets-tests/src/bin/tcp_v4.rs
#	crates/test-programs/wasi-sockets-tests/src/bin/tcp_v6.rs
#	crates/test-programs/wasi-sockets-tests/src/lib.rs
#	crates/wasi/src/preview2/host/tcp.rs
@rvolosatovs
Copy link
Owner

Thank you, merged locally!

@rvolosatovs rvolosatovs closed this Oct 9, 2023
rvolosatovs pushed a commit that referenced this pull request Oct 11, 2023
…dealliance#7029)

* Rename `Host*` things to avoid name conflicts with bindings.

* Update to the latest resource-enabled wit files.

* Adapting the code to the new bindings.

* Update wasi-http to the resource-enabled wit deps.

* Start adapting the wasi-http code to the new bindings.

* Make `get_directories` always return new owned handles.

* Simplify the `poll_one` implementation.

* Update the wasi-preview1-component-adapter.

FIXME: temporarily disable wasi-http tests.

Add logging to the cli world, since stderr is now a reseource that
can only be claimed once.

* Work around a bug hit by poll-list, fix a bug in poll-one.

* Comment out `test_fd_readwrite_invalid_fd`, which panics now.

* Fix a few FIXMEs.

* Use `.as_ref().trapping_unwrap()` instead of `TrappingUnwrapRef`.

* Use `drop_in_place`.

* Remove `State::with_mut`.

* Remove the `RefCell` around the `State`.

* Update to wit-bindgen 0.12.

* Update wasi-http to use resources for poll and I/O.

This required making incoming-body and outgoing-body resourrces too, to
work with `push_input_stream_child` and `push_output_stream_child`.

* Re-enable disabled tests, remove logging from the worlds.

* Remove the `poll_list` workarounds that are no longer needed.

* Remove logging from the adapter.

That said, there is no replacement yet, so add a FIXME comment.

* Reenable a test that now passes.

* Remove `.descriptors_mut` and use `with_descriptors_mut` instead.

Replace `.descriptors()` and `.descriptors_mut()` with functions
that take closures, which limits their scope, to prevent them from
invalid aliasing.

* Implement dynamic borrow checking for descriptors.

* Add a cargo-vet audit for wasmtime-wmemcheck.

* Update cargo vet for wit-bindgen 0.12.

* Cut down on duplicate sync/async resource types (#1)

* Allow calling `get-directories` more than once (#2)

For now `Clone` the directories into new descriptor slots as needed.

* Start to lift restriction of stdio only once  (bytecodealliance#3)

* Start to lift restriction of stdio only once

This commit adds new `{Stdin,Stdout}Stream` traits which take over the
job of the stdio streams in `WasiCtxBuilder` and `WasiCtx`. These traits
bake in the ability to create a stream at any time to satisfy the API
of `wasi:cli`. The TTY functionality is folded into them as while I was
at it.

The implementation for stdin is relatively trivial since the stdin
implementation already handles multiple streams reading it. Built-in
impls of the `StdinStream` trait are also provided for helper types in
`preview2::pipe` which resulted in the implementation of
`MemoryInputPipe` being updated to support `Clone` where all clones read
the same original data.

* Get tests building

* Un-ignore now-passing test

* Remove unneeded argument from `WasiCtxBuilder::build`

* Fix tests

* Remove some workarounds

Stdio functions can now be called multiple times.

* If `poll_oneoff` fails part-way through, clean up properly.

Fix the `Drop` implementation for pollables to only drop the pollables
that have been successfully added to the list.

This fixes the poll_oneoff_files failure and removes a FIXME.

---------

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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants