wasi_p2_sockets (wasm v0.16.0)

View Source

The wasi:sockets slice of the WASI 0.2 host: sockets/1 builds the network, name lookup, TCP and UDP imports over wasi_sock2, gated by a wasi_net grant.

Read it when you change a socket method, an option, or an address check. The streams a connection opens are the stream resources wasi_preview2 serves, and that module calls in here for the socket side of them: udp_pump/4 fills a datagram stream and sock2_errno/1 names a send failure. This module never calls back into wasi_preview2. datagram_allowed/3 and peer_matches/3 are the UDP grant and peer checks.

Summary

Functions

wasi:sockets: the network foundation, ip-name-lookup, TCP and UDP, the sockets themselves over wasi_sock2. instance-network mints a network resource carrying the grant; resolve-addresses resolves a name (gated by wasi_net:resolves/1, so a component with no grant resolves nothing) into a stream of addresses; resolve-next-address pops each as an ipv4/ipv6 value. The address decision is wasi_net, not a second copy of it, so a p2 guest reaches only what a p1 grant permits.

Functions

create_tcp_socket(Family, Grant)

create_udp_socket(Family, Grant)

datagram_allowed/3

endpoint_udp(Addr)

finish(Self, Tag, From, To)

inherit_sockopts(From, To)

ip_address/1

ip_sockaddr/2

opt_get(Self, Which)

opt_set(Self, Which, Value)

opt_set_nonzero(Self, Which, Value)

peer_matches/3

resolve_addresses(NetH, Name)

sock2_errno/1

socket_room(Grant)

sockets(Opts)

-spec sockets(#{grant => term()}) -> #{{binary(), binary()} => fun()}.

wasi:sockets: the network foundation, ip-name-lookup, TCP and UDP, the sockets themselves over wasi_sock2. instance-network mints a network resource carrying the grant; resolve-addresses resolves a name (gated by wasi_net:resolves/1, so a component with no grant resolves nothing) into a stream of addresses; resolve-next-address pops each as an ipv4/ipv6 value. The address decision is wasi_net, not a second copy of it, so a p2 guest reaches only what a p1 grant permits.

tcp_drop(H)

tcp_family(Self)

tcp_is_listening(Self)

tcp_local(Self)

tcp_remote(Self)

tcp_set_nonzero(Self, Value)

tcp_start_bind(Self, Net, Addr)

tcp_start_connect(Self, Net, Addr)

tcp_start_listen(Self)

udp_connect/3

udp_drop(H)

udp_family(Self)

udp_finish_bind(Self)

udp_local(Self)

udp_pump(Sock, Peer, Queue, Blocking)

udp_remote_addr(Self)

udp_start_bind(Self, Net, Addr)