3 static int epoll_fd = -1;
6 epoll_modify (int fd, int oev, int nev)
8 int mode = nev ? oev ? EPOLL_CTL_MOD : EPOLL_CTL_ADD : EPOLL_CTL_DEL;
10 struct epoll_event ev;
13 (nev & EV_READ ? EPOLLIN : 0)
14 | (nev & EV_WRITE ? EPOLLOUT : 0);
16 fprintf (stderr, "reify %d,%d,%d m%d (r=%d)\n", fd, oev, nev, mode,//D
17 epoll_ctl (epoll_fd, mode, fd, &ev)
21 void epoll_postfork_child (void)
25 epoll_fd = epoll_create (256);
27 /* re-register interest in fds */
28 for (fd = 0; fd < anfdmax; ++fd)
30 epoll_modify (fd, EV_NONE, anfds [fd].wev);
33 static struct epoll_event *events;
36 static void epoll_poll (ev_tstamp timeout)
38 int eventcnt = epoll_wait (epoll_fd, events, eventmax, ceil (timeout * 1000.));
44 for (i = 0; i < eventcnt; ++i)
47 (events [i].events & (EPOLLOUT | EPOLLERR | EPOLLHUP) ? EV_WRITE : 0)
48 | (events [i].events & (EPOLLIN | EPOLLERR | EPOLLHUP) ? EV_READ : 0)
51 /* if the receive array was full, increase its size */
52 if (eventcnt == eventmax)
55 eventmax += eventmax >> 1;
56 events = malloc (sizeof (struct epoll_event) * eventmax);
60 int epoll_init (int flags)
62 epoll_fd = epoll_create (256);
67 ev_method = EVMETHOD_EPOLL;
68 method_fudge = 1e-3; /* needed to compensate for epoll returning early */
69 method_modify = epoll_modify;
70 method_poll = epoll_poll;
72 eventmax = 64; /* intiial number of events receivable per poll */
73 events = malloc (sizeof (struct epoll_event) * eventmax);