Skip to content

Commit e5abf25

Browse files
committed
Update to the latest wasi-sockets.
Update to the latest wasi-sockets. This just contains documentation changes, and no interface changes.
1 parent 834a563 commit e5abf25

File tree

3 files changed

+89
-43
lines changed

3 files changed

+89
-43
lines changed

wit/deps.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ sha512 = "cc4fa3d178559a89d9d6a376e3359b892158d1e73317c5db1f797ebc6b0b57abf24227
2525

2626
[sockets]
2727
url = "https://github.com/WebAssembly/wasi-sockets/archive/main.tar.gz"
28-
sha256 = "40863017f355ac90c57630cc00b94518804e8e2c5694a7870b7a54dbdcda0e08"
29-
sha512 = "2d6a919247430e869bf85a06a6a1d198f04368951e76c1fec7961b2b07af381c58c8e8b9079c91925dfbf80976971213329be57d59a90bae6e4e6460b073dc88"
28+
sha256 = "9a3816bfa5a8b0673e5651024d8f9a1540f169f6d70f2bde6ee0e8240cd177ee"
29+
sha512 = "bfcce89127510e16e9e7d7ac058ba3108953067e2d53f05cb1020dadf552738753b7fc9d10797236f2ced089063de7ac853fd9526079758fab1419d9b58a5212"

wit/deps/sockets/tcp.wit

