X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/499c7e995433fedd0a2333ec6d9bc3768e6224f4..57bdc324ccc888c220f3184c1f6952106316762e:/ev_poll.c?ds=sidebyside diff --git a/ev_poll.c b/ev_poll.c index 1ce41c6..5ad7261 100644 --- a/ev_poll.c +++ b/ev_poll.c @@ -46,26 +46,29 @@ poll_modify (EV_P_ int fd, int oev, int nev) if (oev == nev) return; - array_needsize (pollidxs, pollidxmax, fd + 1, pollidx_init); + array_needsize (int, pollidxs, pollidxmax, fd + 1, pollidx_init); idx = pollidxs [fd]; if (idx < 0) /* need to allocate a new pollfd */ { - idx = pollcnt++; - array_needsize (polls, pollmax, 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; } @@ -118,3 +121,4 @@ poll_destroy (EV_P) ev_free (pollidxs); ev_free (polls); } +