diff --git a/phases/ephemeral/docs.md b/phases/ephemeral/docs.md index f29d401c..45b5570c 100644 --- a/phases/ephemeral/docs.md +++ b/phases/ephemeral/docs.md @@ -457,11 +457,56 @@ If [`rights::fd_write`](#rights.fd_write) is set, includes the right to invoke ` Bit: 29 -- `sock_shutdown`: `bool` -The right to invoke `sock_shutdown`. +- `sock_connect`: `bool` +Connect to an address Bit: 30 +- `sock_listen`: `bool` +Listen for incoming connection on an address + +Bit: 31 + +- `sock_bind`: `bool` +Bind an address to a socket + +Bit: 32 + +- `sock_accept`: `bool` +Accept incoming connection + +Bit: 33 + +- `sock_recv`: `bool` +Receive data on a socket + +Bit: 34 + +- `sock_send`: `bool` +Send data on a socket + +Bit: 35 + +- `sock_addr_local`: `bool` +Retrieve locally bound address on a socket + +Bit: 36 + +- `sock_addr_remote`: `bool` +Retrieve remote address on a socket + +Bit: 37 + +- `sock_recv_from`: `bool` +Receive datagram on a socket + +Bit: 38 + +- `sock_send_to`: `bool` +Send datagram on a socket + +Bit: 39 + ## `fd`: `Handle` A file descriptor handle. @@ -601,6 +646,9 @@ The file refers to a symbolic link inode. - `fifo` The file descriptor or file refers to a FIFO. +- `address_pool` +Address pool + ## `dirent`: `Record` A directory entry. @@ -1141,6 +1189,174 @@ Returned by `sock_recv`: Message data has been truncated. Bit: 0 +## `reuse`: `u8` +is reused + +Size: 1 + +Alignment: 1 + +## `sock_type`: `Variant` +Socket type + +Size: 1 + +Alignment: 1 + +### Variant cases +- `socket_dgram` +The file descriptor or file refers to a datagram socket. + +- `socket_stream` +The file descriptor or file refers to a byte-stream socket. + +## `ip_port`: `u16` +IP port number + +Size: 2 + +Alignment: 2 + +## `addr_type`: `Variant` +Address type + +Size: 1 + +Alignment: 1 + +### Variant cases +- `ip4` +IPv4 address + +- `ip6` +IPv6 address + +## `addr_ip4`: `Record` +An IPv4 address is a 32-bit number that uniquely identifies a network interface on a machine. + +Size: 4 + +Alignment: 1 + +### Record members +- `n0`: `u8` + +Offset: 0 + +- `n1`: `u8` + +Offset: 1 + +- `h0`: `u8` + +Offset: 2 + +- `h1`: `u8` + +Offset: 3 + +## `addr_ip4_port`: `Record` +An IPv4 address with a port number + +Size: 6 + +Alignment: 2 + +### Record members +- `addr`: [`addr_ip4`](#addr_ip4) + +Offset: 0 + +- `port`: [`ip_port`](#ip_port) + +Offset: 4 + +## `addr_ip6`: `Record` +An IPv6 address is a 128-bit number that uniquely identifies a network interface on a machine. + +Size: 16 + +Alignment: 2 + +### Record members +- `n0`: `u16` + +Offset: 0 + +- `n1`: `u16` + +Offset: 2 + +- `n2`: `u16` + +Offset: 4 + +- `n3`: `u16` + +Offset: 6 + +- `h0`: `u16` + +Offset: 8 + +- `h1`: `u16` + +Offset: 10 + +- `h2`: `u16` + +Offset: 12 + +- `h3`: `u16` + +Offset: 14 + +## `addr_ip6_port`: `Record` +An IPv6 address with a port number + +Size: 18 + +Alignment: 2 + +### Record members +- `addr`: [`addr_ip6`](#addr_ip6) + +Offset: 0 + +- `port`: [`ip_port`](#ip_port) + +Offset: 16 + +## `addr`: `Variant` +Union of all possible addresses type + +Size: 20 + +Alignment: 2 + +### Variant Layout +- size: 20 +- align: 2 +- tag_size: 1 +### Variant cases +- `ip4`: [`addr_ip4_port`](#addr_ip4_port) + +- `ip6`: [`addr_ip6_port`](#addr_ip6_port) + +## `address_family`: `Variant` +Address family + +Size: 1 + +Alignment: 1 + +### Variant cases +- `inet4` +IP v4 + +- `inet6` +IP v6 + ## `siflags`: `u16` Flags provided to `sock_send`. As there are currently no flags defined, it must be set to zero. @@ -2469,16 +2685,439 @@ Note: This is similar to [`yield`](#yield) in POSIX. --- -#### `recv(fd: fd, ri_data: iovec_array, ri_flags: riflags) -> Result<(size, roflags), errno>` +#### `addr_local(fd: fd, buf: Pointer, buf_len: size) -> Result<(), errno>` +Returns the local address to which the socket is bound. + +Note: This is similar to `getsockname` in POSIX + +When successful, the contents of the output buffer consist of an IP address, +either IP4 or IP6. + +##### Params +- `fd`: [`fd`](#fd) +Host to resolve + +- `buf`: `Pointer` +The buffer where IP addresses will be stored + +- `buf_len`: [`size`](#size) + +##### Results +- `error`: `Result<(), errno>` + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok` + +- `err`: [`errno`](#errno) + + +--- + +#### `addr_remote(fd: fd, buf: Pointer, buf_len: size) -> Result<(), errno>` +Returns the remote address to which the socket is connected to. + +Note: This is similar to `getpeername` in POSIX + +When successful, the contents of the output buffer consist of an IP address, +either IP4 or IP6. + +##### Params +- `fd`: [`fd`](#fd) +Host to resolve + +- `buf`: `Pointer` +The buffer where IP addresses will be stored + +- `buf_len`: [`size`](#size) + +##### Results +- `error`: `Result<(), errno>` + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok` + +- `err`: [`errno`](#errno) + + +--- + +#### `open(pool: fd, af: address_family, socktype: sock_type) -> Result` +Open a socket + +The first argument to this function is a handle to an +address pool. The address pool determines what actions can +be performed and at which addresses they can be performed to. + +The address pool cannot be re-assigned. You will need to close +the socket and open a new one to use a different address pool. + +Note: This is similar to `socket` in POSIX using PF_INET + +##### Params +- `pool`: [`fd`](#fd) +Address pool file descriptor + +- `af`: [`address_family`](#address_family) +Address family + +- `socktype`: [`sock_type`](#sock_type) +Socket type, either datagram or stream + +##### Results +- `error`: `Result` +The opened socket + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok`: [`fd`](#fd) + +- `err`: [`errno`](#errno) + + +--- + +#### `close(fd: fd) -> Result<(), errno>` +Close a socket (this is an alias for `fd_close`) +Note: This is similar to [`close`](#close) in POSIX. + +##### Params +- `fd`: [`fd`](#fd) +Socket descriptor + +##### Results +- `error`: `Result<(), errno>` + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok` + +- `err`: [`errno`](#errno) + + +--- + +#### `set_reuse_addr(fd: fd, reuse: u8) -> Result<(), errno>` +Enable/disable address reuse on a socket +Note: This is similar to `setsockopt` in POSIX for SO_REUSEADDR + +##### Params +- `fd`: [`fd`](#fd) +Socket descriptor + +- `reuse`: `u8` +1 to enable, 0 to disable + +##### Results +- `error`: `Result<(), errno>` + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok` + +- `err`: [`errno`](#errno) + + +--- + +#### `get_reuse_addr(fd: fd) -> Result` +Retrieve status of address reuse on a socket +Note: This is similar to `getsockopt` in POSIX for SO_REUSEADDR + +##### Params +- `fd`: [`fd`](#fd) +Socket descriptor + +##### Results +- `error`: `Result` + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok`: [`reuse`](#reuse) + +- `err`: [`errno`](#errno) + + +--- + +#### `set_reuse_port(fd: fd, reuse: u8) -> Result<(), errno>` +Enable port reuse on a socket +Note: This is similar to `setsockopt` in POSIX for SO_REUSEPORT + +##### Params +- `fd`: [`fd`](#fd) +Socket descriptor + +- `reuse`: `u8` +1 to enable, 0 to disable + +##### Results +- `error`: `Result<(), errno>` + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok` + +- `err`: [`errno`](#errno) + + +--- + +#### `get_reuse_port(fd: fd) -> Result` +Retrieve status of port reuse on a socket +Note: This is similar to `getsockopt` in POSIX for SO_REUSEPORT + +##### Params +- `fd`: [`fd`](#fd) +Socket descriptor + +##### Results +- `error`: `Result` + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok`: [`reuse`](#reuse) + +- `err`: [`errno`](#errno) + + +--- + +#### `set_recv_buf_size(fd: fd, size: size) -> Result<(), errno>` +Set size of receive buffer +Note: This is similar to `setsockopt` in POSIX for SO_RCVBUF + +##### Params +- `fd`: [`fd`](#fd) +Socket descriptor + +- `size`: [`size`](#size) +Buffer size + +##### Results +- `error`: `Result<(), errno>` + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok` + +- `err`: [`errno`](#errno) + + +--- + +#### `get_recv_buf_size(fd: fd) -> Result` +Retrieve the size of the receive buffer +Note: This is similar to `getsockopt` in POSIX for SO_RCVBUF + +##### Params +- `fd`: [`fd`](#fd) +Socket descriptor + +##### Results +- `error`: `Result` + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok`: [`size`](#size) + +- `err`: [`errno`](#errno) + + +--- + +#### `set_send_buf_size(fd: fd, size: size) -> Result<(), errno>` +Set size of send buffer +Note: This is similar to `setsockopt` in POSIX for SO_SNDBUF + +##### Params +- `fd`: [`fd`](#fd) +Socket descriptor + +- `size`: [`size`](#size) +Buffer size + +##### Results +- `error`: `Result<(), errno>` + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok` + +- `err`: [`errno`](#errno) + + +--- + +#### `get_send_buf_size(fd: fd) -> Result` +Retrieve the size of the send buffer +Note: This is similar to `getsockopt` in POSIX for SO_SNDBUF + +##### Params +- `fd`: [`fd`](#fd) +Socket descriptor + +##### Results +- `error`: `Result` + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok`: [`size`](#size) + +- `err`: [`errno`](#errno) + + +--- + +#### `bind(fd: fd, addr: Pointer) -> Result<(), errno>` +Bind a socket +Note: This is similar to [`bind`](#bind) in POSIX using PF_INET + +##### Params +- `fd`: [`fd`](#fd) +File descriptor of the socket to be bind + +- `addr`: `Pointer` +Address to bind the socket to + +##### Results +- `error`: `Result<(), errno>` + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok` + +- `err`: [`errno`](#errno) + + +--- + +#### `listen(fd: fd, backlog: size) -> Result<(), errno>` +Listen for connections on a socket +Note: This is similar to [`listen`](#listen) + +##### Params +- `fd`: [`fd`](#fd) +File descriptor of the socket to be bind + +- `backlog`: [`size`](#size) +Maximum size of the queue for pending connections + +##### Results +- `error`: `Result<(), errno>` + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok` + +- `err`: [`errno`](#errno) + + +--- + +#### `accept(fd: fd) -> Result` +Accept a connection on a socket +Note: This is similar to [`accept`](#accept) + +##### Params +- `fd`: [`fd`](#fd) +File descriptor of the socket to be bind + +##### Results +- `error`: `Result` + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok`: [`fd`](#fd) + +- `err`: [`errno`](#errno) + + +--- + +#### `connect(fd: fd, addr: Pointer) -> Result<(), errno>` +Initiate a connection on a socket to the specified address +Note: This is similar to [`connect`](#connect) in POSIX + +##### Params +- `fd`: [`fd`](#fd) +Socket descriptor + +- `addr`: `Pointer` +Address of the socket to connect to + +##### Results +- `error`: `Result<(), errno>` + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok` + +- `err`: [`errno`](#errno) + + +--- + +#### `recv(fd: fd, buf: Pointer, buf_len: size, ri_flags: riflags) -> Result<(size, roflags), errno>` Receive a message from a socket. -Note: This is similar to [`recv`](#recv) in POSIX, though it also supports reading -the data into multiple buffers in the manner of `readv`. +Note: This is similar to [`recv`](#recv) in POSIX. ##### Params - `fd`: [`fd`](#fd) -- `ri_data`: [`iovec_array`](#iovec_array) -List of scatter/gather vectors to which to store data. +- `buf`: `Pointer` +The buffer where data will be stored + +- `buf_len`: [`size`](#size) - `ri_flags`: [`riflags`](#riflags) Message flags. @@ -2508,16 +3147,17 @@ Offset: 4 --- -#### `send(fd: fd, si_data: ciovec_array, si_flags: siflags) -> Result` +#### `send(fd: fd, buf: Pointer, buf_len: size, si_flags: siflags) -> Result` Send a message on a socket. -Note: This is similar to [`send`](#send) in POSIX, though it also supports writing -the data from multiple buffers in the manner of `writev`. +Note: This is similar to [`send`](#send) in POSIX. ##### Params - `fd`: [`fd`](#fd) -- `si_data`: [`ciovec_array`](#ciovec_array) -List of scatter/gather vectors to which to retrieve data +- `buf`: `Pointer` +The buffer where data will be stored + +- `buf_len`: [`size`](#size) - `si_flags`: [`siflags`](#siflags) Message flags. diff --git a/phases/ephemeral/witx/typenames.witx b/phases/ephemeral/witx/typenames.witx index bbd6489d..93108274 100644 --- a/phases/ephemeral/witx/typenames.witx +++ b/phases/ephemeral/witx/typenames.witx @@ -276,8 +276,26 @@ ;;; If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`. ;;; If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`. $poll_fd_readwrite - ;;; The right to invoke `sock_shutdown`. - $sock_shutdown + ;;; Connect to an address + $sock_connect + ;;; Listen for incoming connection on an address + $sock_listen + ;;; Bind an address to a socket + $sock_bind + ;;; Accept incoming connection + $sock_accept + ;;; Receive data on a socket + $sock_recv + ;;; Send data on a socket + $sock_send + ;;; Retrieve locally bound address on a socket + $sock_addr_local + ;;; Retrieve remote address on a socket + $sock_addr_remote + ;;; Receive datagram on a socket + $sock_recv_from + ;;; Send datagram on a socket + $sock_send_to ) ) @@ -355,6 +373,8 @@ $symbolic_link ;;; The file descriptor or file refers to a FIFO. $fifo + ;;; Address pool + $address_pool ) ) @@ -669,6 +689,90 @@ ) ) +;;; is reused +(typename $reuse u8) + +;;; Socket type +(typename $sock_type + (enum (@witx tag u8) + ;;; The file descriptor or file refers to a datagram socket. + $socket_dgram + ;;; The file descriptor or file refers to a byte-stream socket. + $socket_stream + ) +) + +;;; IP port number +(typename $ip_port u16) + +;;; Address type +(typename $addr_type + (enum (@witx tag u8) + ;;; IPv4 address + $ip4 + ;;; IPv6 address + $ip6 + ) +) + +;;; An IPv4 address is a 32-bit number that uniquely identifies a network interface on a machine. +(typename $addr_ip4 + (record + (field $n0 u8) + (field $n1 u8) + (field $h0 u8) + (field $h1 u8) + ) +) + +;;; An IPv4 address with a port number +(typename $addr_ip4_port + (record + (field $addr $addr_ip4) + (field $port $ip_port) + ) +) + +;;; An IPv6 address is a 128-bit number that uniquely identifies a network interface on a machine. +(typename $addr_ip6 + (record + (field $n0 u16) + (field $n1 u16) + (field $n2 u16) + (field $n3 u16) + (field $h0 u16) + (field $h1 u16) + (field $h2 u16) + (field $h3 u16) + ) +) + +;;; An IPv6 address with a port number +(typename $addr_ip6_port + (record + (field $addr $addr_ip6) + (field $port $ip_port) + ) +) + +;;; Union of all possible addresses type +(typename $addr + (union (@witx tag $addr_type) + $addr_ip4_port + $addr_ip6_port + ) +) + +;;; Address family +(typename $address_family + (enum (@witx tag u8) + ;;; IP v4 + $inet4 + ;;; IP v6 + $inet6 + ) +) + ;;; Flags provided to `sock_send`. As there are currently no flags ;;; defined, it must be set to zero. (typename $siflags u16) diff --git a/phases/ephemeral/witx/wasi_ephemeral_addr.witx b/phases/ephemeral/witx/wasi_ephemeral_addr.witx new file mode 100644 index 00000000..c90e41f7 --- /dev/null +++ b/phases/ephemeral/witx/wasi_ephemeral_addr.witx @@ -0,0 +1,39 @@ +;; WASI Socket Addresses. +;; +;; Some content here is derived from [CloudABI](https://github.com/NuxiNL/cloudabi). +;; +;; This is a `witx` file. See [here](https://github.com/WebAssembly/WASI/tree/master/docs/witx.md) +;; for an explanation of what that means. + +(use "typenames.witx") + +(module $wasi_ephemeral_addr + ;;; Linear memory to be accessed by WASI functions that need it. + (import "memory" (memory)) + + ;;; Resolves a hostname and a port to one or more IP addresses. Port is optional + ;;; and you can pass 0 (zero) in most cases, it is used a hint for protocol. + ;;; + ;;; Note: This is similar to `getaddrinfo` in POSIX + ;;; + ;;; When successful, the contents of the output buffer consist of a sequence of + ;;; IPv4 and/or IPv6 addresses. Each address entry consists of a addr_t object. + ;; + ;;; This function fills the output buffer as much as possible, potentially + ;;; truncating the last address entry. It is advisable that the buffer is + (@interface func (export "resolve") + ;;; Address pool file descriptor + (param $pool $fd) + ;;; Host to resolve + (param $host string) + ;;; Port number + (param $port $ip_port) + ;;; The buffer where IP addresses will be stored + (param $buf (@witx pointer u8)) + (param $buf_len $size) + (result $error $errno) + ;;; The number of bytes stored in the buffer. If less than the size of the buffer, no + ;;; more IP addresses are available. + (result $bufused $size) + ) +) diff --git a/phases/ephemeral/witx/wasi_ephemeral_sock.witx b/phases/ephemeral/witx/wasi_ephemeral_sock.witx index a05b02ea..b15bef45 100644 --- a/phases/ephemeral/witx/wasi_ephemeral_sock.witx +++ b/phases/ephemeral/witx/wasi_ephemeral_sock.witx @@ -11,13 +11,182 @@ ;;; Linear memory to be accessed by WASI functions that need it. (import "memory" (memory)) + ;;; Returns the local address to which the socket is bound. + ;;; + ;;; Note: This is similar to `getsockname` in POSIX + ;;; + ;;; When successful, the contents of the output buffer consist of an IP address, + ;;; either IP4 or IP6. + (@interface func (export "addr_local") + ;;; Host to resolve + (param $fd $fd) + ;;; The buffer where IP addresses will be stored + (param $buf (@witx pointer u8)) + (param $buf_len $size) + (result $error (expected (error $errno))) + ) + + ;;; Returns the remote address to which the socket is connected to. + ;;; + ;;; Note: This is similar to `getpeername` in POSIX + ;;; + ;;; When successful, the contents of the output buffer consist of an IP address, + ;;; either IP4 or IP6. + (@interface func (export "addr_remote") + ;;; Host to resolve + (param $fd $fd) + ;;; The buffer where IP addresses will be stored + (param $buf (@witx pointer u8)) + (param $buf_len $size) + (result $error (expected (error $errno))) + ) + + ;;; Open a socket + ;;; + ;;; The first argument to this function is a handle to an + ;;; address pool. The address pool determines what actions can + ;;; be performed and at which addresses they can be performed to. + ;;; + ;;; The address pool cannot be re-assigned. You will need to close + ;;; the socket and open a new one to use a different address pool. + ;;; + ;;; Note: This is similar to `socket` in POSIX using PF_INET + (@interface func (export "open") + ;;; Address pool file descriptor + (param $pool $fd) + ;;; Address family + (param $af $address_family) + ;;; Socket type, either datagram or stream + (param $socktype $sock_type) + ;;; The opened socket + (result $error (expected $fd (error $errno))) + ) + + ;;; Close a socket (this is an alias for `fd_close`) + ;;; Note: This is similar to `close` in POSIX. + (@interface func (export "close") + ;;; Socket descriptor + (param $fd $fd) + (result $error (expected (error $errno))) + ) + + ;;; Enable/disable address reuse on a socket + ;;; Note: This is similar to `setsockopt` in POSIX for SO_REUSEADDR + (@interface func (export "set_reuse_addr") + ;;; Socket descriptor + (param $fd $fd) + ;;; 1 to enable, 0 to disable + (param $reuse u8) + (result $error (expected (error $errno))) + ) + + ;;; Retrieve status of address reuse on a socket + ;;; Note: This is similar to `getsockopt` in POSIX for SO_REUSEADDR + (@interface func (export "get_reuse_addr") + ;;; Socket descriptor + (param $fd $fd) + (result $error (expected $reuse (error $errno))) + ) + + ;;; Enable port reuse on a socket + ;;; Note: This is similar to `setsockopt` in POSIX for SO_REUSEPORT + (@interface func (export "set_reuse_port") + ;;; Socket descriptor + (param $fd $fd) + ;;; 1 to enable, 0 to disable + (param $reuse u8) + (result $error (expected (error $errno))) + ) + + ;;; Retrieve status of port reuse on a socket + ;;; Note: This is similar to `getsockopt` in POSIX for SO_REUSEPORT + (@interface func (export "get_reuse_port") + ;;; Socket descriptor + (param $fd $fd) + (result $error (expected $reuse (error $errno))) + ) + + ;;; Set size of receive buffer + ;;; Note: This is similar to `setsockopt` in POSIX for SO_RCVBUF + (@interface func (export "set_recv_buf_size") + ;;; Socket descriptor + (param $fd $fd) + ;;; Buffer size + (param $size $size) + (result $error (expected (error $errno))) + ) + + ;;; Retrieve the size of the receive buffer + ;;; Note: This is similar to `getsockopt` in POSIX for SO_RCVBUF + (@interface func (export "get_recv_buf_size") + ;;; Socket descriptor + (param $fd $fd) + (result $error (expected $size (error $errno))) + ) + + ;;; Set size of send buffer + ;;; Note: This is similar to `setsockopt` in POSIX for SO_SNDBUF + (@interface func (export "set_send_buf_size") + ;;; Socket descriptor + (param $fd $fd) + ;;; Buffer size + (param $size $size) + (result $error (expected (error $errno))) + ) + + ;;; Retrieve the size of the send buffer + ;;; Note: This is similar to `getsockopt` in POSIX for SO_SNDBUF + (@interface func (export "get_send_buf_size") + ;;; Socket descriptor + (param $fd $fd) + (result $error (expected $size (error $errno))) + ) + + ;;; Bind a socket + ;;; Note: This is similar to `bind` in POSIX using PF_INET + (@interface func (export "bind") + ;;; File descriptor of the socket to be bind + (param $fd $fd) + ;;; Address to bind the socket to + (param $addr (@witx pointer $addr)) + (result $error (expected (error $errno))) + ) + + ;;; Listen for connections on a socket + ;;; Note: This is similar to `listen` + (@interface func (export "listen") + ;;; File descriptor of the socket to be bind + (param $fd $fd) + ;;; Maximum size of the queue for pending connections + (param $backlog $size) + (result $error (expected (error $errno))) + ) + + ;;; Accept a connection on a socket + ;;; Note: This is similar to `accept` + (@interface func (export "accept") + ;;; File descriptor of the socket to be bind + (param $fd $fd) + (result $error (expected $fd (error $errno))) + ) + + ;;; Initiate a connection on a socket to the specified address + ;;; Note: This is similar to `connect` in POSIX + (@interface func (export "connect") + ;;; Socket descriptor + (param $fd $fd) + ;;; Address of the socket to connect to + (param $addr (@witx pointer $addr)) + (result $error (expected (error $errno))) + ) + ;;; Receive a message from a socket. - ;;; Note: This is similar to `recv` in POSIX, though it also supports reading - ;;; the data into multiple buffers in the manner of `readv`. + ;;; Note: This is similar to `recv` in POSIX. (@interface func (export "recv") (param $fd $fd) - ;;; List of scatter/gather vectors to which to store data. - (param $ri_data $iovec_array) + ;;; The buffer where data will be stored + (param $buf (@witx pointer u8)) + (param $buf_len $size) ;;; Message flags. (param $ri_flags $riflags) ;;; Number of bytes stored in ri_data and message flags. @@ -25,12 +194,12 @@ ) ;;; Send a message on a socket. - ;;; Note: This is similar to `send` in POSIX, though it also supports writing - ;;; the data from multiple buffers in the manner of `writev`. + ;;; Note: This is similar to `send` in POSIX. (@interface func (export "send") (param $fd $fd) - ;;; List of scatter/gather vectors to which to retrieve data - (param $si_data $ciovec_array) + ;;; The buffer where data will be stored + (param $buf (@witx pointer u8)) + (param $buf_len $size) ;;; Message flags. (param $si_flags $siflags) ;;; Number of bytes transmitted. diff --git a/phases/snapshot/docs.md b/phases/snapshot/docs.md index e91c22c8..a96cc7fd 100644 --- a/phases/snapshot/docs.md +++ b/phases/snapshot/docs.md @@ -445,11 +445,6 @@ If [`rights::fd_write`](#rights.fd_write) is set, includes the right to invoke [ Bit: 27 -- `sock_shutdown`: `bool` -The right to invoke [`sock_shutdown`](#sock_shutdown). - -Bit: 28 - ## `fd`: `Handle` A file descriptor handle. @@ -2011,7 +2006,7 @@ The path at which to create the directory. #### `path_filestat_get(fd: fd, flags: lookupflags, path: string) -> Result` Return the attributes of a file or directory. -Note: This is similar to `fstatat` in POSIX. +Note: This is similar to `stat` in POSIX. ##### Params - `fd`: [`fd`](#fd) diff --git a/phases/snapshot/witx/typenames.witx b/phases/snapshot/witx/typenames.witx index 311b4223..568082b9 100644 --- a/phases/snapshot/witx/typenames.witx +++ b/phases/snapshot/witx/typenames.witx @@ -268,8 +268,6 @@ ;;; If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`. ;;; If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`. $poll_fd_readwrite - ;;; The right to invoke `sock_shutdown`. - $sock_shutdown ) )