diff --git a/unix/uxpoll.c b/unix/uxpoll.c index da74ebf9..474926bb 100644 --- a/unix/uxpoll.c +++ b/unix/uxpoll.c @@ -126,29 +126,44 @@ int pollwrap_poll_timeout(pollwrapper *pw, int milliseconds) return poll(pw->fds, pw->nfd, milliseconds); } -int pollwrap_get_fd_events(pollwrapper *pw, int fd) +static void pollwrap_get_fd_events_revents(pollwrapper *pw, int fd, + int *events_p, int *revents_p) { pollwrap_fdtopos *f2p, f2p_find; + int events = 0, revents = 0; assert(fd >= 0); f2p_find.fd = fd; f2p = find234(pw->fdtopos, &f2p_find, NULL); - if (!f2p) - return 0; + if (f2p) { + events = pw->fds[f2p->pos].events; + revents = pw->fds[f2p->pos].revents; + } - return pw->fds[f2p->pos].revents; + if (events_p) + *events_p = events; + if (revents_p) + *revents_p = revents; +} + +int pollwrap_get_fd_events(pollwrapper *pw, int fd) +{ + int revents; + pollwrap_get_fd_events_revents(pw, fd, NULL, &revents); + return revents; } int pollwrap_get_fd_rwx(pollwrapper *pw, int fd) { - int revents = pollwrap_get_fd_events(pw, fd); + int events, revents; + pollwrap_get_fd_events_revents(pw, fd, &events, &revents); int rwx = 0; - if (revents & SELECT_R_OUT) + if ((events & POLLIN) && (revents & SELECT_R_OUT)) rwx |= SELECT_R; - if (revents & SELECT_W_OUT) + if ((events & POLLOUT) && (revents & SELECT_W_OUT)) rwx |= SELECT_W; - if (revents & SELECT_X_OUT) + if ((events & POLLPRI) && (revents & SELECT_X_OUT)) rwx |= SELECT_X; return rwx; }