- if (timeout >= 0) {
- ts.tv_sec = timeout / 1000;
- ts.tv_nsec = (timeout % 1000) * 1000000;
- }
-
- nfds = kevent(poll_fd, NULL, 0, events, ARRAY_SIZE(events), timeout >= 0 ? &ts : NULL);
- for (n = 0; n < nfds; n++) {
- struct uloop_fd_event *cur = &cur_fds[n];
- struct uloop_fd *u = events[n].udata;
- unsigned int ev = 0;
-
- cur->fd = u;
- if (!u)
- continue;
-
- if (events[n].flags & EV_ERROR) {
- u->error = true;
- if (!(u->flags & ULOOP_ERROR_CB))
- uloop_fd_delete(u);
- }
-
- if(events[n].filter == EVFILT_READ)
- ev |= ULOOP_READ;
- else if (events[n].filter == EVFILT_WRITE)
- ev |= ULOOP_WRITE;
-
- if (events[n].flags & EV_EOF)
- u->eof = true;
- else if (!ev)
- cur->fd = NULL;
-
- cur->events = ev;
- if (u->flags & ULOOP_EDGE_DEFER) {
- u->flags &= ~ULOOP_EDGE_DEFER;
- u->flags |= ULOOP_EDGE_TRIGGER;
- register_kevent(u, u->flags);
- }
- }
- return nfds;
-}
-
-#endif
-
-#ifdef USE_EPOLL
-
-/**
- * FIXME: uClibc < 0.9.30.3 does not define EPOLLRDHUP for Linux >= 2.6.17
- */
-#ifndef EPOLLRDHUP
-#define EPOLLRDHUP 0x2000
-#endif
-
-int uloop_init(void)
-{
- if (poll_fd >= 0)