Skip to content

Commit

Permalink
wasi: add stub for sock-accept
Browse files Browse the repository at this point in the history
Refs: nodejs/uvwasi#185

Add stub for sock-accept so that we have stubs for all snapshot 1
methods. Since they changed the spec late in the same it is
awkward but I think it is semver minor at most to add the missing
stub.

Depends on the uvwasi nodejs/uvwasi#185
to land first and to have an updated uvwasi version pulled into
Node.js.

Signed-off-by: Michael Dawson <mdawson@devrus.com>
  • Loading branch information
mhdawson committed Jan 30, 2023
1 parent 9e7093f commit 917512d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/node_wasi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,38 @@ uint32_t WASI::SockShutdown(WASI& wasi,
return uvwasi_sock_shutdown(&wasi.uvw_, sock, how);
}

void WASI::SockAccept(const FunctionCallbackInfo<Value>& args) {
WASI* wasi;
uint32_t sock;
uint32_t flags;
uint32_t fd_ptr;
char* memory;
size_t mem_size;
RETURN_IF_BAD_ARG_COUNT(args, 3);
CHECK_TO_TYPE_OR_RETURN(args, args[0], Uint32, sock);
CHECK_TO_TYPE_OR_RETURN(args, args[1], Uint32, flags);
CHECK_TO_TYPE_OR_RETURN(args, args[2], Uint32, fd_ptr);
ASSIGN_INITIALIZED_OR_RETURN_UNWRAP(&wasi, args.This());
Debug(wasi,
"sock_accept(%d, %d, %d)\n",
sock,
flags,
fd_ptr);
GET_BACKING_STORE_OR_RETURN(wasi, args, &memory, &mem_size);
CHECK_BOUNDS_OR_RETURN(args, mem_size, fd_ptr, UVWASI_SERDES_SIZE_fd_t);

uvwasi_fd_t fd;
uvwasi_errno_t err = uvwasi_sock_accept(&wasi->uvw_,
sock,
flags,
&fd);

if (err == UVWASI_ESUCCESS)
uvwasi_serdes_write_size_t(memory, fd_ptr, fd);

args.GetReturnValue().Set(err);
}

void WASI::_SetMemory(const FunctionCallbackInfo<Value>& args) {
WASI* wasi;
ASSIGN_OR_RETURN_UNWRAP(&wasi, args.This());
Expand Down
1 change: 1 addition & 0 deletions src/node_wasi.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class WASI : public BaseObject,
static uint32_t SockSend(
WASI&, WasmMemory, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t);
static uint32_t SockShutdown(WASI&, WasmMemory, uint32_t, uint32_t);
static void SockAccept(const v8::FunctionCallbackInfo<v8::Value>& args);

static void _SetMemory(const v8::FunctionCallbackInfo<v8::Value>& args);

Expand Down

0 comments on commit 917512d

Please sign in to comment.