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);
26 fcntl (epoll_fd, F_SETFD, FD_CLOEXEC);
28 /* re-register interest in fds */
29 for (fd = 0; fd < anfdmax; ++fd)
31 epoll_modify (fd, EV_NONE, anfds [fd].wev);
34 static struct epoll_event *events;
37 static void epoll_poll (ev_tstamp timeout)
39 int eventcnt = epoll_wait (epoll_fd, events, eventmax, ceil (timeout * 1000.));
45 for (i = 0; i < eventcnt; ++i)
48 (events [i].events & (EPOLLOUT | EPOLLERR | EPOLLHUP) ? EV_WRITE : 0)
49 | (events [i].events & (EPOLLIN | EPOLLERR | EPOLLHUP) ? EV_READ : 0)
52 /* if the receive array was full, increase its size */
53 if (eventcnt == eventmax)
56 eventmax += eventmax >> 1;
57 events = malloc (sizeof (struct epoll_event) * eventmax);
61 void epoll_init (int flags)
63 epoll_fd = epoll_create (256);
68 fcntl (epoll_fd, F_SETFD, FD_CLOEXEC);
70 ev_method = EVMETHOD_EPOLL;
71 method_fudge = 1e-3; /* needed to compensate for epoll returning early */
72 method_modify = epoll_modify;
73 method_poll = epoll_poll;
75 eventmax = 64; /* intiial number of events receivable per poll */
76 events = malloc (sizeof (struct epoll_event) * eventmax);