Skip to content

Conversation

@haraldh
Copy link
Contributor

@haraldh haraldh commented Jan 21, 2022

With the addition of sock_accept() to snapshot1, simple networking via a passed TcpListener is possible. This PR implements the basics to make a simple server work.

See also:

TODO:

  • Discussion of SocketAddr return value for ::accept()
        Ok((
            TcpStream::from_inner(unsafe { Socket::from_raw_fd(fd as _) }),
            // WASI has no concept of SocketAddr yet
            // return an unspecified IPv4Addr
            SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), 0),
        ))

@rust-highfive
Copy link
Contributor

r? @dtolnay

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 21, 2022
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@haraldh haraldh changed the title DRAFT: wasi: implement sock_accept and enable networking wasi: implement sock_accept and enable networking Jan 21, 2022
@haraldh haraldh marked this pull request as ready for review January 21, 2022 18:56
Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good to me after the fix in decode_error_kind.

Feel free to ping anyone who would have a useful opinion about the TcpListener::accept return value. Probably any value is better than unsupported() though.

Copy link
Member

Choose a reason for hiding this comment

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

.as_inner().as_inner().as_inner()

😱

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hehe

Copy link
Member

Choose a reason for hiding this comment

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

Line 66 has this already.

Suggested change
e if e == wasi::ERRNO_AGAIN.raw().into() => WouldBlock,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

@dtolnay dtolnay added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 28, 2022
To make use of `sock_accept()`, update the wasi crate to `0.11.0`.

Signed-off-by: Harald Hoyer <[email protected]>
With the addition of `sock_accept()` to snapshot1, simple networking via
a passed `TcpListener` is possible. This patch implements the basics to
make a simple server work.

Signed-off-by: Harald Hoyer <[email protected]>
@haraldh
Copy link
Contributor Author

haraldh commented Jan 28, 2022

Thanks, this looks good to me after the fix in decode_error_kind.

@dtolnay fixed and rebased

@haraldh haraldh requested a review from dtolnay January 28, 2022 12:29
@bjorn3 bjorn3 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 28, 2022
@dtolnay
Copy link
Member

dtolnay commented Jan 28, 2022

@bors r+

@bors
Copy link
Collaborator

bors commented Jan 28, 2022

📌 Commit d2a1369 has been approved by dtolnay

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 28, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 28, 2022
wasi: implement `sock_accept` and enable networking

With the addition of `sock_accept()` to snapshot1, simple networking via a passed `TcpListener` is possible. This PR implements the basics to make a simple server work.

See also:
* [wasmtime tracking issue](bytecodealliance/wasmtime#3730)
* [wasmtime PR](bytecodealliance/wasmtime#3711)

TODO:
* [ ] Discussion of `SocketAddr` return value for `::accept()`

```rust
        Ok((
            TcpStream::from_inner(unsafe { Socket::from_raw_fd(fd as _) }),
            // WASI has no concept of SocketAddr yet
            // return an unspecified IPv4Addr
            SocketAddr::new(Ipv4Addr::UNSPECIFIED.into(), 0),
        ))
```
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 28, 2022
…askrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#92611 (Add links to the reference and rust by example for asm! docs and lints)
 - rust-lang#93158 (wasi: implement `sock_accept` and enable networking)
 - rust-lang#93239 (Add os::unix::net::SocketAddr::from_path)
 - rust-lang#93261 (Some unwinding related cg_ssa cleanups)
 - rust-lang#93295 (Avoid double panics when using `TempDir` in tests)
 - rust-lang#93353 (Unimpl {Add,Sub,Mul,Div,Rem,BitXor,BitOr,BitAnd}<$t> for Saturating<$t>)
 - rust-lang#93356 (Edit docs introduction for `std::cmp::PartialOrd`)
 - rust-lang#93375 (fix typo `documenation`)
 - rust-lang#93399 (rustbuild: Fix compiletest warning when building outside of root.)
 - rust-lang#93404 (Fix a typo from rust-lang#92899)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9f15c4d into rust-lang:master Jan 29, 2022
@rustbot rustbot added this to the 1.60.0 milestone Jan 29, 2022
haraldh added a commit to haraldh/mio that referenced this pull request Feb 4, 2022
With
* bytecodealliance/wasmtime#3711
* rust-lang/rust#93158
merged, mio can have limited support for networking for the
`wasm32-wasi` target.

Signed-off-by: Harald Hoyer <[email protected]>
haraldh added a commit to haraldh/mio that referenced this pull request Feb 15, 2022
With
* bytecodealliance/wasmtime#3711
* rust-lang/rust#93158
merged, mio can have limited support for networking for the
`wasm32-wasi` target.

Signed-off-by: Harald Hoyer <[email protected]>
haraldh added a commit to haraldh/mio that referenced this pull request Feb 15, 2022
With
* bytecodealliance/wasmtime#3711
* rust-lang/rust#93158
merged, mio can have limited support for networking for the
`wasm32-wasi` target.

Signed-off-by: Harald Hoyer <[email protected]>
haraldh added a commit to haraldh/mio that referenced this pull request Feb 15, 2022
With
* bytecodealliance/wasmtime#3711
* rust-lang/rust#93158
merged, mio can have limited support for networking for the
`wasm32-wasi` target.

Signed-off-by: Harald Hoyer <[email protected]>
haraldh added a commit to haraldh/mio that referenced this pull request Feb 18, 2022
With
* bytecodealliance/wasmtime#3711
* rust-lang/rust#93158
merged, mio can have limited support for networking for the
`wasm32-wasi` target.

Signed-off-by: Harald Hoyer <[email protected]>
haraldh added a commit to haraldh/mio that referenced this pull request Feb 21, 2022
Based on tokio-rs#1395

And with
* bytecodealliance/wasmtime#3711
* rust-lang/rust#93158
merged, mio can have limited support for networking for the
`wasm32-wasi` target.

Co-authored-by: Thomas de Zeeuw <[email protected]>
Signed-off-by: Harald Hoyer <[email protected]>
haraldh added a commit to haraldh/mio that referenced this pull request Mar 8, 2022
Based on tokio-rs#1395

And with
* bytecodealliance/wasmtime#3711
* rust-lang/rust#93158
merged, mio can have limited support for networking for the
`wasm32-wasi` target.

Co-authored-by: Thomas de Zeeuw <[email protected]>
Signed-off-by: Harald Hoyer <[email protected]>
Thomasdezeeuw added a commit to tokio-rs/mio that referenced this pull request Mar 8, 2022
Based on #1395

And with
* bytecodealliance/wasmtime#3711
* rust-lang/rust#93158
merged, mio can have limited support for networking for the
`wasm32-wasi` target.

Co-authored-by: Thomas de Zeeuw <[email protected]>
Signed-off-by: Harald Hoyer <[email protected]>
bdbai pushed a commit to YtFlow/mio-noafd that referenced this pull request May 15, 2022
Based on tokio-rs#1395

And with
* bytecodealliance/wasmtime#3711
* rust-lang/rust#93158
merged, mio can have limited support for networking for the
`wasm32-wasi` target.

Co-authored-by: Thomas de Zeeuw <[email protected]>
Signed-off-by: Harald Hoyer <[email protected]>
stlankes added a commit to hermit-os/mio that referenced this pull request Jun 30, 2022
Based on tokio-rs#1395

And with
* bytecodealliance/wasmtime#3711
* rust-lang/rust#93158
merged, mio can have limited support for networking for the
`wasm32-wasi` target.

Co-authored-by: Thomas de Zeeuw <[email protected]>
Signed-off-by: Harald Hoyer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants