Skip to content

Conversation

haraldh
Copy link
Contributor

@haraldh haraldh commented May 2, 2022

Since the socket address of the accepted socket is unknown,
all bytes are set to zero and the length is truncated to the size
of the generic struct sockaddr.

Fixes: #284
Supersedes: #286

Signed-off-by: Harald Hoyer [email protected]

@haraldh
Copy link
Contributor Author

haraldh commented May 2, 2022

Side note: while writing test code, I encountered:

In file included from main.c:4:
In file included from wasi-libc/sysroot/include/sys/socket.h:5:
In file included from wasi-libc/sysroot/include/__header_sys_socket.h:5:
wasi-libc/sysroot/include/__struct_sockaddr.h:10:14: error: use of undeclared identifier 'max_align_t'
    _Alignas(max_align_t) sa_family_t sa_family;

I hope, this is just me using wasi-sdk-14.0 mixed with this HEAD branch's sysroot

@npmccallum
Copy link

@sunfishcode This is the feature I mentioned on the phone. We should consider this a blocker before starting the wit-bindgen work.

Copy link
Member

@sunfishcode sunfishcode left a comment

Choose a reason for hiding this comment

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

Overall looks good!

When adding new files, such as this accept.c, we should add them in libc-bottom-half/sources, since they aren't derived from cloudlibc. See below for how to resolve the common/errno.h header:

Since the socket address of the accepted socket is unknown,
all bytes are set to zero and the length is truncated to the size
of the generic `struct sockaddr`.

Signed-off-by: Harald Hoyer <[email protected]>
@sunfishcode
Copy link
Member

Looks good!

int accept4(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen, int flags) {
int ret = -1;

if (flags & ~(SOCK_NONBLOCK | SOCK_CLOEXEC)) {

Choose a reason for hiding this comment

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

I suppose the rationale for validating, but dropping the only flag besides nonblock is because it isn't in wasi, right? https://github.com/WebAssembly/WASI/blob/main/phases/snapshot/docs.md#fdflags cc @deadprogram who's implementing tinygo tinygo-org/tinygo#2748 🎖️

Choose a reason for hiding this comment

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

sorry tagged wrong person meant @rvolosatovs 😊

Copy link
Contributor

@rvolosatovs rvolosatovs Sep 26, 2022

Choose a reason for hiding this comment

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

Yes, this behavior is not relevant for the TinyGo implementation, since this is a wrapper for sock_accept, whereas in the TinyGo PR we call it directly via WASI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for accept{,4}

5 participants