X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/85e9d898522a460b8dcf57f1781f6acc3d2f3ee5..6778edc72c8101697c478c40f104fe75c97e336e:/ev_poll.c diff --git a/ev_poll.c b/ev_poll.c index de516d7..d0b7299 100644 --- a/ev_poll.c +++ b/ev_poll.c @@ -52,20 +52,23 @@ poll_modify (EV_P_ int fd, int oev, int nev) if (idx < 0) /* need to allocate a new pollfd */ { - idx = pollcnt++; + pollidxs [fd] = idx = pollcnt++; array_needsize (struct pollfd, polls, pollmax, pollcnt, ); polls [idx].fd = fd; } + assert (polls [idx].fd == fd); + if (nev) polls [idx].events = (nev & EV_READ ? POLLIN : 0) | (nev & EV_WRITE ? POLLOUT : 0); else /* remove pollfd */ { - if (idx < pollcnt--) + pollidxs [fd] = -1; + + if (idx < --pollcnt) { - pollidxs [fd] = -1; polls [idx] = polls [pollcnt]; pollidxs [polls [idx].fd] = idx; } @@ -76,7 +79,7 @@ static void poll_poll (EV_P_ ev_tstamp timeout) { int i; - int res = poll (polls, pollcnt, ceil (timeout * 1000.)); + int res = poll (polls, pollcnt, (int)ceil (timeout * 1000.)); if (res < 0) {