Skip to content

Commit 0ba0c5e

Browse files
authored
Add sock_accept() to snapshot1 (#458)
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 <[email protected]>
1 parent 3423c9c commit 0ba0c5e

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

phases/snapshot/docs.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,11 @@ The right to invoke [`sock_shutdown`](#sock_shutdown).
450450

451451
Bit: 28
452452

453+
- <a href="#rights.sock_accept" name="rights.sock_accept"></a> `sock_accept`: `bool`
454+
The right to invoke [`sock_accept`](#sock_accept).
455+
456+
Bit: 29
457+
453458
## <a href="#fd" name="fd"></a> `fd`: `Handle`
454459
A file descriptor handle.
455460

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

20122017
#### <a href="#path_filestat_get" name="path_filestat_get"></a> `path_filestat_get(fd: fd, flags: lookupflags, path: string) -> Result<filestat, errno>`
20132018
Return the attributes of a file or directory.
2014-
Note: This is similar to `fstatat` in POSIX.
2019+
Note: This is similar to `stat` in POSIX.
20152020

20162021
##### Params
20172022
- <a href="#path_filestat_get.fd" name="path_filestat_get.fd"></a> `fd`: [`fd`](#fd)
@@ -2414,6 +2419,33 @@ The buffer to fill with random data.
24142419
- <a href="#random_get.error.err" name="random_get.error.err"></a> `err`: [`errno`](#errno)
24152420

24162421

2422+
---
2423+
2424+
#### <a href="#sock_accept" name="sock_accept"></a> `sock_accept(fd: fd, flags: fdflags) -> Result<fd, errno>`
2425+
Accept a new incoming connection.
2426+
Note: This is similar to `accept` in POSIX.
2427+
2428+
##### Params
2429+
- <a href="#sock_accept.fd" name="sock_accept.fd"></a> `fd`: [`fd`](#fd)
2430+
The listening socket.
2431+
2432+
- <a href="#sock_accept.flags" name="sock_accept.flags"></a> `flags`: [`fdflags`](#fdflags)
2433+
The desired values of the file descriptor flags.
2434+
2435+
##### Results
2436+
- <a href="#sock_accept.error" name="sock_accept.error"></a> `error`: `Result<fd, errno>`
2437+
New socket connection
2438+
2439+
###### Variant Layout
2440+
- size: 8
2441+
- align: 4
2442+
- tag_size: 4
2443+
###### Variant cases
2444+
- <a href="#sock_accept.error.ok" name="sock_accept.error.ok"></a> `ok`: [`fd`](#fd)
2445+
2446+
- <a href="#sock_accept.error.err" name="sock_accept.error.err"></a> `err`: [`errno`](#errno)
2447+
2448+
24172449
---
24182450

24192451
#### <a href="#sock_recv" name="sock_recv"></a> `sock_recv(fd: fd, ri_data: iovec_array, ri_flags: riflags) -> Result<(size, roflags), errno>`

phases/snapshot/witx/typenames.witx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@
270270
$poll_fd_readwrite
271271
;;; The right to invoke `sock_shutdown`.
272272
$sock_shutdown
273+
;;; The right to invoke `sock_accept`.
274+
$sock_accept
273275
)
274276
)
275277

phases/snapshot/witx/wasi_snapshot_preview1.witx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,17 @@
473473
(result $error (expected (error $errno)))
474474
)
475475

476+
;;; Accept a new incoming connection.
477+
;;; Note: This is similar to `accept` in POSIX.
478+
(@interface func (export "sock_accept")
479+
;;; The listening socket.
480+
(param $fd $fd)
481+
;;; The desired values of the file descriptor flags.
482+
(param $flags $fdflags)
483+
;;; New socket connection
484+
(result $error (expected $fd (error $errno)))
485+
)
486+
476487
;;; Receive a message from a socket.
477488
;;; Note: This is similar to `recv` in POSIX, though it also supports reading
478489
;;; the data into multiple buffers in the manner of `readv`.

0 commit comments

Comments
 (0)