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 epoll_ctl (epoll_fd, mode, fd, &ev);
19 void epoll_postfork_child (void)
23 epoll_fd = epoll_create (256);
24 fcntl (epoll_fd, F_SETFD, FD_CLOEXEC);
26 /* re-register interest in fds */
27 for (fd = 0; fd < anfdmax; ++fd)
29 epoll_modify (fd, EV_NONE, anfds [fd].wev);
32 static struct epoll_event *events;
35 static void epoll_poll (ev_tstamp timeout)
37 int eventcnt = epoll_wait (epoll_fd, events, eventmax, ceil (timeout * 1000.));
43 for (i = 0; i < eventcnt; ++i)
46 (events [i].events & (EPOLLOUT | EPOLLERR | EPOLLHUP) ? EV_WRITE : 0)
47 | (events [i].events & (EPOLLIN | EPOLLERR | EPOLLHUP) ? EV_READ : 0)
50 /* if the receive array was full, increase its size */
51 if (eventcnt == eventmax)
54 eventmax += eventmax >> 1;
55 events = malloc (sizeof (struct epoll_event) * eventmax);
59 void epoll_init (int flags)
61 epoll_fd = epoll_create (256);
66 fcntl (epoll_fd, F_SETFD, FD_CLOEXEC);
68 ev_method = EVMETHOD_EPOLL;
69 method_fudge = 1e-3; /* needed to compensate for epoll returning early */
70 method_modify = epoll_modify;
71 method_poll = epoll_poll;
73 eventmax = 64; /* intiial number of events receivable per poll */
74 events = malloc (sizeof (struct epoll_event) * eventmax);