diff --git a/command.md b/command.md index 263c2ac..3d92c20 100644 --- a/command.md +++ b/command.md @@ -1859,20 +1859,21 @@ supported size.
If the IP address is zero (0.0.0.0
in IPv4, ::
in IPv6), it is left to the implementation to decide which
network interface(s) to bind to.
If the port is zero, the socket will be bound to a random free port.
Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts.
-start
errorsinvalid-argument
: The local-address
has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)invalid-state
: The socket is already bound. (EINVAL)finish
errorsaddress-in-use
: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)address-in-use
: Address is already in use. (EADDRINUSE)address-not-bindable
: local-address
is not an address that the network
can bind to. (EADDRNOTAVAIL)not-in-progress
: A bind
operation is not in progress.would-block
: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)Unlike in POSIX, in WASI the bind operation is async. This enables
+interactive WASI hosts to inject permission prompts. Runtimes that
+don't want to make use of this ability can simply call the native
+bind
as part of either start-bind
or finish-bind
.
resource tcp-socket
A TCP socket resource.
+The socket can be in one of the following states:
+unbound
bind-in-progress
bound
(See note below)listen-in-progress
listening
connect-in-progress
connected
closed
+See https://github.com/WebAssembly/wasi-sockets/TcpSocketOperationalSemantics.md
+for a more information.Note: Except where explicitly mentioned, whenever this documentation uses
+the term "bound" without backticks it actually means: in the bound
state or higher.
+(i.e. bound
, listen-in-progress
, listening
, connect-in-progress
or connected
)
network::error-code
type, TCP socket methods may always return
+error(invalid-state)
when in the closed
state.[method]tcp-socket.start-bind: func
Bind the socket to a specific network on the provided IP address and port.
If the IP address is zero (0.0.0.0
in IPv4, ::
in IPv6), it is left to the implementation to decide which
network interface(s) to bind to.
If the TCP/UDP port is zero, the socket will be bound to a random free port.
Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts.
-start
errorsBind can be attempted multiple times on the same socket, even with +different arguments on each iteration. But never concurrently and +only as long as the previous bind failed. Once a bind succeeds, the +binding can't be changed anymore.
+invalid-argument
: The local-address
has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)invalid-argument
: local-address
is not a unicast address. (EINVAL)invalid-argument
: local-address
is an IPv4-mapped IPv6 address. (EINVAL)invalid-state
: The socket is already bound. (EINVAL)finish
errorsaddress-in-use
: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)address-in-use
: Address is already in use. (EADDRINUSE)address-not-bindable
: local-address
is not an address that the network
can bind to. (EADDRNOTAVAIL)Unlike in POSIX, in WASI the bind operation is async. This enables
+interactive WASI hosts to inject permission prompts. Runtimes that
+don't want to make use of this ability can simply call the native
+bind
as part of either start-bind
or finish-bind
.
Connect to a remote endpoint.
On success:
connection
state.After a failed connection attempt, the only valid action left is to
-drop
the socket. A single socket can not be used to connect more than once.
start
errorsAfter a failed connection attempt, the socket will be in the closed
+state and the only valid action left is to drop
the socket. A single
+socket can not be used to connect more than once.
invalid-argument
: The remote-address
has the wrong address family. (EAFNOSUPPORT)invalid-argument
: remote-address
is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS)invalid-argument
: The IP address in remote-address
is set to INADDR_ANY (0.0.0.0
/ ::
). (EADDRNOTAVAIL on Windows)invalid-argument
: The port in remote-address
is set to 0. (EADDRNOTAVAIL on Windows)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
.invalid-state
: The socket is already in the Connection state. (EISCONN)invalid-state
: The socket is already in the Listener state. (EOPNOTSUPP, EINVAL on Windows)finish
errorsinvalid-state
: The socket is already in the connected
state. (EISCONN)invalid-state
: The socket is already in the listening
state. (EOPNOTSUPP, EINVAL on Windows)timeout
: Connection timed out. (ETIMEDOUT)connection-refused
: The connection was forcefully rejected. (ECONNREFUSED)connection-reset
: The connection was reset. (ECONNRESET)connection-aborted
: The connection was aborted. (ECONNABORTED)remote-unreachable
: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)address-in-use
: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)not-in-progress
: A connect
operation is not in progress.not-in-progress
: A connect operation is not in progress.would-block
: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)The POSIX equivalent of start-connect
is the regular connect
syscall.
+Because all WASI sockets are non-blocking this is expected to return
+EINPROGRESS, which should be translated to ok()
in WASI.
The POSIX equivalent of finish-connect
is a poll
for event POLLOUT
+with a timeout of 0 on the socket descriptor. Followed by a check for
+the SO_ERROR
socket option, in case the poll signaled readiness.
[method]tcp-socket.start-listen: func
Start listening for new connections.
-Transitions the socket into the Listener state.
-Unlike POSIX:
-start
errorsTransitions the socket into the listening
state.
Unlike POSIX, the socket must already be explicitly bound.
+invalid-state
: The socket is not bound to any local address. (EDESTADDRREQ)invalid-state
: The socket is already in the Connection state. (EISCONN, EINVAL on BSD)invalid-state
: The socket is already in the Listener state.finish
errorsinvalid-state
: The socket is already in the connected
state. (EISCONN, EINVAL on BSD)invalid-state
: The socket is already in the listening
state.address-in-use
: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE)not-in-progress
: A listen
operation is not in progress.not-in-progress
: A listen operation is not in progress.would-block
: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)Unlike in POSIX, in WASI the listen operation is async. This enables
+interactive WASI hosts to inject permission prompts. Runtimes that
+don't want to make use of this ability can simply call the native
+listen
as part of either start-listen
or finish-listen
.
[method]tcp-socket.accept: func
Accept a new client socket.
-The returned socket is bound and in the Connection state. The following properties are inherited from the listener socket:
+The returned socket is bound and in the connected
state. The following properties are inherited from the listener socket:
address-family
keep-alive-enabled
invalid-state
: Socket is not in the Listener state. (EINVAL)invalid-state
: Socket is not in the listening
state. (EINVAL)would-block
: No pending connections at the moment. (EWOULDBLOCK, EAGAIN)connection-aborted
: An incoming connection was pending, but was terminated by the client before this listener could accept it. (ECONNABORTED)new-socket-limit
: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE)address
is unspecified.
ip-socket-address
, error-code
>[method]tcp-socket.is-listening: func
Whether the socket is listening for new connections.
+Whether the socket is in the listening
state.
Equivalent to the SO_ACCEPTCONN socket option.
not-supported
: (set) The platform does not support changing the backlog size after the initial listen.invalid-argument
: (set) The provided value was 0.invalid-state
: (set) The socket is already in the Connection state.invalid-state
: (set) The socket is in the connect-in-progress
or connected
state.invalid-argument
: (set) The TTL value must be 1 or higher.invalid-state
: (set) The socket is already in the Connection state.invalid-state
: (set) The socket is already in the Listener state.invalid-argument
: (set) The provided value was 0.invalid-state
: (set) The socket is already in the Connection state.invalid-state
: (set) The socket is already in the Listener state.error-code
>[method]tcp-socket.subscribe: func
Create a pollable
which will resolve once the socket is ready for I/O.
Create a pollable
which can be used to poll for, or block on,
+completion of any of the asynchronous operations of this socket.
When finish-bind
, finish-listen
, finish-connect
or accept
+return error(would-block)
, this pollable can be used to wait for
+their success or failure, after which the method can be retried.
The pollable is not limited to the async operation that happens to be
+in progress at the time of calling subscribe
(if any). Theoretically,
+subscribe
only has to be called once per socket and can then be
+(re)used for the remainder of the socket's lifetime.
See https://github.com/WebAssembly/wasi-sockets/TcpSocketOperationalSemantics.md#Pollable-readiness +for a more information.
Note: this function is here for WASI Preview2 only.
It's planned to be removed when future
is natively supported in Preview3.
ok
.
The shutdown function does not close (drop) the socket.
invalid-state
: The socket is not in the Connection state. (ENOTCONN)invalid-state
: The socket is not in the connected
state. (ENOTCONN)If the IP address is zero (0.0.0.0
in IPv4, ::
in IPv6), it is left to the implementation to decide which
network interface(s) to bind to.
If the port is zero, the socket will be bound to a random free port.
Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts.
-start
errorsinvalid-argument
: The local-address
has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)invalid-state
: The socket is already bound. (EINVAL)finish
errorsaddress-in-use
: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)address-in-use
: Address is already in use. (EADDRINUSE)address-not-bindable
: local-address
is not an address that the network
can bind to. (EADDRNOTAVAIL)not-in-progress
: A bind
operation is not in progress.would-block
: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)Unlike in POSIX, in WASI the bind operation is async. This enables
+interactive WASI hosts to inject permission prompts. Runtimes that
+don't want to make use of this ability can simply call the native
+bind
as part of either start-bind
or finish-bind
.
resource tcp-socket
A TCP socket resource.
+The socket can be in one of the following states:
+unbound
bind-in-progress
bound
(See note below)listen-in-progress
listening
connect-in-progress
connected
closed
+See https://github.com/WebAssembly/wasi-sockets/TcpSocketOperationalSemantics.md
+for a more information.Note: Except where explicitly mentioned, whenever this documentation uses
+the term "bound" without backticks it actually means: in the bound
state or higher.
+(i.e. bound
, listen-in-progress
, listening
, connect-in-progress
or connected
)
network::error-code
type, TCP socket methods may always return
+error(invalid-state)
when in the closed
state.[method]tcp-socket.start-bind: func
Bind the socket to a specific network on the provided IP address and port.
If the IP address is zero (0.0.0.0
in IPv4, ::
in IPv6), it is left to the implementation to decide which
network interface(s) to bind to.
If the TCP/UDP port is zero, the socket will be bound to a random free port.
Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts.
-start
errorsBind can be attempted multiple times on the same socket, even with +different arguments on each iteration. But never concurrently and +only as long as the previous bind failed. Once a bind succeeds, the +binding can't be changed anymore.
+invalid-argument
: The local-address
has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows)invalid-argument
: local-address
is not a unicast address. (EINVAL)invalid-argument
: local-address
is an IPv4-mapped IPv6 address. (EINVAL)invalid-state
: The socket is already bound. (EINVAL)finish
errorsaddress-in-use
: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows)address-in-use
: Address is already in use. (EADDRINUSE)address-not-bindable
: local-address
is not an address that the network
can bind to. (EADDRNOTAVAIL)Unlike in POSIX, in WASI the bind operation is async. This enables
+interactive WASI hosts to inject permission prompts. Runtimes that
+don't want to make use of this ability can simply call the native
+bind
as part of either start-bind
or finish-bind
.
Connect to a remote endpoint.
On success:
connection
state.After a failed connection attempt, the only valid action left is to
-drop
the socket. A single socket can not be used to connect more than once.
start
errorsAfter a failed connection attempt, the socket will be in the closed
+state and the only valid action left is to drop
the socket. A single
+socket can not be used to connect more than once.
invalid-argument
: The remote-address
has the wrong address family. (EAFNOSUPPORT)invalid-argument
: remote-address
is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS)invalid-argument
: The IP address in remote-address
is set to INADDR_ANY (0.0.0.0
/ ::
). (EADDRNOTAVAIL on Windows)invalid-argument
: The port in remote-address
is set to 0. (EADDRNOTAVAIL on Windows)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
.invalid-state
: The socket is already in the Connection state. (EISCONN)invalid-state
: The socket is already in the Listener state. (EOPNOTSUPP, EINVAL on Windows)finish
errorsinvalid-state
: The socket is already in the connected
state. (EISCONN)invalid-state
: The socket is already in the listening
state. (EOPNOTSUPP, EINVAL on Windows)timeout
: Connection timed out. (ETIMEDOUT)connection-refused
: The connection was forcefully rejected. (ECONNREFUSED)connection-reset
: The connection was reset. (ECONNRESET)connection-aborted
: The connection was aborted. (ECONNABORTED)remote-unreachable
: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET)address-in-use
: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD)not-in-progress
: A connect
operation is not in progress.not-in-progress
: A connect operation is not in progress.would-block
: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)The POSIX equivalent of start-connect
is the regular connect
syscall.
+Because all WASI sockets are non-blocking this is expected to return
+EINPROGRESS, which should be translated to ok()
in WASI.
The POSIX equivalent of finish-connect
is a poll
for event POLLOUT
+with a timeout of 0 on the socket descriptor. Followed by a check for
+the SO_ERROR
socket option, in case the poll signaled readiness.
[method]tcp-socket.start-listen: func
Start listening for new connections.
-Transitions the socket into the Listener state.
-Unlike POSIX:
-start
errorsTransitions the socket into the listening
state.
Unlike POSIX, the socket must already be explicitly bound.
+invalid-state
: The socket is not bound to any local address. (EDESTADDRREQ)invalid-state
: The socket is already in the Connection state. (EISCONN, EINVAL on BSD)invalid-state
: The socket is already in the Listener state.finish
errorsinvalid-state
: The socket is already in the connected
state. (EISCONN, EINVAL on BSD)invalid-state
: The socket is already in the listening
state.address-in-use
: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE)not-in-progress
: A listen
operation is not in progress.not-in-progress
: A listen operation is not in progress.would-block
: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN)Unlike in POSIX, in WASI the listen operation is async. This enables
+interactive WASI hosts to inject permission prompts. Runtimes that
+don't want to make use of this ability can simply call the native
+listen
as part of either start-listen
or finish-listen
.
[method]tcp-socket.accept: func
Accept a new client socket.
-The returned socket is bound and in the Connection state. The following properties are inherited from the listener socket:
+The returned socket is bound and in the connected
state. The following properties are inherited from the listener socket:
address-family
keep-alive-enabled
invalid-state
: Socket is not in the Listener state. (EINVAL)invalid-state
: Socket is not in the listening
state. (EINVAL)would-block
: No pending connections at the moment. (EWOULDBLOCK, EAGAIN)connection-aborted
: An incoming connection was pending, but was terminated by the client before this listener could accept it. (ECONNABORTED)new-socket-limit
: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE)address
is unspecified.
ip-socket-address
, error-code
>[method]tcp-socket.is-listening: func
Whether the socket is listening for new connections.
+Whether the socket is in the listening
state.
Equivalent to the SO_ACCEPTCONN socket option.
not-supported
: (set) The platform does not support changing the backlog size after the initial listen.invalid-argument
: (set) The provided value was 0.invalid-state
: (set) The socket is already in the Connection state.invalid-state
: (set) The socket is in the connect-in-progress
or connected
state.invalid-argument
: (set) The TTL value must be 1 or higher.invalid-state
: (set) The socket is already in the Connection state.invalid-state
: (set) The socket is already in the Listener state.invalid-argument
: (set) The provided value was 0.invalid-state
: (set) The socket is already in the Connection state.invalid-state
: (set) The socket is already in the Listener state.error-code
>[method]tcp-socket.subscribe: func
Create a pollable
which will resolve once the socket is ready for I/O.
Create a pollable
which can be used to poll for, or block on,
+completion of any of the asynchronous operations of this socket.
When finish-bind
, finish-listen
, finish-connect
or accept
+return error(would-block)
, this pollable can be used to wait for
+their success or failure, after which the method can be retried.
The pollable is not limited to the async operation that happens to be
+in progress at the time of calling subscribe
(if any). Theoretically,
+subscribe
only has to be called once per socket and can then be
+(re)used for the remainder of the socket's lifetime.
See https://github.com/WebAssembly/wasi-sockets/TcpSocketOperationalSemantics.md#Pollable-readiness +for a more information.
Note: this function is here for WASI Preview2 only.
It's planned to be removed when future
is natively supported in Preview3.
ok
.
The shutdown function does not close (drop) the socket.
invalid-state
: The socket is not in the Connection state. (ENOTCONN)invalid-state
: The socket is not in the connected
state. (ENOTCONN)