diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 16:08:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 16:08:03 +0000 |
commit | f1db79e6e5c383cf76f3bf0dd42115d19591a72b (patch) | |
tree | 3f9509008e8a130c45b7e31b1520d66d720493ec /libc-bottom-half/cloudlibc/src/libc/poll/poll.c | |
parent | Adding upstream version 0.0~git20230821.ec4566b. (diff) | |
download | wasi-libc-upstream.tar.xz wasi-libc-upstream.zip |
Adding upstream version 0.0~git20240411.9e8c542.upstream/0.0_git20240411.9e8c542upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libc-bottom-half/cloudlibc/src/libc/poll/poll.c')
-rw-r--r-- | libc-bottom-half/cloudlibc/src/libc/poll/poll.c | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c index cde4e81..0ee1479 100644 --- a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c +++ b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c @@ -7,7 +7,7 @@ #include <poll.h> #include <stdbool.h> -int poll(struct pollfd *fds, size_t nfds, int timeout) { +static int poll_wasip1(struct pollfd *fds, size_t nfds, int timeout) { // Construct events for poll(). size_t maxevents = 2 * nfds + 1; __wasi_subscription_t subscriptions[maxevents]; @@ -127,3 +127,48 @@ int poll(struct pollfd *fds, size_t nfds, int timeout) { } return retval; } + +#ifdef __wasilibc_use_wasip2 +#include <wasi/descriptor_table.h> + +int poll_wasip2(struct pollfd *fds, size_t nfds, int timeout); + +int poll(struct pollfd* fds, nfds_t nfds, int timeout) +{ + bool found_socket = false; + bool found_non_socket = false; + for (size_t i = 0; i < nfds; ++i) { + descriptor_table_entry_t* entry; + if (descriptor_table_get_ref(fds[i].fd, &entry)) { + found_socket = true; + } else { + found_non_socket = true; + } + } + + if (found_socket) { + if (found_non_socket) { + // We currently don't support polling a mix of non-sockets and + // sockets here (though you can do it by using the host APIs + // directly), and we probably won't until we've migrated entirely to + // WASI 0.2. + errno = ENOTSUP; + return -1; + } + + return poll_wasip2(fds, nfds, timeout); + } else if (found_non_socket) { + return poll_wasip1(fds, nfds, timeout); + } else if (timeout >= 0) { + return poll_wasip2(fds, nfds, timeout); + } else { + errno = ENOTSUP; + return -1; + } +} +#else // not __wasilibc_use_wasip2 +int poll(struct pollfd* fds, nfds_t nfds, int timeout) +{ + return poll_wasip1(fds, nfds, timeout); +} +#endif // not __wasilibc_use_wasip2 |