Skip to content

Commit

Permalink
add sub for sock_accept
Browse files Browse the repository at this point in the history
Refs: nodejs#183

add the stub for sock_accept so that we have
stubs for all method in the current version of
snapshot 1. sock_accept was added later after
snapshot 1 was first documented.

Does not complete nodejs#183 but is first step.

Signed-off-by: Michael Dawson <mdawson@devrus.com>
  • Loading branch information
mhdawson committed Jan 30, 2023
1 parent 6ad5fc9 commit e62cebe
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions include/uvwasi.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ uvwasi_errno_t uvwasi_sock_send(uvwasi_t* uvwasi,
uvwasi_errno_t uvwasi_sock_shutdown(uvwasi_t* uvwasi,
uvwasi_fd_t sock,
uvwasi_sdflags_t how);
uvwasi_errno_t uvwasi_sock_accept(uvwasi_t* uvwasi,
uvwasi_fd_t sock,
uvwasi_fdflags_t flags,
uvwasi_fd_t* fd);

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions include/wasi_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ typedef uint64_t uvwasi_rights_t; /* Bitfield */
#define UVWASI_RIGHT_PATH_UNLINK_FILE (1 << 26)
#define UVWASI_RIGHT_POLL_FD_READWRITE (1 << 27)
#define UVWASI_RIGHT_SOCK_SHUTDOWN (1 << 28)
#define UVWASI_RIGHT_SOCK_ACCEPT (1 << 29)

typedef uint16_t uvwasi_roflags_t; /* Bitfield */
#define UVWASI_SOCK_RECV_DATA_TRUNCATED (1 << 0)
Expand Down
10 changes: 10 additions & 0 deletions src/uvwasi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2557,6 +2557,16 @@ uvwasi_errno_t uvwasi_sock_shutdown(uvwasi_t* uvwasi,
return UVWASI_ENOTSUP;
}

uvwasi_errno_t uvwasi_sock_accept(uvwasi_t* uvwasi,
uvwasi_fd_t sock,
uvwasi_fdflags_t flags,
uvwasi_fd_t* fd) {
/* TODO(mhdawson): Waiting to implement, pending
https://github.com/WebAssembly/WASI/issues/4 */
UVWASI_DEBUG("uvwasi_sock_accept(uvwasi=%p, unimplemented)\n", uvwasi);
return UVWASI_ENOTSUP;
};


const char* uvwasi_embedder_err_code_to_string(uvwasi_errno_t code) {
switch (code) {
Expand Down
3 changes: 2 additions & 1 deletion src/wasi_rights.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
UVWASI_RIGHT_PATH_UNLINK_FILE | \
UVWASI_RIGHT_PATH_REMOVE_DIRECTORY | \
UVWASI_RIGHT_POLL_FD_READWRITE | \
UVWASI_RIGHT_SOCK_SHUTDOWN)
UVWASI_RIGHT_SOCK_SHUTDOWN | \
UVWASI_RIGHT_SOCK_ACCEPT)

#define UVWASI__RIGHTS_BLOCK_DEVICE_BASE UVWASI__RIGHTS_ALL
#define UVWASI__RIGHTS_BLOCK_DEVICE_INHERITING UVWASI__RIGHTS_ALL
Expand Down
1 change: 1 addition & 0 deletions test/test-enotsup-apis.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ int main(void) {
assert(UVWASI_ENOTSUP == uvwasi_sock_recv(NULL, 0, NULL, 0, 0, NULL, NULL));
assert(UVWASI_ENOTSUP == uvwasi_sock_send(NULL, 0, NULL, 0, 0, NULL));
assert(UVWASI_ENOTSUP == uvwasi_sock_shutdown(NULL, 0, 0));
assert(UVWASI_ENOTSUP == uvwasi_sock_accept(NULL, 0, 0, NULL));

return 0;
}

0 comments on commit e62cebe

Please sign in to comment.