Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is set-listen-backlog-size a function? #34

Closed
sunfishcode opened this issue Apr 6, 2023 · 2 comments
Closed

Why is set-listen-backlog-size a function? #34

sunfishcode opened this issue Apr 6, 2023 · 2 comments

Comments

@sunfishcode
Copy link
Member

If I understand correctly, set-listen-backlog-size corresponds to the backlog parameter in the listen function in POSIX. I'm curious why it's a function here instead of being a listen parameter.

@badeend
Copy link
Collaborator

badeend commented Apr 10, 2023

Although not part of the official POSIX documentation, many implementations allow listen to be called multiple times:

  • The first invocation performs the actual listen and sets the initial backlog size.
  • Any future invocation just updates the backlog size.

Splitting out these concerns into distinct functions simplifies the WASI interface.

  • tcp-socket::listen performs the actual listener transition, permission checks, etc. Additionally:
    • is async
    • can be called exactly once (successfully)
    • can potentially return an "accept stream" in the future.
  • tcp-socket::set-listen-backlog-size behaves just like any other socket option (which it effectively is, in my mind)
    • is sync
    • can be called multiple times
    • on non-listening sockets, stashes the value on the internal socket instance, to be passed on to the native listen call part of tcp-socket::listen
    • on already listening socket, calls out to the native listen

@sunfishcode
Copy link
Member Author

Cool, thanks!

badeend added a commit to badeend/wasi-sockets that referenced this issue Sep 10, 2023
- Document reasoning behind `listen-backlog-size` in the repository itself. As opposed to just in issue WebAssembly#34
- Change type from u64 to u32, since that's what all OS'es use.
- Add getter. This shouldn't require any additional overhead from implementations, because they already need to keep track of the value (see README). Also, there is precedent for it (SO_LISTENQLIMIT)
badeend added a commit to badeend/wasi-sockets that referenced this issue Sep 10, 2023
- Document reasoning behind `listen-backlog-size` in the repository itself. As opposed to just in issue WebAssembly#34
- Change type from u64 to u32, since that's what all OS'es use.
- Add getter for symmetry with other socket options. This shouldn't require any additional overhead from implementations, because they already need to somehow keep track of the value (see README). Also, there is precedent for it (SO_LISTENQLIMIT)
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

No branches or pull requests

2 participants