diff --git a/phases/ephemeral/docs.md b/phases/ephemeral/docs.md index f17e9aa9..a1b0684b 100644 --- a/phases/ephemeral/docs.md +++ b/phases/ephemeral/docs.md @@ -397,8 +397,35 @@ The right to invoke `path_unlink_file`. If [`rights::fd_read`](#rights.fd_read) is set, includes the right to invoke `poll_oneoff` to subscribe to [`eventtype::fd_read`](#eventtype.fd_read). If [`rights::fd_write`](#rights.fd_write) is set, includes the right to invoke `poll_oneoff` to subscribe to [`eventtype::fd_write`](#eventtype.fd_write). -- `sock_shutdown` -The right to invoke `sock_shutdown`. +- `sock_connect` +Connect to an address + +- `sock_listen` +Listen for incoming connection on an address + +- `sock_bind` +Bind an address to a socket + +- `sock_accept` +Accept incoming connection + +- `sock_recv` +Receive data on a socket + +- `sock_send` +Send data on a socket + +- `sock_addr_local` +Retrieve locally bound address on a socket + +- `sock_addr_remote` +Retrieve remote address on a socket + +- `sock_recv_from` +Receive datagram on a socket + +- `sock_send_to` +Send datagram on a socket ## `fd` A file descriptor handle. @@ -540,6 +567,9 @@ The file refers to a symbolic link inode. - `fifo` The file descriptor or file refers to a FIFO. +- `address_pool` +Address pool + ## `dirent`: Struct A directory entry. @@ -1033,6 +1063,169 @@ Alignment: 2 - `recv_data_truncated` Returned by `sock_recv`: Message data has been truncated. +## `sock_type`: Enum(`u8`) +Socket type + +Size: 1 + +Alignment: 1 + +### Variants +- `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`: Enum(`u8`) +Address type + +Size: 1 + +Alignment: 1 + +### Variants +- `ip4` +IPv4 address + +- `ip6` +IPv6 address + +## `addr_ip4`: Struct +An IPv4 address is a 32-bit number that uniquely identifies a network interface on a machine. + +Size: 4 + +Alignment: 1 + +### Struct members +- `n0`: `u8` + +Offset: 0 + +- `n1`: `u8` + +Offset: 1 + +- `h0`: `u8` + +Offset: 2 + +- `h1`: `u8` + +Offset: 3 + +## `addr_ip4_port`: Struct +An IPv4 address with a port number + +Size: 6 + +Alignment: 2 + +### Struct members +- `addr`: [`addr_ip4`](#addr_ip4) + +Offset: 0 + +- `port`: [`ip_port`](#ip_port) + +Offset: 4 + +## `addr_ip6`: Struct +An IPv6 address is a 128-bit number that uniquely identifies a network interface on a machine. + +Size: 16 + +Alignment: 2 + +### Struct 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`: Struct +An IPv6 address with a port number + +Size: 18 + +Alignment: 2 + +### Struct members +- `addr`: [`addr_ip6`](#addr_ip6) + +Offset: 0 + +- `port`: [`ip_port`](#ip_port) + +Offset: 16 + +## `addr`: Union +Union of all possible addresses type + +Size: 20 + +Alignment: 2 + +### Union Layout +- tag_size: 1 +- tag_align: 1 +- contents_offset: 2 +- contents_size: 18 +- contents_align: 2 +### Union variants +- `ip4`: [`addr_ip4_port`](#addr_ip4_port) + +- `ip6`: [`addr_ip6_port`](#addr_ip6_port) + +## `address_family`: Enum(`u8`) +Address family + +Size: 1 + +Alignment: 1 + +### Variants +- `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. @@ -1998,50 +2191,396 @@ Note: This is similar to [`yield`](#yield) in POSIX. --- -#### `recv(fd: fd, ri_data: iovec_array, ri_flags: riflags) -> (errno, size, roflags)` +#### `addr_local(fd: fd, buf: Pointer, buf_len: size) -> 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`: [`errno`](#errno) + + +--- + +#### `addr_remote(fd: fd, buf: Pointer, buf_len: size) -> 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`: [`errno`](#errno) + + +--- + +#### `open(pool: fd, af: address_family, socktype: sock_type) -> (errno, fd)` +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`: [`errno`](#errno) + +- `fd`: [`fd`](#fd) +The opened socket + + +--- + +#### `close(fd: fd) -> 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`: [`errno`](#errno) + + +--- + +#### `set_reuse_addr(fd: fd, reuse: u8) -> 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`: [`errno`](#errno) + + +--- + +#### `get_reuse_addr(fd: fd) -> (errno, u8)` +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`: [`errno`](#errno) + +- `reuse`: `u8` + + +--- + +#### `set_reuse_port(fd: fd, reuse: u8) -> 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`: [`errno`](#errno) + + +--- + +#### `get_reuse_port(fd: fd) -> (errno, u8)` +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`: [`errno`](#errno) + +- `reuse`: `u8` + + +--- + +#### `set_recv_buf_size(fd: fd, size: size) -> 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`: [`errno`](#errno) + + +--- + +#### `get_recv_buf_size(fd: fd) -> (errno, size)` +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`: [`errno`](#errno) + +- `size`: [`size`](#size) + + +--- + +#### `set_send_buf_size(fd: fd, size: size) -> 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`: [`errno`](#errno) + + +--- + +#### `get_send_buf_size(fd: fd) -> (errno, size)` +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`: [`errno`](#errno) + +- `size`: [`size`](#size) + + +--- + +#### `bind(fd: fd, addr: Pointer) -> 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`: [`errno`](#errno) + + +--- + +#### `listen(fd: fd, backlog: size) -> 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`: [`errno`](#errno) + + +--- + +#### `accept(fd: fd) -> (errno, fd)` +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`: [`errno`](#errno) + +- `childfd`: [`fd`](#fd) + + +--- + +#### `connect(fd: fd, addr: Pointer) -> 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`: [`errno`](#errno) + + +--- + +#### `recv(fd: fd, buf: Pointer, buf_len: size, flags: riflags) -> (errno, size)` 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) +- `flags`: [`riflags`](#riflags) Message flags. ##### Results - `error`: [`errno`](#errno) -- `ro_datalen`: [`size`](#size) -Number of bytes stored in ri_data. +- `bufused`: [`size`](#size) + + +--- + +#### `recv_from(fd: fd, buf: Pointer, buf_len: size, addr_buf: Pointer, addr_buf_len: size, flags: riflags) -> (errno, size)` +Receive a message from a socket. -- `ro_flags`: [`roflags`](#roflags) +The address buffer must be at least the size of addr_t. + +Note: This is similar to `recvfrom` in POSIX. + +##### Params +- `fd`: [`fd`](#fd) + +- `buf`: `Pointer` +The buffer where data will be stored + +- `buf_len`: [`size`](#size) + +- `addr_buf`: `Pointer` +The address of origin for the message + +- `addr_buf_len`: [`size`](#size) + +- `flags`: [`riflags`](#riflags) Message flags. +##### Results +- `error`: [`errno`](#errno) + +- `bufused`: [`size`](#size) + --- -#### `send(fd: fd, si_data: ciovec_array, si_flags: siflags) -> (errno, size)` +#### `send(fd: fd, buf: Pointer, buf_len: size, flags: siflags) -> (errno, size)` 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) +- `flags`: [`siflags`](#siflags) Message flags. ##### Results - `error`: [`errno`](#errno) -- `so_datalen`: [`size`](#size) +- `bufused`: [`size`](#size) +Number of bytes transmitted. + + +--- + +#### `send_to(fd: fd, buf: Pointer, buf_len: size, addr: Pointer, flags: siflags) -> (errno, size)` +Send a message on a socket. +Note: This is similar to `sendto` in POSIX. + +##### Params +- `fd`: [`fd`](#fd) + +- `buf`: `Pointer` +The buffer where data will be stored + +- `buf_len`: [`size`](#size) + +- `addr`: `Pointer` +Address of the socket to send message to + +- `flags`: [`siflags`](#siflags) +Message flags. + +##### Results +- `error`: [`errno`](#errno) + +- `bufused`: [`size`](#size) Number of bytes transmitted. diff --git a/phases/ephemeral/witx/typenames.witx b/phases/ephemeral/witx/typenames.witx index 349952a1..5a6544e7 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 ) ) @@ -357,6 +375,8 @@ $symbolic_link ;;; The file descriptor or file refers to a FIFO. $fifo + ;;; Address pool + $address_pool ) ) @@ -661,6 +681,87 @@ ) ) +;;; Socket type +(typename $sock_type + (enum 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 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 + (struct + (field $n0 u8) + (field $n1 u8) + (field $h0 u8) + (field $h1 u8) + ) +) + +;;; An IPv4 address with a port number +(typename $addr_ip4_port + (struct + (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 + (struct + (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 + (struct + (field $addr $addr_ip6) + (field $port $ip_port) + ) +) + +;;; Union of all possible addresses type +(typename $addr + (union $addr_type + (field $ip4 $addr_ip4_port) + (field $ip6 $addr_ip6_port) + ) +) + +;;; Address family +(typename $address_family + (enum 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 becf80ff..908ff68a 100644 --- a/phases/ephemeral/witx/wasi_ephemeral_sock.witx +++ b/phases/ephemeral/witx/wasi_ephemeral_sock.witx @@ -11,34 +11,241 @@ ;;; 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 $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 $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) + (result $error $errno) + ;;; The opened socket + (result $fd $fd) + ) + + ;;; 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 $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 $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 $errno) + (result $reuse u8) + ) + + ;;; 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 $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 $errno) + (result $reuse u8) + ) + + ;;; 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 $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 $errno) + (result $size $size) + ) + + ;;; 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 $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 $errno) + (result $size $size) + ) + + ;;; 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 $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 $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 $errno) + (result $childfd $fd) + ) + + ;;; 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 $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) + (param $flags $riflags) (result $error $errno) - ;;; Number of bytes stored in ri_data. - (result $ro_datalen $size) + (result $bufused $size) + ) + + ;;; Receive a message from a socket. + ;;; + ;;; The address buffer must be at least the size of addr_t. + ;;; + ;;; Note: This is similar to `recvfrom` in POSIX. + (@interface func (export "recv_from") + (param $fd $fd) + ;;; The buffer where data will be stored + (param $buf (@witx pointer u8)) + (param $buf_len $size) + ;;; The address of origin for the message + (param $addr_buf (@witx pointer u8)) + (param $addr_buf_len $size) ;;; Message flags. - (result $ro_flags $roflags) + (param $flags $riflags) + (result $error $errno) + (result $bufused $size) ) ;;; 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 $flags $siflags) + (result $error $errno) + ;;; Number of bytes transmitted. + (result $bufused $size) + ) + + ;;; Send a message on a socket. + ;;; Note: This is similar to `sendto` in POSIX. + (@interface func (export "send_to") + (param $fd $fd) + ;;; The buffer where data will be stored + (param $buf (@witx pointer u8)) + (param $buf_len $size) + ;;; Address of the socket to send message to + (param $addr (@witx pointer $addr)) ;;; Message flags. - (param $si_flags $siflags) + (param $flags $siflags) (result $error $errno) ;;; Number of bytes transmitted. - (result $so_datalen $size) + (result $bufused $size) ) ;;; Shut down socket send and receive channels. diff --git a/phases/snapshot/docs.md b/phases/snapshot/docs.md index 640943f8..7da41888 100644 --- a/phases/snapshot/docs.md +++ b/phases/snapshot/docs.md @@ -389,9 +389,6 @@ The right to invoke [`path_unlink_file`](#path_unlink_file). If [`rights::fd_read`](#rights.fd_read) is set, includes the right to invoke [`poll_oneoff`](#poll_oneoff) to subscribe to [`eventtype::fd_read`](#eventtype.fd_read). If [`rights::fd_write`](#rights.fd_write) is set, includes the right to invoke [`poll_oneoff`](#poll_oneoff) to subscribe to [`eventtype::fd_write`](#eventtype.fd_write). -- `sock_shutdown` -The right to invoke [`sock_shutdown`](#sock_shutdown). - ## `fd` A file descriptor handle. diff --git a/phases/snapshot/witx/typenames.witx b/phases/snapshot/witx/typenames.witx index b7737273..aab8fd2f 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 ) )