Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions expected/wasm32-wasi/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ _start
a64l
abort
abs
accept
accept4
access
acos
acosf
Expand Down
30 changes: 30 additions & 0 deletions libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/
// SPDX-License-Identifier: BSD-2-Clause

#include <common/errno.h>
#include <sys/socket.h>
#include <assert.h>
#include <wasi/api.h>
#include <errno.h>

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;
}
3 changes: 3 additions & 0 deletions libc-bottom-half/headers/public/__header_sys_socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do these need to be declared here, but not other socket APIs?

It looks like top-half/musl/include/sys/socket.h can be modified instead to declare these maybe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's admittedly confusing, and I forgot to mention it earlier, but even though wasi-libc doesn't use musl's bottom-half implementations, it does use musl's headers.

So the way to fix this is to move this #endif up two lines, to enable musl's accept declaration.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sunfishcode So,Can I go ahead with making this change ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made the Change

#ifdef __cplusplus
}
#endif
Expand Down