From fdb9d0d28d48f80f89d763d5fb6f26a24640b5a4 Mon Sep 17 00:00:00 2001 From: Nathaniel McCallum Date: Tue, 14 Dec 2021 07:11:00 +0000 Subject: [PATCH 1/2] Run documentation generation I will be changing the documents in future commits. This ensures they are up to date before making any changes. Signed-off-by: Nathaniel McCallum --- phases/snapshot/docs.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phases/snapshot/docs.md b/phases/snapshot/docs.md index e91c22c8..44c3c35f 100644 --- a/phases/snapshot/docs.md +++ b/phases/snapshot/docs.md @@ -2011,7 +2011,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) From 71e710bfa88fa460963ad465dcdc548e4542fae2 Mon Sep 17 00:00:00 2001 From: Nathaniel McCallum Date: Thu, 13 Jan 2022 20:57:34 +0000 Subject: [PATCH 2/2] Add sock_accept() This function allows a server to accept incoming connections. A few notes are in order. Although there are legitimate questions about the capabilities model in numerous networking APIs, this particular API is both immensely useful and not a violation of the capabilities model. There is still no way to create an arbitrary socket. The only thing that WASM can do is accept incoming connections on a predefined listening socket. Signed-off-by: Nathaniel McCallum --- phases/snapshot/docs.md | 32 +++++++++++++++++++ phases/snapshot/witx/typenames.witx | 2 ++ .../snapshot/witx/wasi_snapshot_preview1.witx | 11 +++++++ 3 files changed, 45 insertions(+) diff --git a/phases/snapshot/docs.md b/phases/snapshot/docs.md index 44c3c35f..657ce7a6 100644 --- a/phases/snapshot/docs.md +++ b/phases/snapshot/docs.md @@ -450,6 +450,11 @@ The right to invoke [`sock_shutdown`](#sock_shutdown). Bit: 28 +- `sock_accept`: `bool` +The right to invoke [`sock_accept`](#sock_accept). + +Bit: 29 + ## `fd`: `Handle` A file descriptor handle. @@ -2414,6 +2419,33 @@ The buffer to fill with random data. - `err`: [`errno`](#errno) +--- + +#### `sock_accept(fd: fd, flags: fdflags) -> Result` +Accept a new incoming connection. +Note: This is similar to `accept` in POSIX. + +##### Params +- `fd`: [`fd`](#fd) +The listening socket. + +- `flags`: [`fdflags`](#fdflags) +The desired values of the file descriptor flags. + +##### Results +- `error`: `Result` +New socket connection + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok`: [`fd`](#fd) + +- `err`: [`errno`](#errno) + + --- #### `sock_recv(fd: fd, ri_data: iovec_array, ri_flags: riflags) -> Result<(size, roflags), errno>` diff --git a/phases/snapshot/witx/typenames.witx b/phases/snapshot/witx/typenames.witx index 311b4223..893e5b28 100644 --- a/phases/snapshot/witx/typenames.witx +++ b/phases/snapshot/witx/typenames.witx @@ -270,6 +270,8 @@ $poll_fd_readwrite ;;; The right to invoke `sock_shutdown`. $sock_shutdown + ;;; The right to invoke `sock_accept`. + $sock_accept ) ) diff --git a/phases/snapshot/witx/wasi_snapshot_preview1.witx b/phases/snapshot/witx/wasi_snapshot_preview1.witx index efb2c797..100d852b 100644 --- a/phases/snapshot/witx/wasi_snapshot_preview1.witx +++ b/phases/snapshot/witx/wasi_snapshot_preview1.witx @@ -473,6 +473,17 @@ (result $error (expected (error $errno))) ) + ;;; Accept a new incoming connection. + ;;; Note: This is similar to `accept` in POSIX. + (@interface func (export "sock_accept") + ;;; The listening socket. + (param $fd $fd) + ;;; The desired values of the file descriptor flags. + (param $flags $fdflags) + ;;; New socket connection + (result $error (expected $fd (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`.