… | |
… | |
60 | } |
60 | } |
61 | |
61 | |
62 | static void |
62 | static void |
63 | epoll_poll (EV_P_ ev_tstamp timeout) |
63 | epoll_poll (EV_P_ ev_tstamp timeout) |
64 | { |
64 | { |
65 | int eventcnt = epoll_wait (epoll_fd, events, eventmax, ceil (timeout * 1000.)); |
65 | int eventcnt = epoll_wait (epoll_fd, epoll_events, epoll_eventmax, ceil (timeout * 1000.)); |
66 | int i; |
66 | int i; |
67 | |
67 | |
68 | if (eventcnt < 0) |
68 | if (eventcnt < 0) |
69 | return; |
69 | return; |
70 | |
70 | |
71 | for (i = 0; i < eventcnt; ++i) |
71 | for (i = 0; i < eventcnt; ++i) |
72 | fd_event ( |
72 | fd_event ( |
73 | EV_A_ |
73 | EV_A_ |
74 | events [i].data.u64, |
74 | epoll_events [i].data.u64, |
75 | (events [i].events & (EPOLLOUT | EPOLLERR | EPOLLHUP) ? EV_WRITE : 0) |
75 | (epoll_events [i].events & (EPOLLOUT | EPOLLERR | EPOLLHUP) ? EV_WRITE : 0) |
76 | | (events [i].events & (EPOLLIN | EPOLLERR | EPOLLHUP) ? EV_READ : 0) |
76 | | (epoll_events [i].events & (EPOLLIN | EPOLLERR | EPOLLHUP) ? EV_READ : 0) |
77 | ); |
77 | ); |
78 | |
78 | |
79 | /* if the receive array was full, increase its size */ |
79 | /* if the receive array was full, increase its size */ |
80 | if (expect_false (eventcnt == eventmax)) |
80 | if (expect_false (eventcnt == epoll_eventmax)) |
81 | { |
81 | { |
82 | free (events); |
82 | free (epoll_events); |
83 | eventmax = array_roundsize (events, eventmax << 1); |
83 | epoll_eventmax = array_roundsize (epoll_events, epoll_eventmax << 1); |
84 | events = malloc (sizeof (struct epoll_event) * eventmax); |
84 | epoll_events = malloc (sizeof (struct epoll_event) * epoll_eventmax); |
85 | } |
85 | } |
86 | } |
86 | } |
87 | |
87 | |
88 | static int |
88 | static int |
89 | epoll_init (EV_P_ int flags) |
89 | epoll_init (EV_P_ int flags) |
… | |
… | |
97 | |
97 | |
98 | method_fudge = 1e-3; /* needed to compensate for epoll returning early */ |
98 | method_fudge = 1e-3; /* needed to compensate for epoll returning early */ |
99 | method_modify = epoll_modify; |
99 | method_modify = epoll_modify; |
100 | method_poll = epoll_poll; |
100 | method_poll = epoll_poll; |
101 | |
101 | |
102 | eventmax = 64; /* intiial number of events receivable per poll */ |
102 | epoll_eventmax = 64; /* intiial number of events receivable per poll */ |
103 | events = malloc (sizeof (struct epoll_event) * eventmax); |
103 | epoll_events = malloc (sizeof (struct epoll_event) * epoll_eventmax); |
104 | |
104 | |
105 | return EVMETHOD_EPOLL; |
105 | return EVMETHOD_EPOLL; |
106 | } |
106 | } |
107 | |
107 | |