When this flag is enabled, functions may return immediately with an
error-code::would-block error code in situations where they would
@@ -1048,7 +1055,7 @@ from fdstat_get in earlier versions of WASI.
An opaque resource that represents access to (a subset of) the network.
+This enables context-based security for networking.
+There is no need for this to map 1:1 to a physical network interface.
+
FYI, In the future this will be replaced by handle types.
Resolve an internet host name to a list of IP addresses.
+
See the wasi-socket proposal README.md for a comparison with getaddrinfo.
+
Parameters:
+
+
name: The name to look up. IP addresses are not allowed. Unicode domain names are automatically converted
+to ASCII using IDNA encoding.
+
address-family: If provided, limit the results to addresses of this specific address family.
+
include-unavailable: When set to true, this function will also return addresses of which the runtime
+thinks (or knows) can't be connected to at the moment. For example, this will return IPv6 addresses on
+systems without an active IPv6 interface. Notes:
+
Even when no public IPv6 interfaces are present or active, names like "localhost" can still resolve to an IPv6 address.
+
Whatever is "available" or "unavailable" is volatile and can change everytime a network cable is unplugged.
+
+
This function never blocks. It either immediately returns successfully with a resolve-address-stream
+that can be used to (asynchronously) fetch the results.
+Or it immediately fails whenever name is:
+
+
empty
+
an IP address
+
a syntactically invalid domain name in another way
This function should be called multiple times. On each call, it will
+return the next address in connection order preference. If all
+addresses have been exhausted, this function returns none.
+After which, you should release the stream with drop-resolve-address-stream.
+
This function never returns IPv4-mapped IPv6 addresses.
By default a stream is in "blocking" mode, meaning that any function blocks and waits for its completion.
+When switched to "non-blocking" mode, operations that would block return an again error. After which
+the API consumer is expected to call subscribe and wait for completion using the wasi-poll module.
+
Note: these functions are here for WASI Preview2 only.
+They're planned to be removed when future is natively supported in Preview3.
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.
+
When a socket is not explicitly bound, the first invocation to a listen or connect operation will
+implicitly bind the socket.
Whether IPv4 compatibility (dual-stack) mode is disabled or not.
+Implementations are not required to support dual-stack mode. Calling set-ipv6-only(false) might fail.
The kernel buffer space reserved for sends/receives on this socket.
+
Note #1: an implementation may choose to cap or round the buffer size when setting the value.
+In other words, after setting a value, reading the same setting back may return a different value.
+
Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of
+actual data to be sent/received by the application, because the kernel might also use the buffer space
+for internal metadata structures.
+
Fails when this socket is in the Listening state.
+
Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.
By default a socket is in "blocking" mode, meaning that any function blocks and waits for its completion.
+When switched to "non-blocking" mode, operations that would block return an again error. After which
+the API consumer is expected to call subscribe and wait for completion using the wasi-poll module.
+
Note: these functions are here for WASI Preview2 only.
+They're planned to be removed when future is natively supported in Preview3.
receive: the socket is not expecting to receive any more data from the peer. All subsequent read
+operations on the input-stream associated with this socket will return an End Of Stream indication.
+Any data still in the receive queue at time of calling shutdown will be discarded.
+
send: the socket is not expecting to send any more data to the peer. All subsequent write
+operations on the output-stream associated with this socket will return an error.
+
both: same effect as receive & send combined.
+
+
The shutdown function does not close the socket.
+
Fails when the socket is not in the Connection state.
Similar to socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP) in POSIX.
+
This function does not require a network capability handle. This is considered to be safe because
+at time of creation, the socket is not bound to any network yet. Up to the moment bind/listen/connect
+is called, the socket is effectively an in-memory configuration object, unable to communicate with the outside world.
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.
+
When a socket is not explicitly bound, the first invocation to a connect, send or receive operation will
+implicitly bind the socket.
Whether IPv4 compatibility (dual-stack) mode is disabled or not.
+Implementations are not required to support dual-stack mode, so calling set-ipv6-only(false) might fail.
The kernel buffer space reserved for sends/receives on this socket.
+
Note #1: an implementation may choose to cap or round the buffer size when setting the value.
+In other words, after setting a value, reading the same setting back may return a different value.
+
Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of
+actual data to be sent/received by the application, because the kernel might also use the buffer space
+for internal metadata structures.
+
Fails when this socket is in the Listening state.
+
Equivalent to the SO_RCVBUF and SO_SNDBUF socket options.
By default a socket is in "blocking" mode, meaning that any function blocks and waits for its completion.
+When switched to "non-blocking" mode, operations that would block return an again error. After which
+the API consumer is expected to call subscribe and wait for completion using the wasi-poll module.
+
Note: these functions are here for WASI Preview2 only.
+They're planned to be removed when future is natively supported in Preview3.
Similar to socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP) in POSIX.
+
This function does not require a network capability handle. This is considered to be safe because
+at time of creation, the socket is not bound to any network yet. Up to the moment bind/connect is called,
+the socket is effectively an in-memory configuration object, unable to communicate with the outside world.
It is intended to be portable at least between Unix-family platforms and
diff --git a/wit/cli.wit b/wit/cli.wit
index 3946023..9eccbb7 100644
--- a/wit/cli.wit
+++ b/wit/cli.wit
@@ -5,6 +5,13 @@ default world cli {
import instance-monotonic-clock: clocks.instance-monotonic-clock
import timezone: clocks.timezone
import filesystem: filesystem.filesystem
+ import instance-network: sockets.instance-network
+ import ip-name-lookup: sockets.ip-name-lookup
+ import network: sockets.network
+ import tcp-create-socket: sockets.tcp-create-socket
+ import tcp: sockets.tcp
+ import udp-create-socket: sockets.udp-create-socket
+ import udp: sockets.udp
import random: random.random
import poll: poll.poll
import io: io.streams
diff --git a/wit/deps/sockets/instance-network.wit b/wit/deps/sockets/instance-network.wit
new file mode 100644
index 0000000..b1f5c98
--- /dev/null
+++ b/wit/deps/sockets/instance-network.wit
@@ -0,0 +1,9 @@
+
+/// This interface provides a value-export of the default network handle..
+default interface instance-network {
+ use pkg.network.{network}
+
+ /// Get a handle to the default network.
+ instance-network: func() -> network
+
+}
diff --git a/wit/deps/sockets/ip-name-lookup.wit b/wit/deps/sockets/ip-name-lookup.wit
new file mode 100644
index 0000000..dd85d58
--- /dev/null
+++ b/wit/deps/sockets/ip-name-lookup.wit
@@ -0,0 +1,71 @@
+
+default interface ip-name-lookup {
+ use poll.poll.{pollable}
+ use pkg.network.{network, error, ip-address, ip-address-family}
+
+
+ /// Resolve an internet host name to a list of IP addresses.
+ ///
+ /// See the wasi-socket proposal README.md for a comparison with getaddrinfo.
+ ///
+ /// Parameters:
+ /// - `name`: The name to look up. IP addresses are not allowed. Unicode domain names are automatically converted
+ /// to ASCII using IDNA encoding.
+ /// - `address-family`: If provided, limit the results to addresses of this specific address family.
+ /// - `include-unavailable`: When set to true, this function will also return addresses of which the runtime
+ /// thinks (or knows) can't be connected to at the moment. For example, this will return IPv6 addresses on
+ /// systems without an active IPv6 interface. Notes:
+ /// - Even when no public IPv6 interfaces are present or active, names like "localhost" can still resolve to an IPv6 address.
+ /// - Whatever is "available" or "unavailable" is volatile and can change everytime a network cable is unplugged.
+ ///
+ /// This function never blocks. It either immediately returns successfully with a `resolve-address-stream`
+ /// that can be used to (asynchronously) fetch the results.
+ /// Or it immediately fails whenever `name` is:
+ /// - empty
+ /// - an IP address
+ /// - a syntactically invalid domain name in another way
+ ///
+ /// References:
+ /// - https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html
+ /// - https://man7.org/linux/man-pages/man3/getaddrinfo.3.html
+ ///
+ resolve-addresses: func(network: network, name: string, address-family: option, include-unavailable: bool) -> result
+
+
+
+ type resolve-address-stream = u32
+
+ /// Returns the next address from the resolver.
+ ///
+ /// This function should be called multiple times. On each call, it will
+ /// return the next address in connection order preference. If all
+ /// addresses have been exhausted, this function returns `none`.
+ /// After which, you should release the stream with `drop-resolve-address-stream`.
+ ///
+ /// This function never returns IPv4-mapped IPv6 addresses.
+ resolve-next-address: func(this: resolve-address-stream) -> result