… | |
… | |
40 | ev.data.u64 = fd; /* use u64 to fully initialise the struct, for nicer strace etc. */ |
40 | ev.data.u64 = fd; /* use u64 to fully initialise the struct, for nicer strace etc. */ |
41 | ev.events = |
41 | ev.events = |
42 | (nev & EV_READ ? EPOLLIN : 0) |
42 | (nev & EV_READ ? EPOLLIN : 0) |
43 | | (nev & EV_WRITE ? EPOLLOUT : 0); |
43 | | (nev & EV_WRITE ? EPOLLOUT : 0); |
44 | |
44 | |
45 | if (epoll_ctl (backend_fd, mode, fd, &ev)) |
45 | if (expect_false (epoll_ctl (backend_fd, mode, fd, &ev))) |
46 | if (errno != ENOENT /* on ENOENT the fd went away, so try to do the right thing */ |
46 | if (errno != ENOENT /* on ENOENT the fd went away, so try to do the right thing */ |
47 | || (nev && epoll_ctl (backend_fd, EPOLL_CTL_ADD, fd, &ev))) |
47 | || (nev && epoll_ctl (backend_fd, EPOLL_CTL_ADD, fd, &ev))) |
48 | fd_kill (EV_A_ fd); |
48 | fd_kill (EV_A_ fd); |
49 | } |
49 | } |
50 | |
50 | |
… | |
… | |
52 | epoll_poll (EV_P_ ev_tstamp timeout) |
52 | epoll_poll (EV_P_ ev_tstamp timeout) |
53 | { |
53 | { |
54 | int i; |
54 | int i; |
55 | int eventcnt = epoll_wait (backend_fd, epoll_events, epoll_eventmax, (int)ceil (timeout * 1000.)); |
55 | int eventcnt = epoll_wait (backend_fd, epoll_events, epoll_eventmax, (int)ceil (timeout * 1000.)); |
56 | |
56 | |
57 | if (eventcnt < 0) |
57 | if (expect_false (eventcnt < 0)) |
58 | { |
58 | { |
59 | if (errno != EINTR) |
59 | if (errno != EINTR) |
60 | syserr ("(libev) epoll_wait"); |
60 | syserr ("(libev) epoll_wait"); |
61 | |
61 | |
62 | return; |
62 | return; |
… | |
… | |
87 | if (backend_fd < 0) |
87 | if (backend_fd < 0) |
88 | return 0; |
88 | return 0; |
89 | |
89 | |
90 | fcntl (backend_fd, F_SETFD, FD_CLOEXEC); |
90 | fcntl (backend_fd, F_SETFD, FD_CLOEXEC); |
91 | |
91 | |
92 | backend_fudge = 1e-3; /* needed to compensate for epoll returning early */ |
92 | backend_fudge = 0.; /* kernel sources seem to indicate this to be zero */ |
93 | backend_modify = epoll_modify; |
93 | backend_modify = epoll_modify; |
94 | backend_poll = epoll_poll; |
94 | backend_poll = epoll_poll; |
95 | |
95 | |
96 | epoll_eventmax = 64; /* intiial number of events receivable per poll */ |
96 | epoll_eventmax = 64; /* intiial number of events receivable per poll */ |
97 | epoll_events = (struct epoll_event *)ev_malloc (sizeof (struct epoll_event) * epoll_eventmax); |
97 | epoll_events = (struct epoll_event *)ev_malloc (sizeof (struct epoll_event) * epoll_eventmax); |