Commit 388f6af
committed
add
This implementation currently uses a mix of POSIX-style APIs (provided by
`wasi-libc` via the `libc` crate) and WASIp2-native APIs (provided by the `wasi`
crate).
Alternatively, we could implement `Selector` using only POSIX APIs,
e.g. `poll(2)`. However, that would add an extra layer of abstraction to
support and debug, as well as make it impossible to support polling
`wasi:io/poll/pollable` objects which cannot be represented as POSIX file
descriptors (e.g. timer events, DNS queries, HTTP requests, etc.).
Another approach would be to use _only_ the WASIp2 APIs and bypass `wasi-libc`
entirely. However, that would break interoperability with both Rust `std` and
e.g. C libraries which expect to work with file descriptors.
Since `wasi-libc` does not yet provide a public API for converting between file
descriptors and WASIp2 resource handles, we currently use a non-public API (see
the `netc` module below) to do so. Once
WebAssembly/wasi-libc#542 is addressed, we'll be able
to switch to a public API.
I've tested this end-to-end using https://github.com/dicej/wasi-sockets-tests,
which includes smoke tests for `mio`, `tokio`, `tokio-postgres`, etc.
add WASIp2 TODO comments
// TODO #1: Add a public, WASIp2-only API for registering
// `wasi::io::poll::Pollable`s directly (i.e. those which do not correspond to
// any `wasi-libc` file descriptor, such as `wasi:http` requests).
//
// TODO #2: Add support for binding, listening, and accepting. This would
// involve adding cases for `TCP_SOCKET_STATE_UNBOUND`,
// `TCP_SOCKET_STATE_BOUND`, and `TCP_SOCKET_STATE_LISTENING` to the `match`
// statements in `Selector::select`.
//
// TODO #3: Add support for UDP sockets. This would involve adding cases for
// the `UDP_SOCKET_STATE_*` tags to the `match` statements in
// `Selector::select`.
Signed-off-by: Joel Dice <[email protected]>wasm32-wasip2 support1 parent f352b81 commit 388f6af
File tree
7 files changed
+1066
-373
lines changed- src
- net/tcp
- sys
- wasi
7 files changed
+1066
-373
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
70 | 75 | | |
71 | 76 | | |
72 | 77 | | |
| |||
80 | 85 | | |
81 | 86 | | |
82 | 87 | | |
| 88 | + | |
83 | 89 | | |
84 | 90 | | |
85 | 91 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
| 107 | + | |
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
| 178 | + | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | | - | |
| 90 | + | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
| 93 | + | |
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
0 commit comments