WebAssembly / WebAssembly/wasi-libc
polling on mix of libc-posix socket/file descriptors with non-libc WASI pollable handles
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 1k
- Forks
- 251
- Avg merge
- 7h 15m
- Merged PRs (30d)
- 3
Description
In context of dotnet sockets I would like to be able to wasi:poll_poll on mix of handles
- which were created by consuming other WASI APIs, like
wasi:http - and file handles obtained by using libc sockets APIs
The motivation to do it on single "system" call is to
- be able to make progress on events from HTTP while socket is not ready and vice versa
- if we called each
select/pollorpoll_pollseparately, we would get blocked only on part of pollables
- if we called each
- to be able to block (stop spinning) if there are no I/O events (and no CPU bound jobs)
At the moment, we can hack it via using libc internal descriptor_table_get_ref and it's data structures to obtain underlying pollables.
@dicej made similar hack for mio
But it's fragile and bad practice.
I can see few possible solutions
- expose libc function accepting both lists of resources
void wasi_poll_plus_fd(poll_list_borrow_pollable_t *in, list_pollfd_t *in, wasip2_list_u32_t *ret)- this is with wit-bindgen generated C structures on APIs and with list of
pollfdstruct
- we can try simpler C types, something like
void wasi_poll_plus_fd(int *pollables, int pollables_count, struct pollfd *fds, int fds_count, int **ret, int *ret_count)
- or we can expose just the mapping from
fdsto list of pollablesvoid socket_fds_to_wasi_pollables(struct pollfd *fds, int fds_count, int **pollables, int pollables_count)- this would have to be called before each call to
wasi:poll_poll
- create
libcfile descriptor by registering external pollable- this would have to be un-registered later
- calling socket oriented
poll()API on any pollable (clock) feels confusing to me
Relevant code, possibly to be refactored and reused for above.
https://github.com/WebAssembly/wasi-libc/blob/7d4d3b83fc66c79b3faa5989e67ed2d1042dacaf/libc-bottom-half/sources/poll-wasip2.c#L27-L151
cc @badeend
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading libc-bottom-half/sources/poll-wasip2.c, especially lines 27-151, and review the linked dotnet sockets and mio context. Compare the proposed approaches for combining libc file descriptors with WASI pollables; done means an agreed, supported API design and implementation path rather than reliance on libc internals.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- api, operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100