Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b2a80d7

Browse filesBrowse files
mhdawsontargos
authored andcommitted
wasi: add wasi sock_accept stub
Refs: nodejs/uvwasi#185 Add stub for sock_accept so that we have stubs for all of the sock methods in wasi_snapshot_preview1. Its a bit awkward as the method was added after the initial definitial of wasi_snapshot-preview1 but I think it should be semver minor at most to add the method. Depends on nodejs/uvwasi#185 being landed in uvwasi first and an updated version of uvwasi that includes that being pulled into Node.js Signed-off-by: Michael Dawson <mdawson@devrus.com> PR-URL: #46434 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 7ab7f97 commit b2a80d7
Copy full SHA for b2a80d7

File tree

Expand file treeCollapse file tree

5 files changed

+35
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+35
-0
lines changed
Open diff view settings
Collapse file

‎src/node_wasi.cc‎

Copy file name to clipboardExpand all lines: src/node_wasi.cc
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,21 @@ uint32_t WASI::SchedYield(WASI& wasi, WasmMemory) {
11481148
return uvwasi_sched_yield(&wasi.uvw_);
11491149
}
11501150

1151+
uint32_t WASI::SockAccept(WASI& wasi,
1152+
WasmMemory memory,
1153+
uint32_t sock,
1154+
uint32_t flags,
1155+
uint32_t fd_ptr) {
1156+
Debug(wasi, "sock_accept(%d, %d, %d)\n", sock, flags, fd_ptr);
1157+
uvwasi_fd_t fd;
1158+
uvwasi_errno_t err = uvwasi_sock_accept(&wasi.uvw_, sock, flags, &fd);
1159+
1160+
if (err == UVWASI_ESUCCESS)
1161+
uvwasi_serdes_write_size_t(memory.data, fd_ptr, fd);
1162+
1163+
return err;
1164+
}
1165+
11511166
uint32_t WASI::SockRecv(WASI& wasi,
11521167
WasmMemory memory,
11531168
uint32_t sock,
@@ -1303,6 +1318,7 @@ static void InitializePreview1(Local<Object> target,
13031318
V(ProcRaise, "proc_raise")
13041319
V(RandomGet, "random_get")
13051320
V(SchedYield, "sched_yield")
1321+
V(SockAccept, "sock_accept")
13061322
V(SockRecv, "sock_recv")
13071323
V(SockSend, "sock_send")
13081324
V(SockShutdown, "sock_shutdown")
Collapse file

‎src/node_wasi.h‎

Copy file name to clipboardExpand all lines: src/node_wasi.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class WASI : public BaseObject,
131131
static uint32_t ProcRaise(WASI&, WasmMemory, uint32_t);
132132
static uint32_t RandomGet(WASI&, WasmMemory, uint32_t, uint32_t);
133133
static uint32_t SchedYield(WASI&, WasmMemory);
134+
static uint32_t SockAccept(WASI&, WasmMemory, uint32_t, uint32_t, uint32_t);
134135
static uint32_t SockRecv(WASI&,
135136
WasmMemory,
136137
uint32_t,
Collapse file

‎test/wasi/c/sock.c‎

Copy file name to clipboard
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <sys/socket.h>
2+
#include <stddef.h>
3+
#include <errno.h>
4+
#include <assert.h>
5+
#include <stdio.h>
6+
7+
// TODO(mhdawson): Update once sock_accept is implemented in uvwasi
8+
int main(void) {
9+
int fd = 0 ;
10+
socklen_t addrlen = 0;
11+
int flags = 0;
12+
int ret = accept(0, NULL, &addrlen);
13+
assert(ret == -1);
14+
assert(errno == ENOTSUP);
15+
16+
return 0;
17+
}
Collapse file

‎test/wasi/test-wasi.js‎

Copy file name to clipboardExpand all lines: test/wasi/test-wasi.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ if (process.argv[2] === 'wasi-child-default') {
137137
stdout: `hello from input.txt${checkoutEOL}hello from input.txt${checkoutEOL}`,
138138
});
139139
runWASI({ test: 'stat' });
140+
runWASI({ test: 'sock' });
140141
runWASI({ test: 'write_file' });
141142

142143
// Tests that are currently unsupported on Windows.
Collapse file

‎test/wasi/wasm/sock.wasm‎

Copy file name to clipboard
18.6 KB
Binary file not shown.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.