diff --git a/expected/wasm32-wasi/defined-symbols.txt b/expected/wasm32-wasi/defined-symbols.txt index fb7234a02..a0d70666e 100644 --- a/expected/wasm32-wasi/defined-symbols.txt +++ b/expected/wasm32-wasi/defined-symbols.txt @@ -363,6 +363,8 @@ _start a64l abort abs +accept +accept4 access acos acosf diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c new file mode 100644 index 000000000..b62c04c22 --- /dev/null +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c @@ -0,0 +1,30 @@ +// Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/ +// SPDX-License-Identifier: BSD-2-Clause + +#include +#include +#include +#include +#include + +int accept(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen) { + int ret = -1; + __wasi_errno_t error = __wasi_sock_accept(socket, 0, &ret); + + if (error != 0) { + errno = errno_fixup_socket(socket, error); + return -1; + } + return ret; +} + +int accept4(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen, int flags) { + int ret = -1; + __wasi_errno_t error = __wasi_sock_accept(socket, flags, &ret); + + if (error != 0) { + errno = errno_fixup_socket(socket, error); + return -1; + } + return ret; +} diff --git a/libc-bottom-half/headers/public/__header_sys_socket.h b/libc-bottom-half/headers/public/__header_sys_socket.h index 9fa8684f8..e1be80ca4 100644 --- a/libc-bottom-half/headers/public/__header_sys_socket.h +++ b/libc-bottom-half/headers/public/__header_sys_socket.h @@ -34,6 +34,9 @@ extern "C" { #endif +int accept(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen); +int accept4(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen, int flags); + #ifdef __cplusplus } #endif diff --git a/libc-top-half/musl/include/sys/socket.h b/libc-top-half/musl/include/sys/socket.h index cea24cfd4..4cef3cf0f 100644 --- a/libc-top-half/musl/include/sys/socket.h +++ b/libc-top-half/musl/include/sys/socket.h @@ -404,9 +404,9 @@ int shutdown (int, int); int bind (int, const struct sockaddr *, socklen_t); int connect (int, const struct sockaddr *, socklen_t); int listen (int, int); +#endif int accept (int, struct sockaddr *__restrict, socklen_t *__restrict); int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int); -#endif #ifdef __wasilibc_unmodified_upstream /* WASI has no getsockname/getpeername */ int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict);