package wasi:sockets@0.2.0; interface network { resource network; enum error-code { unknown, access-denied, not-supported, invalid-argument, out-of-memory, timeout, concurrency-conflict, not-in-progress, would-block, invalid-state, new-socket-limit, address-not-bindable, address-in-use, remote-unreachable, connection-refused, connection-reset, connection-aborted, datagram-too-large, name-unresolvable, temporary-resolver-failure, permanent-resolver-failure, } enum ip-address-family { ipv4, ipv6, } type ipv4-address = tuple; type ipv6-address = tuple; variant ip-address { ipv4(ipv4-address), ipv6(ipv6-address), } record ipv4-socket-address { port: u16, address: ipv4-address, } record ipv6-socket-address { port: u16, flow-info: u32, address: ipv6-address, scope-id: u32, } variant ip-socket-address { ipv4(ipv4-socket-address), ipv6(ipv6-socket-address), } } interface instance-network { use network.{network}; instance-network: func() -> network; } interface udp { use wasi:io/poll@0.2.0.{pollable}; use network.{network, error-code, ip-socket-address, ip-address-family}; record incoming-datagram { data: list, remote-address: ip-socket-address, } record outgoing-datagram { data: list, remote-address: option, } resource udp-socket { start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; finish-bind: func() -> result<_, error-code>; %stream: func(remote-address: option) -> result, error-code>; local-address: func() -> result; remote-address: func() -> result; address-family: func() -> ip-address-family; unicast-hop-limit: func() -> result; set-unicast-hop-limit: func(value: u8) -> result<_, error-code>; receive-buffer-size: func() -> result; set-receive-buffer-size: func(value: u64) -> result<_, error-code>; send-buffer-size: func() -> result; set-send-buffer-size: func(value: u64) -> result<_, error-code>; subscribe: func() -> pollable; } resource incoming-datagram-stream { receive: func(max-results: u64) -> result, error-code>; subscribe: func() -> pollable; } resource outgoing-datagram-stream { check-send: func() -> result; send: func(datagrams: list) -> result; subscribe: func() -> pollable; } } interface udp-create-socket { use network.{network, error-code, ip-address-family}; use udp.{udp-socket}; create-udp-socket: func(address-family: ip-address-family) -> result; } interface tcp { use wasi:io/streams@0.2.0.{input-stream, output-stream}; use wasi:io/poll@0.2.0.{pollable}; use wasi:clocks/monotonic-clock@0.2.0.{duration}; use network.{network, error-code, ip-socket-address, ip-address-family}; enum shutdown-type { receive, send, both, } resource tcp-socket { start-bind: func(network: borrow, local-address: ip-socket-address) -> result<_, error-code>; finish-bind: func() -> result<_, error-code>; start-connect: func(network: borrow, remote-address: ip-socket-address) -> result<_, error-code>; finish-connect: func() -> result, error-code>; start-listen: func() -> result<_, error-code>; finish-listen: func() -> result<_, error-code>; accept: func() -> result, error-code>; local-address: func() -> result; remote-address: func() -> result; is-listening: func() -> bool; address-family: func() -> ip-address-family; set-listen-backlog-size: func(value: u64) -> result<_, error-code>; keep-alive-enabled: func() -> result; set-keep-alive-enabled: func(value: bool) -> result<_, error-code>; keep-alive-idle-time: func() -> result; set-keep-alive-idle-time: func(value: duration) -> result<_, error-code>; keep-alive-interval: func() -> result; set-keep-alive-interval: func(value: duration) -> result<_, error-code>; keep-alive-count: func() -> result; set-keep-alive-count: func(value: u32) -> result<_, error-code>; hop-limit: func() -> result; set-hop-limit: func(value: u8) -> result<_, error-code>; receive-buffer-size: func() -> result; set-receive-buffer-size: func(value: u64) -> result<_, error-code>; send-buffer-size: func() -> result; set-send-buffer-size: func(value: u64) -> result<_, error-code>; subscribe: func() -> pollable; shutdown: func(shutdown-type: shutdown-type) -> result<_, error-code>; } } interface tcp-create-socket { use network.{network, error-code, ip-address-family}; use tcp.{tcp-socket}; create-tcp-socket: func(address-family: ip-address-family) -> result; } interface ip-name-lookup { use wasi:io/poll@0.2.0.{pollable}; use network.{network, error-code, ip-address}; resource resolve-address-stream { resolve-next-address: func() -> result, error-code>; subscribe: func() -> pollable; } resolve-addresses: func(network: borrow, name: string) -> result; }