From 917512d972bd565817940a334cea728d026ec2ba Mon Sep 17 00:00:00 2001 From: Michael Dawson Date: Mon, 30 Jan 2023 15:52:09 -0500 Subject: [PATCH] wasi: add stub for sock-accept Refs: https://github.com/nodejs/uvwasi/pull/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 https://github.com/nodejs/uvwasi/pull/185 to land first and to have an updated uvwasi version pulled into Node.js. Signed-off-by: Michael Dawson --- src/node_wasi.cc | 32 ++++++++++++++++++++++++++++++++ src/node_wasi.h | 1 + 2 files changed, 33 insertions(+) diff --git a/src/node_wasi.cc b/src/node_wasi.cc index 5d7f5a4dff50ec6..f22e4adeddc1215 100644 --- a/src/node_wasi.cc +++ b/src/node_wasi.cc @@ -1234,6 +1234,38 @@ uint32_t WASI::SockShutdown(WASI& wasi, return uvwasi_sock_shutdown(&wasi.uvw_, sock, how); } +void WASI::SockAccept(const FunctionCallbackInfo& 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& args) { WASI* wasi; ASSIGN_OR_RETURN_UNWRAP(&wasi, args.This()); diff --git a/src/node_wasi.h b/src/node_wasi.h index a28bdd8ad1bfa64..8f306afd0188d3a 100644 --- a/src/node_wasi.h +++ b/src/node_wasi.h @@ -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& args); static void _SetMemory(const v8::FunctionCallbackInfo& args);