Lines changed: 80 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,45 @@ interface tcp {
1515
/// Similar to `SHUT_RDWR` in POSIX.
1616
both,
1717
}
18-
19-
20-
/// A TCP socket handle.
18+
19+
/// A TCP socket resource.
20+
///
21+
/// The socket can be in one of the following states:
22+
/// - `unbound`
23+
/// - `bind-in-progress`
24+
/// - `bound` (See note below)
25+
/// - `listen-in-progress`
26+
/// - `listening`
27+
/// - `connect-in-progress`
28+
/// - `connected`
29+
/// - `closed`
30+
/// See <https://github.com/WebAssembly/wasi-sockets/TcpSocketOperationalSemantics.md>
31+
/// for a more information.
32+
///
33+
/// Note: Except where explicitly mentioned, whenever this documentation uses
34+
/// the term "bound" without backticks it actually means: in the `bound` state *or higher*.
35+
/// (i.e. `bound`, `listen-in-progress`, `listening`, `connect-in-progress` or `connected`)
36+
///
37+
/// In addition to the general error codes documented on the
38+
/// `network::error-code` type, TCP socket methods may always return
39+
/// `error(invalid-state)` when in the `closed` state.
2140
resource tcp-socket {
2241
/// Bind the socket to a specific network on the provided IP address and port.
2342
///
2443
/// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which
2544
/// network interface(s) to bind to.
2645
/// If the TCP/UDP port is zero, the socket will be bound to a random free port.
2746
///
28-
/// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts.
47+
/// Bind can be attempted multiple times on the same socket, even with
48+
/// different arguments on each iteration. But never concurrently and
49+
/// only as long as the previous bind failed. Once a bind succeeds, the
50+
/// binding can't be changed anymore.
2951
///
30-
/// # Typical `start` errors
52+
/// # Typical errors
3153
/// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)
3254
/// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL)
3355
/// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. (EINVAL)
3456
/// - `invalid-state`: The socket is already bound. (EINVAL)
35-
///
36-
/// # Typical `finish` errors
3757
/// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)
3858
/// - `address-in-use`: Address is already in use. (EADDRINUSE)
3959
/// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL)
@@ -46,6 +66,11 @@ interface tcp {
4666
/// socket option should be set implicitly on all platforms, except on Windows where this is the default behavior
4767
/// and SO_REUSEADDR performs something different entirely.
4868
///
69+
/// Unlike in POSIX, in WASI the bind operation is async. This enables
70+
/// interactive WASI hosts to inject permission prompts. Runtimes that
71+
/// don't want to make use of this ability can simply call the native
72+
/// `bind` as part of either `start-bind` or `finish-bind`.
73+
///
4974
/// # References
5075
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html>
5176
/// - <https://man7.org/linux/man-pages/man2/bind.2.html>
@@ -57,32 +82,40 @@ interface tcp {
5782
/// Connect to a remote endpoint.
5883
///
5984
/// On success:
60-
/// - the socket is transitioned into the Connection state
85+
/// - the socket is transitioned into the `connection` state.
6186
/// - a pair of streams is returned that can be used to read & write to the connection
6287
///
63-
/// After a failed connection attempt, the only valid action left is to
64-
/// `drop` the socket. A single socket can not be used to connect more than once.
88+
/// After a failed connection attempt, the socket will be in the `closed`
89+
/// state and the only valid action left is to `drop` the socket. A single
90+
/// socket can not be used to connect more than once.
6591
///
66-
/// # Typical `start` errors
92+
/// # Typical errors
6793
/// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT)
6894
/// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS)
6995
/// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos)
7096
/// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows)
7197
/// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL on Windows)
7298
/// - `invalid-argument`: The socket is already attached to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`.
73-
/// - `invalid-state`: The socket is already in the Connection state. (EISCONN)
74-
/// - `invalid-state`: The socket is already in the Listener state. (EOPNOTSUPP, EINVAL on Windows)
75-
///
76-
/// # Typical `finish` errors
99+
/// - `invalid-state`: The socket is already in the `connected` state. (EISCONN)
100+
/// - `invalid-state`: The socket is already in the `listening` state. (EOPNOTSUPP, EINVAL on Windows)
77101
/// - `timeout`: Connection timed out. (ETIMEDOUT)
78102
/// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED)
79103
/// - `connection-reset`: The connection was reset. (ECONNRESET)
80104
/// - `connection-aborted`: The connection was aborted. (ECONNABORTED)
81105
/// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)
82106
/// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)
83-
/// - `not-in-progress`: A `connect` operation is not in progress.
107+
/// - `not-in-progress`: A connect operation is not in progress.
84108
/// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
85109
///
110+
/// # Implementors note
111+
/// The POSIX equivalent of `start-connect` is the regular `connect` syscall.
112+
/// Because all WASI sockets are non-blocking this is expected to return
113+
/// EINPROGRESS, which should be translated to `ok()` in WASI.
114+
///
115+
/// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT`
116+
/// with a timeout of 0 on the socket descriptor. Followed by a check for
117+
/// the `SO_ERROR` socket option, in case the poll signaled readiness.
118+
///
86119
/// # References
87120
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html>
88121
/// - <https://man7.org/linux/man-pages/man2/connect.2.html>
@@ -93,22 +126,24 @@ interface tcp {
93126

94127
/// Start listening for new connections.
95128
///
96-
/// Transitions the socket into the Listener state.
129+
/// Transitions the socket into the `listening` state.
97130
///
98-
/// Unlike POSIX:
99-
/// - this function is async. This enables interactive WASI hosts to inject permission prompts.
100-
/// - the socket must already be explicitly bound.
131+
/// Unlike POSIX, the socket must already be explicitly bound.
101132
///
102-
/// # Typical `start` errors
133+
/// # Typical errors
103134
/// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ)
104-
/// - `invalid-state`: The socket is already in the Connection state. (EISCONN, EINVAL on BSD)
105-
/// - `invalid-state`: The socket is already in the Listener state.
106-
///
107-
/// # Typical `finish` errors
135+
/// - `invalid-state`: The socket is already in the `connected` state. (EISCONN, EINVAL on BSD)
136+
/// - `invalid-state`: The socket is already in the `listening` state.
108137
/// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE)
109-
/// - `not-in-progress`: A `listen` operation is not in progress.
138+
/// - `not-in-progress`: A listen operation is not in progress.
110139
/// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
111140
///
141+
/// # Implementors note
142+
/// Unlike in POSIX, in WASI the listen operation is async. This enables
143+
/// interactive WASI hosts to inject permission prompts. Runtimes that
144+
/// don't want to make use of this ability can simply call the native
145+
/// `listen` as part of either `start-listen` or `finish-listen`.
146+
///
112147
/// # References
113148
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/listen.html>
114149
/// - <https://man7.org/linux/man-pages/man2/listen.2.html>
@@ -119,7 +154,7 @@ interface tcp {
119154

120155
/// Accept a new client socket.
121156
///
122-
/// The returned socket is bound and in the Connection state. The following properties are inherited from the listener socket:
157+
/// The returned socket is bound and in the `connected` state. The following properties are inherited from the listener socket:
123158
/// - `address-family`
124159
/// - `keep-alive-enabled`
125160
/// - `keep-alive-idle-time`
@@ -133,7 +168,7 @@ interface tcp {
133168
/// a pair of streams that can be used to read & write to the connection.
134169
///
135170
/// # Typical errors
136-
/// - `invalid-state`: Socket is not in the Listener state. (EINVAL)
171+
/// - `invalid-state`: Socket is not in the `listening` state. (EINVAL)
137172
/// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN)
138173
/// - `connection-aborted`: An incoming connection was pending, but was terminated by the client before this listener could accept it. (ECONNABORTED)
139174
/// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE)
@@ -175,7 +210,7 @@ interface tcp {
175210
/// - <https://man.freebsd.org/cgi/man.cgi?query=getpeername&sektion=2&n=1>
176211
remote-address: func() -> result<ip-socket-address, error-code>;
177212

178-
/// Whether the socket is listening for new connections.
213+
/// Whether the socket is in the `listening` state.
179214
///
180215
/// Equivalent to the SO_ACCEPTCONN socket option.
181216
is-listening: func() -> bool;
@@ -193,7 +228,7 @@ interface tcp {
193228
/// # Typical errors
194229
/// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen.
195230
/// - `invalid-argument`: (set) The provided value was 0.
196-
/// - `invalid-state`: (set) The socket is already in the Connection state.
231+
/// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` state.
197232
set-listen-backlog-size: func(value: u64) -> result<_, error-code>;
198233

199234
/// Enables or disables keepalive.
@@ -253,8 +288,6 @@ interface tcp {
253288
///
254289
/// # Typical errors
255290
/// - `invalid-argument`: (set) The TTL value must be 1 or higher.
256-
/// - `invalid-state`: (set) The socket is already in the Connection state.
257-
/// - `invalid-state`: (set) The socket is already in the Listener state.
258291
hop-limit: func() -> result<u8, error-code>;
259292
set-hop-limit: func(value: u8) -> result<_, error-code>;
260293

@@ -268,14 +301,25 @@ interface tcp {
268301
///
269302
/// # Typical errors
270303
/// - `invalid-argument`: (set) The provided value was 0.
271-
/// - `invalid-state`: (set) The socket is already in the Connection state.
272-
/// - `invalid-state`: (set) The socket is already in the Listener state.
273304
receive-buffer-size: func() -> result<u64, error-code>;
274305
set-receive-buffer-size: func(value: u64) -> result<_, error-code>;
275306
send-buffer-size: func() -> result<u64, error-code>;
276307
set-send-buffer-size: func(value: u64) -> result<_, error-code>;
277308

278-
/// Create a `pollable` which will resolve once the socket is ready for I/O.
309+
/// Create a `pollable` which can be used to poll for, or block on,
310+
/// completion of any of the asynchronous operations of this socket.
311+
///
312+
/// When `finish-bind`, `finish-listen`, `finish-connect` or `accept`
313+
/// return `error(would-block)`, this pollable can be used to wait for
314+
/// their success or failure, after which the method can be retried.
315+
///
316+
/// The pollable is not limited to the async operation that happens to be
317+
/// in progress at the time of calling `subscribe` (if any). Theoretically,
318+
/// `subscribe` only has to be called once per socket and can then be
319+
/// (re)used for the remainder of the socket's lifetime.
320+
///
321+
/// See <https://github.com/WebAssembly/wasi-sockets/TcpSocketOperationalSemantics.md#Pollable-readiness>
322+
/// for a more information.
279323
///
280324
/// Note: this function is here for WASI Preview2 only.
281325
/// It's planned to be removed when `future` is natively supported in Preview3.
@@ -297,7 +341,7 @@ interface tcp {
297341
/// The shutdown function does not close (drop) the socket.
298342
///
299343
/// # Typical errors
300-
/// - `invalid-state`: The socket is not in the Connection state. (ENOTCONN)
344+
/// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN)
301345
///
302346
/// # References
303347
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/shutdown.html>

wit/deps/sockets/udp.wit

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,21 @@ interface udp {
4343
/// network interface(s) to bind to.
4444
/// If the port is zero, the socket will be bound to a random free port.
4545
///
46-
/// Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts.
47-
///
48-
/// # Typical `start` errors
46+
/// # Typical errors
4947
/// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)
5048
/// - `invalid-state`: The socket is already bound. (EINVAL)
51-
///
52-
/// # Typical `finish` errors
5349
/// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)
5450
/// - `address-in-use`: Address is already in use. (EADDRINUSE)
5551
/// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL)
5652
/// - `not-in-progress`: A `bind` operation is not in progress.
5753
/// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)
5854
///
55+
/// # Implementors note
56+
/// Unlike in POSIX, in WASI the bind operation is async. This enables
57+
/// interactive WASI hosts to inject permission prompts. Runtimes that
58+
/// don't want to make use of this ability can simply call the native
59+
/// `bind` as part of either `start-bind` or `finish-bind`.
60+
///
5961
/// # References
6062
/// - <https://pubs.opengroup.org/onlinepubs/9699919799/functions/bind.html>
6163
/// - <https://man7.org/linux/man-pages/man2/bind.2.html>

0 commit comments

Comments
 (0)