From 4bd545e8a75b58b18ddf190a07e40bc276a87ea2 Mon Sep 17 00:00:00 2001 From: Emiliano Lesende Date: Thu, 4 Jun 2020 17:47:50 -0300 Subject: [PATCH 1/4] feat(socket): initial witx update for new socket functions. addr_resolve, sock_open, sock_connect feat(socket): added port to addr_resolve so DNS SRV records can also be searched feat(socket): added new rights, removed local socket feat(socket): added missing sock_bind, sock_listen, sock_accept feat(socket): add address family feat(socket): added new rights for bind and accept feat(socket): removed sock_shutdown perm. might bring it back. feat(socket): changed recv to not use iovec since there is pread for that feat(socket): sock_send now uses regular buffer rather than iovecs feat(socket): added sock_addr_local and sock_addr_remote feat(socket): added sock_close, sock_set_reuse_addr and sock_set_reuse_port feat(socket): added sock_set_recv_buf_size and sock_get_recv_buf_size feat(socket): added sock_set_send_buf_size, sock_get_send_buf_size feat(socket): added sock_send_to and sock_recv_from for UDP feat(socket): changed sock_open and addr_resolve to receive a handle to an address pool feat(socket): moved socket API into ephemeral --- phases/ephemeral/witx/typenames.witx | 98 ++++++- .../ephemeral/witx/wasi_ephemeral_sock.witx | 267 ++++++++++++++++-- phases/snapshot/witx/typenames.witx | 2 - 3 files changed, 346 insertions(+), 21 deletions(-) diff --git a/phases/ephemeral/witx/typenames.witx b/phases/ephemeral/witx/typenames.witx index 349952a1..a795043a 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,80 @@ ) ) + + +;;; 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) + ) +) + ;;; 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_sock.witx b/phases/ephemeral/witx/wasi_ephemeral_sock.witx index becf80ff..6d1f1fca 100644 --- a/phases/ephemeral/witx/wasi_ephemeral_sock.witx +++ b/phases/ephemeral/witx/wasi_ephemeral_sock.witx @@ -11,39 +11,272 @@ ;;; 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 "addr_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) + ) + + ;;; 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 "sock_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 "sock_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 "sock_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 "sock_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 "sock_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 "sock_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 "sock_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 "sock_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 "sock_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 "sock_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 "sock_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 "sock_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 "sock_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 "sock_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 "sock_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 "sock_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`. - (@interface func (export "recv") + ;;; Note: This is similar to `recv` in POSIX. + (@interface func (export "sock_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 "sock_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. + (@interface func (export "sock_send") + (param $fd $fd) + ;;; 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 `send` in POSIX, though it also supports writing - ;;; the data from multiple buffers in the manner of `writev`. - (@interface func (export "send") + ;;; Note: This is similar to `sendto` in POSIX. + (@interface func (export "sock_send_to") (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) + ;;; 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. ;;; Note: This is similar to `shutdown` in POSIX. - (@interface func (export "shutdown") + (@interface func (export "sock_shutdown") (param $fd $fd) ;;; Which channels on the socket to shut down. (param $how $sdflags) 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 ) ) From 5130daf2046682d9a9bfda3e991c97364958922f Mon Sep 17 00:00:00 2001 From: Emiliano Lesende Date: Tue, 18 Aug 2020 13:19:33 -0300 Subject: [PATCH 2/4] feat(socket): updated docs --- phases/ephemeral/docs.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/phases/ephemeral/docs.md b/phases/ephemeral/docs.md index f17e9aa9..bc7d59df 100644 --- a/phases/ephemeral/docs.md +++ b/phases/ephemeral/docs.md @@ -397,9 +397,6 @@ 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`. - ## `fd` A file descriptor handle. From 093bf8744fca3bde32903b200a3c763b2a961f6e Mon Sep 17 00:00:00 2001 From: Emiliano Lesende Date: Tue, 18 Aug 2020 13:33:27 -0300 Subject: [PATCH 3/4] feat(socket): added missing address family and updated docs --- phases/ephemeral/docs.md | 640 +++++++++++++++++++++++++-- phases/ephemeral/witx/typenames.witx | 13 +- phases/snapshot/docs.md | 3 - 3 files changed, 619 insertions(+), 37 deletions(-) diff --git a/phases/ephemeral/docs.md b/phases/ephemeral/docs.md index bc7d59df..fb49254c 100644 --- a/phases/ephemeral/docs.md +++ b/phases/ephemeral/docs.md @@ -296,7 +296,7 @@ If `path_open` is set, includes the right to invoke `path_open` with [`fdflags::dsync`](#fdflags.dsync). - `fd_read` -The right to invoke `fd_read` and `sock_recv`. +The right to invoke `fd_read` and [`sock_recv`](#sock_recv). If [`rights::fd_seek`](#rights.fd_seek) is set, includes the right to invoke `fd_pread`. - `fd_seek` @@ -316,7 +316,7 @@ remains unaltered (i.e., [`whence::cur`](#whence.cur) with offset zero), or to invoke `fd_tell`. - `fd_write` -The right to invoke `fd_write` and `sock_send`. +The right to invoke `fd_write` and [`sock_send`](#sock_send). If [`rights::fd_seek`](#rights.fd_seek) is set, includes the right to invoke `fd_pwrite`. - `fd_advise` @@ -397,6 +397,36 @@ 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_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. @@ -537,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. @@ -1006,7 +1039,7 @@ Size: 4 Alignment: 4 ## `riflags`: Flags(`u16`) -Flags provided to `sock_recv`. +Flags provided to [`sock_recv`](#sock_recv). Size: 2 @@ -1020,7 +1053,7 @@ Returns the message without removing it from the socket's receive queue. On byte-stream sockets, block until the full amount of data can be returned. ## `roflags`: Flags(`u16`) -Flags returned by `sock_recv`. +Flags returned by [`sock_recv`](#sock_recv). Size: 2 @@ -1028,10 +1061,173 @@ Alignment: 2 ### Flags - `recv_data_truncated` -Returned by `sock_recv`: Message data has been truncated. +Returned by [`sock_recv`](#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 +Flags provided to [`sock_send`](#sock_send). As there are currently no flags defined, it must be set to zero. Size: 2 @@ -1995,65 +2191,447 @@ Note: This is similar to [`yield`](#yield) in POSIX. --- -#### `recv(fd: fd, ri_data: iovec_array, ri_flags: riflags) -> (errno, size, roflags)` +#### `addr_resolve(pool: fd, host: string, port: ip_port, buf: Pointer, buf_len: size) -> (errno, size)` +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 + +##### Params +- `pool`: [`fd`](#fd) +Address pool file descriptor + +- `host`: `string` +Host to resolve + +- `port`: [`ip_port`](#ip_port) +Port number + +- `buf`: `Pointer` +The buffer where IP addresses will be stored + +- `buf_len`: [`size`](#size) + +##### Results +- `error`: [`errno`](#errno) + +- `bufused`: [`size`](#size) +The number of bytes stored in the buffer. If less than the size of the buffer, no +more IP addresses are available. + + +--- + +#### `sock_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) + + +--- + +#### `sock_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) + + +--- + +#### `sock_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 + + +--- + +#### `sock_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) + + +--- + +#### `sock_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) + + +--- + +#### `sock_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` + + +--- + +#### `sock_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) + + +--- + +#### `sock_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` + + +--- + +#### `sock_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) + + +--- + +#### `sock_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) + + +--- + +#### `sock_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) + + +--- + +#### `sock_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) + + +--- + +#### `sock_bind(fd: fd, addr: Pointer) -> errno` +Bind a socket +Note: This is similar to `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) + + +--- + +#### `sock_listen(fd: fd, backlog: size) -> errno` +Listen for connections on a socket +Note: This is similar to `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) + + +--- + +#### `sock_accept(fd: fd) -> (errno, fd)` +Accept a connection on a socket +Note: This is similar to `accept` + +##### Params +- `fd`: [`fd`](#fd) +File descriptor of the socket to be bind + +##### Results +- `error`: [`errno`](#errno) + +- `childfd`: [`fd`](#fd) + + +--- + +#### `sock_connect(fd: fd, addr: Pointer) -> errno` +Initiate a connection on a socket to the specified address +Note: This is similar to `connect` in POSIX + +##### Params +- `fd`: [`fd`](#fd) +Socket descriptor + +- `addr`: `Pointer` +Address of the socket to connect to + +##### Results +- `error`: [`errno`](#errno) + + +--- + +#### `sock_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` in POSIX. ##### Params -- `fd`: [`fd`](#fd) +- `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) + +- `flags`: [`riflags`](#riflags) +Message flags. + +##### Results +- `error`: [`errno`](#errno) + +- `bufused`: [`size`](#size) + + +--- + +#### `sock_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. + +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) -- `ri_flags`: [`riflags`](#riflags) +- `flags`: [`riflags`](#riflags) Message flags. ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) + +- `bufused`: [`size`](#size) + + +--- + +#### `sock_send(fd: fd, buf: Pointer, buf_len: size, flags: siflags) -> (errno, size)` +Send a message on a socket. +Note: This is similar to `send` in POSIX. + +##### Params +- `fd`: [`fd`](#fd) -- `ro_datalen`: [`size`](#size) -Number of bytes stored in ri_data. +- `buf`: `Pointer` +The buffer where data will be stored -- `ro_flags`: [`roflags`](#roflags) +- `buf_len`: [`size`](#size) + +- `flags`: [`siflags`](#siflags) Message flags. +##### Results +- `error`: [`errno`](#errno) + +- `bufused`: [`size`](#size) +Number of bytes transmitted. + --- -#### `send(fd: fd, si_data: ciovec_array, si_flags: siflags) -> (errno, size)` +#### `sock_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 [`send`](#send) in POSIX, though it also supports writing -the data from multiple buffers in the manner of `writev`. +Note: This is similar to `sendto` in POSIX. ##### Params -- `fd`: [`fd`](#fd) +- `fd`: [`fd`](#fd) + +- `buf`: `Pointer` +The buffer where data will be stored + +- `buf_len`: [`size`](#size) -- `si_data`: [`ciovec_array`](#ciovec_array) -List of scatter/gather vectors to which to retrieve data +- `addr`: `Pointer` +Address of the socket to send message to -- `si_flags`: [`siflags`](#siflags) +- `flags`: [`siflags`](#siflags) Message flags. ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) -- `so_datalen`: [`size`](#size) +- `bufused`: [`size`](#size) Number of bytes transmitted. --- -#### `shutdown(fd: fd, how: sdflags) -> errno` +#### `sock_shutdown(fd: fd, how: sdflags) -> errno` Shut down socket send and receive channels. -Note: This is similar to [`shutdown`](#shutdown) in POSIX. +Note: This is similar to `shutdown` in POSIX. ##### Params -- `fd`: [`fd`](#fd) +- `fd`: [`fd`](#fd) -- `how`: [`sdflags`](#sdflags) +- `how`: [`sdflags`](#sdflags) Which channels on the socket to shut down. ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) diff --git a/phases/ephemeral/witx/typenames.witx b/phases/ephemeral/witx/typenames.witx index a795043a..5a6544e7 100644 --- a/phases/ephemeral/witx/typenames.witx +++ b/phases/ephemeral/witx/typenames.witx @@ -681,8 +681,6 @@ ) ) - - ;;; Socket type (typename $sock_type (enum u8 @@ -746,7 +744,6 @@ ) ) - ;;; Union of all possible addresses type (typename $addr (union $addr_type @@ -755,6 +752,16 @@ ) ) +;;; 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/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. From 2a220ffad644a4fc700996de1e27e4c7d140dfaa Mon Sep 17 00:00:00 2001 From: Emiliano Lesende Date: Wed, 19 Aug 2020 15:02:39 -0300 Subject: [PATCH 4/4] feat(socket): removed prefixes and put addr_resolve into its own module so module prefixes match --- phases/ephemeral/docs.md | 266 ++++++++---------- .../ephemeral/witx/wasi_ephemeral_addr.witx | 39 +++ .../ephemeral/witx/wasi_ephemeral_sock.witx | 68 ++--- 3 files changed, 175 insertions(+), 198 deletions(-) create mode 100644 phases/ephemeral/witx/wasi_ephemeral_addr.witx diff --git a/phases/ephemeral/docs.md b/phases/ephemeral/docs.md index fb49254c..a1b0684b 100644 --- a/phases/ephemeral/docs.md +++ b/phases/ephemeral/docs.md @@ -296,7 +296,7 @@ If `path_open` is set, includes the right to invoke `path_open` with [`fdflags::dsync`](#fdflags.dsync). - `fd_read` -The right to invoke `fd_read` and [`sock_recv`](#sock_recv). +The right to invoke `fd_read` and `sock_recv`. If [`rights::fd_seek`](#rights.fd_seek) is set, includes the right to invoke `fd_pread`. - `fd_seek` @@ -316,7 +316,7 @@ remains unaltered (i.e., [`whence::cur`](#whence.cur) with offset zero), or to invoke `fd_tell`. - `fd_write` -The right to invoke `fd_write` and [`sock_send`](#sock_send). +The right to invoke `fd_write` and `sock_send`. If [`rights::fd_seek`](#rights.fd_seek) is set, includes the right to invoke `fd_pwrite`. - `fd_advise` @@ -1039,7 +1039,7 @@ Size: 4 Alignment: 4 ## `riflags`: Flags(`u16`) -Flags provided to [`sock_recv`](#sock_recv). +Flags provided to `sock_recv`. Size: 2 @@ -1053,7 +1053,7 @@ Returns the message without removing it from the socket's receive queue. On byte-stream sockets, block until the full amount of data can be returned. ## `roflags`: Flags(`u16`) -Flags returned by [`sock_recv`](#sock_recv). +Flags returned by `sock_recv`. Size: 2 @@ -1061,7 +1061,7 @@ Alignment: 2 ### Flags - `recv_data_truncated` -Returned by [`sock_recv`](#sock_recv): Message data has been truncated. +Returned by `sock_recv`: Message data has been truncated. ## `sock_type`: Enum(`u8`) Socket type @@ -1227,7 +1227,7 @@ IP v4 IP v6 ## `siflags`: `u16` -Flags provided to [`sock_send`](#sock_send). As there are currently no flags +Flags provided to `sock_send`. As there are currently no flags defined, it must be set to zero. Size: 2 @@ -2191,43 +2191,7 @@ Note: This is similar to [`yield`](#yield) in POSIX. --- -#### `addr_resolve(pool: fd, host: string, port: ip_port, buf: Pointer, buf_len: size) -> (errno, size)` -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 - -##### Params -- `pool`: [`fd`](#fd) -Address pool file descriptor - -- `host`: `string` -Host to resolve - -- `port`: [`ip_port`](#ip_port) -Port number - -- `buf`: `Pointer` -The buffer where IP addresses will be stored - -- `buf_len`: [`size`](#size) - -##### Results -- `error`: [`errno`](#errno) - -- `bufused`: [`size`](#size) -The number of bytes stored in the buffer. If less than the size of the buffer, no -more IP addresses are available. - - ---- - -#### `sock_addr_local(fd: fd, buf: Pointer, buf_len: size) -> errno` +#### `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 @@ -2236,21 +2200,21 @@ When successful, the contents of the output buffer consist of an IP address, either IP4 or IP6. ##### Params -- `fd`: [`fd`](#fd) +- `fd`: [`fd`](#fd) Host to resolve -- `buf`: `Pointer` +- `buf`: `Pointer` The buffer where IP addresses will be stored -- `buf_len`: [`size`](#size) +- `buf_len`: [`size`](#size) ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) --- -#### `sock_addr_remote(fd: fd, buf: Pointer, buf_len: size) -> 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 @@ -2259,21 +2223,21 @@ When successful, the contents of the output buffer consist of an IP address, either IP4 or IP6. ##### Params -- `fd`: [`fd`](#fd) +- `fd`: [`fd`](#fd) Host to resolve -- `buf`: `Pointer` +- `buf`: `Pointer` The buffer where IP addresses will be stored -- `buf_len`: [`size`](#size) +- `buf_len`: [`size`](#size) ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) --- -#### `sock_open(pool: fd, af: address_family, socktype: sock_type) -> (errno, fd)` +#### `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 @@ -2286,261 +2250,261 @@ 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) +- `pool`: [`fd`](#fd) Address pool file descriptor -- `af`: [`address_family`](#address_family) +- `af`: [`address_family`](#address_family) Address family -- `socktype`: [`sock_type`](#sock_type) +- `socktype`: [`sock_type`](#sock_type) Socket type, either datagram or stream ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) -- `fd`: [`fd`](#fd) +- `fd`: [`fd`](#fd) The opened socket --- -#### `sock_close(fd: fd) -> errno` +#### `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) +- `fd`: [`fd`](#fd) Socket descriptor ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) --- -#### `sock_set_reuse_addr(fd: fd, reuse: u8) -> 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) +- `fd`: [`fd`](#fd) Socket descriptor -- `reuse`: `u8` +- `reuse`: `u8` 1 to enable, 0 to disable ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) --- -#### `sock_get_reuse_addr(fd: fd) -> (errno, u8)` +#### `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) +- `fd`: [`fd`](#fd) Socket descriptor ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) -- `reuse`: `u8` +- `reuse`: `u8` --- -#### `sock_set_reuse_port(fd: fd, reuse: u8) -> errno` +#### `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) +- `fd`: [`fd`](#fd) Socket descriptor -- `reuse`: `u8` +- `reuse`: `u8` 1 to enable, 0 to disable ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) --- -#### `sock_get_reuse_port(fd: fd) -> (errno, u8)` +#### `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) +- `fd`: [`fd`](#fd) Socket descriptor ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) -- `reuse`: `u8` +- `reuse`: `u8` --- -#### `sock_set_recv_buf_size(fd: fd, size: size) -> errno` +#### `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) +- `fd`: [`fd`](#fd) Socket descriptor -- `size`: [`size`](#size) +- `size`: [`size`](#size) Buffer size ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) --- -#### `sock_get_recv_buf_size(fd: fd) -> (errno, size)` +#### `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) +- `fd`: [`fd`](#fd) Socket descriptor ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) -- `size`: [`size`](#size) +- `size`: [`size`](#size) --- -#### `sock_set_send_buf_size(fd: fd, size: size) -> errno` +#### `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) +- `fd`: [`fd`](#fd) Socket descriptor -- `size`: [`size`](#size) +- `size`: [`size`](#size) Buffer size ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) --- -#### `sock_get_send_buf_size(fd: fd) -> (errno, size)` +#### `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) +- `fd`: [`fd`](#fd) Socket descriptor ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) -- `size`: [`size`](#size) +- `size`: [`size`](#size) --- -#### `sock_bind(fd: fd, addr: Pointer) -> errno` +#### `bind(fd: fd, addr: Pointer) -> errno` Bind a socket -Note: This is similar to `bind` in POSIX using PF_INET +Note: This is similar to [`bind`](#bind) in POSIX using PF_INET ##### Params -- `fd`: [`fd`](#fd) +- `fd`: [`fd`](#fd) File descriptor of the socket to be bind -- `addr`: `Pointer` +- `addr`: `Pointer` Address to bind the socket to ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) --- -#### `sock_listen(fd: fd, backlog: size) -> errno` +#### `listen(fd: fd, backlog: size) -> errno` Listen for connections on a socket -Note: This is similar to `listen` +Note: This is similar to [`listen`](#listen) ##### Params -- `fd`: [`fd`](#fd) +- `fd`: [`fd`](#fd) File descriptor of the socket to be bind -- `backlog`: [`size`](#size) +- `backlog`: [`size`](#size) Maximum size of the queue for pending connections ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) --- -#### `sock_accept(fd: fd) -> (errno, fd)` +#### `accept(fd: fd) -> (errno, fd)` Accept a connection on a socket -Note: This is similar to `accept` +Note: This is similar to [`accept`](#accept) ##### Params -- `fd`: [`fd`](#fd) +- `fd`: [`fd`](#fd) File descriptor of the socket to be bind ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) -- `childfd`: [`fd`](#fd) +- `childfd`: [`fd`](#fd) --- -#### `sock_connect(fd: fd, addr: Pointer) -> errno` +#### `connect(fd: fd, addr: Pointer) -> errno` Initiate a connection on a socket to the specified address -Note: This is similar to `connect` in POSIX +Note: This is similar to [`connect`](#connect) in POSIX ##### Params -- `fd`: [`fd`](#fd) +- `fd`: [`fd`](#fd) Socket descriptor -- `addr`: `Pointer` +- `addr`: `Pointer` Address of the socket to connect to ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) --- -#### `sock_recv(fd: fd, buf: Pointer, buf_len: size, flags: riflags) -> (errno, size)` +#### `recv(fd: fd, buf: Pointer, buf_len: size, flags: riflags) -> (errno, size)` Receive a message from a socket. -Note: This is similar to `recv` in POSIX. +Note: This is similar to [`recv`](#recv) in POSIX. ##### Params -- `fd`: [`fd`](#fd) +- `fd`: [`fd`](#fd) -- `buf`: `Pointer` +- `buf`: `Pointer` The buffer where data will be stored -- `buf_len`: [`size`](#size) +- `buf_len`: [`size`](#size) -- `flags`: [`riflags`](#riflags) +- `flags`: [`riflags`](#riflags) Message flags. ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) -- `bufused`: [`size`](#size) +- `bufused`: [`size`](#size) --- -#### `sock_recv_from(fd: fd, buf: Pointer, buf_len: size, addr_buf: Pointer, addr_buf_len: size, flags: riflags) -> (errno, 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. The address buffer must be at least the size of addr_t. @@ -2548,90 +2512,90 @@ The address buffer must be at least the size of addr_t. Note: This is similar to `recvfrom` in POSIX. ##### Params -- `fd`: [`fd`](#fd) +- `fd`: [`fd`](#fd) -- `buf`: `Pointer` +- `buf`: `Pointer` The buffer where data will be stored -- `buf_len`: [`size`](#size) +- `buf_len`: [`size`](#size) -- `addr_buf`: `Pointer` +- `addr_buf`: `Pointer` The address of origin for the message -- `addr_buf_len`: [`size`](#size) +- `addr_buf_len`: [`size`](#size) -- `flags`: [`riflags`](#riflags) +- `flags`: [`riflags`](#riflags) Message flags. ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) -- `bufused`: [`size`](#size) +- `bufused`: [`size`](#size) --- -#### `sock_send(fd: fd, buf: Pointer, buf_len: size, 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` in POSIX. +Note: This is similar to [`send`](#send) in POSIX. ##### Params -- `fd`: [`fd`](#fd) +- `fd`: [`fd`](#fd) -- `buf`: `Pointer` +- `buf`: `Pointer` The buffer where data will be stored -- `buf_len`: [`size`](#size) +- `buf_len`: [`size`](#size) -- `flags`: [`siflags`](#siflags) +- `flags`: [`siflags`](#siflags) Message flags. ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) -- `bufused`: [`size`](#size) +- `bufused`: [`size`](#size) Number of bytes transmitted. --- -#### `sock_send_to(fd: fd, buf: Pointer, buf_len: size, addr: Pointer, flags: siflags) -> (errno, size)` +#### `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) +- `fd`: [`fd`](#fd) -- `buf`: `Pointer` +- `buf`: `Pointer` The buffer where data will be stored -- `buf_len`: [`size`](#size) +- `buf_len`: [`size`](#size) -- `addr`: `Pointer` +- `addr`: `Pointer` Address of the socket to send message to -- `flags`: [`siflags`](#siflags) +- `flags`: [`siflags`](#siflags) Message flags. ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) -- `bufused`: [`size`](#size) +- `bufused`: [`size`](#size) Number of bytes transmitted. --- -#### `sock_shutdown(fd: fd, how: sdflags) -> errno` +#### `shutdown(fd: fd, how: sdflags) -> errno` Shut down socket send and receive channels. -Note: This is similar to `shutdown` in POSIX. +Note: This is similar to [`shutdown`](#shutdown) in POSIX. ##### Params -- `fd`: [`fd`](#fd) +- `fd`: [`fd`](#fd) -- `how`: [`sdflags`](#sdflags) +- `how`: [`sdflags`](#sdflags) Which channels on the socket to shut down. ##### Results -- `error`: [`errno`](#errno) +- `error`: [`errno`](#errno) 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 6d1f1fca..908ff68a 100644 --- a/phases/ephemeral/witx/wasi_ephemeral_sock.witx +++ b/phases/ephemeral/witx/wasi_ephemeral_sock.witx @@ -11,39 +11,13 @@ ;;; 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 "addr_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) - ) - ;;; 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 "sock_addr_local") + (@interface func (export "addr_local") ;;; Host to resolve (param $fd $fd) ;;; The buffer where IP addresses will be stored @@ -58,7 +32,7 @@ ;;; ;;; When successful, the contents of the output buffer consist of an IP address, ;;; either IP4 or IP6. - (@interface func (export "sock_addr_remote") + (@interface func (export "addr_remote") ;;; Host to resolve (param $fd $fd) ;;; The buffer where IP addresses will be stored @@ -77,7 +51,7 @@ ;;; 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 "sock_open") + (@interface func (export "open") ;;; Address pool file descriptor (param $pool $fd) ;;; Address family @@ -91,7 +65,7 @@ ;;; Close a socket (this is an alias for `fd_close`) ;;; Note: This is similar to `close` in POSIX. - (@interface func (export "sock_close") + (@interface func (export "close") ;;; Socket descriptor (param $fd $fd) (result $error $errno) @@ -99,7 +73,7 @@ ;;; Enable/disable address reuse on a socket ;;; Note: This is similar to `setsockopt` in POSIX for SO_REUSEADDR - (@interface func (export "sock_set_reuse_addr") + (@interface func (export "set_reuse_addr") ;;; Socket descriptor (param $fd $fd) ;;; 1 to enable, 0 to disable @@ -109,7 +83,7 @@ ;;; Retrieve status of address reuse on a socket ;;; Note: This is similar to `getsockopt` in POSIX for SO_REUSEADDR - (@interface func (export "sock_get_reuse_addr") + (@interface func (export "get_reuse_addr") ;;; Socket descriptor (param $fd $fd) (result $error $errno) @@ -118,7 +92,7 @@ ;;; Enable port reuse on a socket ;;; Note: This is similar to `setsockopt` in POSIX for SO_REUSEPORT - (@interface func (export "sock_set_reuse_port") + (@interface func (export "set_reuse_port") ;;; Socket descriptor (param $fd $fd) ;;; 1 to enable, 0 to disable @@ -128,7 +102,7 @@ ;;; Retrieve status of port reuse on a socket ;;; Note: This is similar to `getsockopt` in POSIX for SO_REUSEPORT - (@interface func (export "sock_get_reuse_port") + (@interface func (export "get_reuse_port") ;;; Socket descriptor (param $fd $fd) (result $error $errno) @@ -137,7 +111,7 @@ ;;; Set size of receive buffer ;;; Note: This is similar to `setsockopt` in POSIX for SO_RCVBUF - (@interface func (export "sock_set_recv_buf_size") + (@interface func (export "set_recv_buf_size") ;;; Socket descriptor (param $fd $fd) ;;; Buffer size @@ -147,7 +121,7 @@ ;;; Retrieve the size of the receive buffer ;;; Note: This is similar to `getsockopt` in POSIX for SO_RCVBUF - (@interface func (export "sock_get_recv_buf_size") + (@interface func (export "get_recv_buf_size") ;;; Socket descriptor (param $fd $fd) (result $error $errno) @@ -156,7 +130,7 @@ ;;; Set size of send buffer ;;; Note: This is similar to `setsockopt` in POSIX for SO_SNDBUF - (@interface func (export "sock_set_send_buf_size") + (@interface func (export "set_send_buf_size") ;;; Socket descriptor (param $fd $fd) ;;; Buffer size @@ -166,7 +140,7 @@ ;;; Retrieve the size of the send buffer ;;; Note: This is similar to `getsockopt` in POSIX for SO_SNDBUF - (@interface func (export "sock_get_send_buf_size") + (@interface func (export "get_send_buf_size") ;;; Socket descriptor (param $fd $fd) (result $error $errno) @@ -175,7 +149,7 @@ ;;; Bind a socket ;;; Note: This is similar to `bind` in POSIX using PF_INET - (@interface func (export "sock_bind") + (@interface func (export "bind") ;;; File descriptor of the socket to be bind (param $fd $fd) ;;; Address to bind the socket to @@ -185,7 +159,7 @@ ;;; Listen for connections on a socket ;;; Note: This is similar to `listen` - (@interface func (export "sock_listen") + (@interface func (export "listen") ;;; File descriptor of the socket to be bind (param $fd $fd) ;;; Maximum size of the queue for pending connections @@ -195,7 +169,7 @@ ;;; Accept a connection on a socket ;;; Note: This is similar to `accept` - (@interface func (export "sock_accept") + (@interface func (export "accept") ;;; File descriptor of the socket to be bind (param $fd $fd) (result $error $errno) @@ -204,7 +178,7 @@ ;;; Initiate a connection on a socket to the specified address ;;; Note: This is similar to `connect` in POSIX - (@interface func (export "sock_connect") + (@interface func (export "connect") ;;; Socket descriptor (param $fd $fd) ;;; Address of the socket to connect to @@ -214,7 +188,7 @@ ;;; Receive a message from a socket. ;;; Note: This is similar to `recv` in POSIX. - (@interface func (export "sock_recv") + (@interface func (export "recv") (param $fd $fd) ;;; The buffer where data will be stored (param $buf (@witx pointer u8)) @@ -230,7 +204,7 @@ ;;; The address buffer must be at least the size of addr_t. ;;; ;;; Note: This is similar to `recvfrom` in POSIX. - (@interface func (export "sock_recv_from") + (@interface func (export "recv_from") (param $fd $fd) ;;; The buffer where data will be stored (param $buf (@witx pointer u8)) @@ -246,7 +220,7 @@ ;;; Send a message on a socket. ;;; Note: This is similar to `send` in POSIX. - (@interface func (export "sock_send") + (@interface func (export "send") (param $fd $fd) ;;; The buffer where data will be stored (param $buf (@witx pointer u8)) @@ -260,7 +234,7 @@ ;;; Send a message on a socket. ;;; Note: This is similar to `sendto` in POSIX. - (@interface func (export "sock_send_to") + (@interface func (export "send_to") (param $fd $fd) ;;; The buffer where data will be stored (param $buf (@witx pointer u8)) @@ -276,7 +250,7 @@ ;;; Shut down socket send and receive channels. ;;; Note: This is similar to `shutdown` in POSIX. - (@interface func (export "sock_shutdown") + (@interface func (export "shutdown") (param $fd $fd) ;;; Which channels on the socket to shut down. (param $how $sdflags)