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

backport wasi-sockets changes to Wasmtime 14 #7216

Merged

Conversation

rvolosatovs
Copy link
Member

Backport #7120 (containing a WIT change)
Backport #7148 (containing UDP implementation and small fix to TCP polling)

badeend and others added 2 commits October 11, 2023 18:48
* Use Rustix::Errno to unify error code mapping.

* Clarify Connect failure state

* Allow accept() to return transient errors.

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

* Fold `ephemeral-ports-exhausted` into `address-in-use`

There is no cross-platform way to know the distinction between them

* Clarify `local-address` behavior on unbound socket

* Remove `concurrency-conflict` clutter,
and just document it to be always possible.

* Simplify state errors.

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.

* Document that connect may return ECONNABORTED

* Remove create-tcp/udp-socket not supported errors.

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.

* Simplify "not supported" and "invalid argument" error cases.

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.

* Move example_body out of lib.rs into its own test-case make room for other tests.

* Refactor TCP integration tests:
- Ad-hoc skeleton implementation of resources.
- Add blocking wrappers around async operations.

* Fix get/set_unicast_hop_limit on Linux

* Test TCP socket states

* Keep track of address family ourselves.

Because I need the family for input validation.
And the resulting code is more straightforward.

* Add more tests and make it work on Linux

* Fix Windows

* Simplify integration tests.

All platforms supported by wasmtime also support dualstack sockets.

* Test ipv6_only inheritence

* Test that socket options keep being respected, even if listen() has already been called

* cargo fmt

* Duplicate .wit changes to wasi-http

* prtest:full

* Fix BSD behavior of SO_SNDBUF/SO_RCVBUF

* fmt

* Fix type error

* Got lost during merge

* Implement listen backlog tests

* Manually inherit buffer size from listener on MacOS.

I suspect that these changes apply to any BSD platform, but I can't test that.

* Keep track of IPV6_V6ONLY ourselves.

- This provides cross-platform behaviour for `ipv6-only`
- This eliminates the syscall in `validate_address_family`

* Reject IPv4-compatible IPv6 addresses.

* Remove intermediate SystemError trait

* Fix ambiguous .into()'s

* Fix IPV6_UNICAST_HOPS inheritance on MacOS
* feat(wasi-sockets): implement UDP

This is based on TCP implementation

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

* refactor(wasi-sockets): simplify UDP implementation

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>

* feat(wasi-sockets): store UDP connect address in state

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

* fix(wasi-sockets): avoid `shutdown` on `drop`

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

* Remove explicit bind

* Simplify start_connect&finish_connect.
On UDP sockets, `connect` never blocks.

* Move UDP test to single file, similar to `tcp_sample_application.rs`

* Update UDP tests

---------

Signed-off-by: Roman Volosatovs <rvolosatovs@riseup.net>
Co-authored-by: Dave Bakker <github@davebakker.io>
@rvolosatovs rvolosatovs marked this pull request as ready for review October 11, 2023 17:44
@rvolosatovs rvolosatovs requested a review from a team as a code owner October 11, 2023 17:44
@rvolosatovs rvolosatovs requested review from alexcrichton and removed request for a team October 11, 2023 17:44
@rvolosatovs
Copy link
Member Author

@pchickey as discussed at the call earlier today

@pchickey pchickey merged commit 28dc805 into bytecodealliance:release-14.0.0 Oct 11, 2023
32 checks passed
@rvolosatovs rvolosatovs deleted the backport/wasi-sockets branch October 11, 2023 18:51
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.

3 participants