-
Notifications
You must be signed in to change notification settings - Fork 203
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
polling on mix of libc-posix socket/file descriptors with non-libc WASI pollable handles #542
Comments
Out of the four options, 1 and 2 seem the best to me.
Note that one libc socket can map to anywhere from 0 to 3 pollable resources depending on its state. With the proposed function signature the user can't know which pollable relates to which aspect of the socket.
POSIX |
After discussing with @sunfishcode we came up with another alternative solution: int32_t get_wasip2_input_stream(int fd); // wasi:io/[email protected]
int32_t get_wasip2_output_stream(int fd); // wasi:io/[email protected]
int32_t get_wasip2_filesystem_descriptor(int fd); // wasi:filesystem/[email protected]
int32_t get_wasip2_tcp_socket(int fd); // wasi:sockets/[email protected]
int32_t get_wasip2_udp_socket(int fd); // wasi:sockets/[email protected]
// etc.. The consumer is in charge of getting the pollables from them. These come with some implicit assumptions that should be documented:
|
If WASPp3 will call back on promises instead of central polling. And if that lands in few months, I'm happy to wait for that and drop this issue. I'm not 100% clear about WASIp3 callbacks from streams. I'm worried about performance.
|
Also the way how we hide those promises/streams and callback behind |
If the As usual, we'll want to benchmark and optimize as necessary if we do discover bottlenecks.
We will create a new task each time an async host function is unable to complete immediately, yes.
I guess that depends on whether the host implementation of TCP streams buffers output (either in user space or at the kernel level). |
With the exception of |
Luke has not yet written down a spec for |
dotnet |
Sure, but p3 tasks might not map one-to-one with .NET |
@dicej Okay! It doesn't really matter for this issue. Was just curious. |
Right, the current proposal (which I'm trying to finish up and post) has:
where the |
This implementation currently uses a mix of POSIX-style APIs (provided by `wasi-libc` via the `libc` crate) and WASIp2-native APIs (provided by the `wasi` crate). Alternatively, we could implement `Selector` using only POSIX APIs, e.g. `poll(2)`. However, that would add an extra layer of abstraction to support and debug, as well as make it impossible to support polling `wasi:io/poll/pollable` objects which cannot be represented as POSIX file descriptors (e.g. timer events, DNS queries, HTTP requests, etc.). Another approach would be to use _only_ the WASIp2 APIs and bypass `wasi-libc` entirely. However, that would break interoperability with both Rust `std` and e.g. C libraries which expect to work with file descriptors. Since `wasi-libc` does not yet provide a public API for converting between file descriptors and WASIp2 resource handles, we currently use a non-public API (see the `netc` module below) to do so. Once WebAssembly/wasi-libc#542 is addressed, we'll be able to switch to a public API. I've tested this end-to-end using https://github.com/dicej/wasi-sockets-tests, which includes smoke tests for `mio`, `tokio`, `tokio-postgres`, etc. Signed-off-by: Joel Dice <[email protected]>
In context of dotnet sockets I would like to be able to
wasi:poll_poll
on mix of handleswasi:http
The motivation to do it on single "system" call is to
select
/poll
orpoll_poll
separately, we would get blocked only on part of pollablesAt the moment, we can hack it via using
libc
internaldescriptor_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
void wasi_poll_plus_fd(poll_list_borrow_pollable_t *in, list_pollfd_t *in, wasip2_list_u32_t *ret)
pollfd
structvoid wasi_poll_plus_fd(int *pollables, int pollables_count, struct pollfd *fds, int fds_count, int **ret, int *ret_count)
fds
to list of pollablesvoid socket_fds_to_wasi_pollables(struct pollfd *fds, int fds_count, int **pollables, int pollables_count)
wasi:poll_poll
libc
file descriptor by registering external pollablepoll()
API on any pollable (clock) feels confusing to meRelevant code, possibly to be refactored and reused for above.
wasi-libc/libc-bottom-half/sources/poll-wasip2.c
Lines 27 to 151 in 7d4d3b8
cc @badeend
The text was updated successfully, but these errors were encountered: