From 366961a3b6bb7cd2af3b3805b3fb52b26eafc13f Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Thu, 5 Dec 2019 17:49:36 +0900 Subject: [PATCH] libc: implement poll with fswait3 --- libc/poll/poll.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libc/poll/poll.c b/libc/poll/poll.c index 38d16688..c77e7d94 100644 --- a/libc/poll/poll.c +++ b/libc/poll/poll.c @@ -24,6 +24,7 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout) { int fswait_fds[count_pollin]; int fswait_backref[count_pollin]; + int fswait_results[count_pollin]; int j = 0; for (nfds_t i = 0; i < nfds; ++i) { if (fds[i].events & POLLIN) { @@ -33,11 +34,17 @@ int poll(struct pollfd *fds, nfds_t nfds, int timeout) { } } - int ret = fswait2(count_pollin, fswait_fds, timeout); + int ret = fswait3(count_pollin, fswait_fds, timeout, fswait_results); if (ret >= 0 && ret < count_pollin) { - fds[fswait_backref[ret]].revents = POLLIN; - return 1; + int count = 0; + for (int i = 0; i < count_pollin; ++i) { + if (fswait_results[i]) { + fds[fswait_backref[i]].revents = POLLIN; + count++; + } + } + return count; } else if (ret == count_pollin) { return 0; } else {