Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sock_accept() to snapshot1 #458

Merged
merged 2 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion phases/snapshot/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,11 @@ The right to invoke [`sock_shutdown`](#sock_shutdown).

Bit: 28

- <a href="#rights.sock_accept" name="rights.sock_accept"></a> `sock_accept`: `bool`
The right to invoke [`sock_accept`](#sock_accept).

Bit: 29

## <a href="#fd" name="fd"></a> `fd`: `Handle`
A file descriptor handle.

Expand Down Expand Up @@ -2011,7 +2016,7 @@ The path at which to create the directory.

#### <a href="#path_filestat_get" name="path_filestat_get"></a> `path_filestat_get(fd: fd, flags: lookupflags, path: string) -> Result<filestat, errno>`
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
- <a href="#path_filestat_get.fd" name="path_filestat_get.fd"></a> `fd`: [`fd`](#fd)
Expand Down Expand Up @@ -2414,6 +2419,33 @@ The buffer to fill with random data.
- <a href="#random_get.error.err" name="random_get.error.err"></a> `err`: [`errno`](#errno)


---

#### <a href="#sock_accept" name="sock_accept"></a> `sock_accept(fd: fd, flags: fdflags) -> Result<fd, errno>`
Accept a new incoming connection.
Note: This is similar to `accept` in POSIX.

##### Params
- <a href="#sock_accept.fd" name="sock_accept.fd"></a> `fd`: [`fd`](#fd)
The listening socket.

- <a href="#sock_accept.flags" name="sock_accept.flags"></a> `flags`: [`fdflags`](#fdflags)
The desired values of the file descriptor flags.

##### Results
- <a href="#sock_accept.error" name="sock_accept.error"></a> `error`: `Result<fd, errno>`
New socket connection

###### Variant Layout
- size: 8
- align: 4
- tag_size: 4
###### Variant cases
- <a href="#sock_accept.error.ok" name="sock_accept.error.ok"></a> `ok`: [`fd`](#fd)

- <a href="#sock_accept.error.err" name="sock_accept.error.err"></a> `err`: [`errno`](#errno)


---

#### <a href="#sock_recv" name="sock_recv"></a> `sock_recv(fd: fd, ri_data: iovec_array, ri_flags: riflags) -> Result<(size, roflags), errno>`
Expand Down
2 changes: 2 additions & 0 deletions phases/snapshot/witx/typenames.witx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@
$poll_fd_readwrite
;;; The right to invoke `sock_shutdown`.
$sock_shutdown
;;; The right to invoke `sock_accept`.
$sock_accept
)
)

Expand Down
11 changes: 11 additions & 0 deletions phases/snapshot/witx/wasi_snapshot_preview1.witx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the purpose of accept a fdflags value here to have an equivalent to the SOCK_NONBLOCK flag? If so, it'd be good to mention that flag in the comment above, and document that accept doesn't recognize any of the other $fdflags flags.

;;; 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`.
Expand Down