… | |
… | |
49 | } |
49 | } |
50 | |
50 | |
51 | static void |
51 | static void |
52 | epoll_poll (EV_P_ ev_tstamp timeout) |
52 | epoll_poll (EV_P_ ev_tstamp timeout) |
53 | { |
53 | { |
|
|
54 | int i; |
54 | int eventcnt = epoll_wait (epoll_fd, epoll_events, epoll_eventmax, ceil (timeout * 1000.)); |
55 | int eventcnt = epoll_wait (epoll_fd, epoll_events, epoll_eventmax, ceil (timeout * 1000.)); |
55 | int i; |
|
|
56 | |
56 | |
57 | if (eventcnt < 0) |
57 | if (eventcnt < 0) |
|
|
58 | { |
|
|
59 | if (errno != EINTR) |
|
|
60 | syserr (); |
|
|
61 | |
58 | return; |
62 | return; |
|
|
63 | } |
59 | |
64 | |
60 | for (i = 0; i < eventcnt; ++i) |
65 | for (i = 0; i < eventcnt; ++i) |
61 | fd_event ( |
66 | fd_event ( |
62 | EV_A_ |
67 | EV_A_ |
63 | epoll_events [i].data.u64, |
68 | epoll_events [i].data.u64, |
… | |
… | |
66 | ); |
71 | ); |
67 | |
72 | |
68 | /* if the receive array was full, increase its size */ |
73 | /* if the receive array was full, increase its size */ |
69 | if (expect_false (eventcnt == epoll_eventmax)) |
74 | if (expect_false (eventcnt == epoll_eventmax)) |
70 | { |
75 | { |
71 | free (epoll_events); |
76 | ev_free (epoll_events); |
72 | epoll_eventmax = array_roundsize (epoll_events, epoll_eventmax << 1); |
77 | epoll_eventmax = array_roundsize (epoll_events, epoll_eventmax << 1); |
73 | epoll_events = malloc (sizeof (struct epoll_event) * epoll_eventmax); |
78 | epoll_events = ev_malloc (sizeof (struct epoll_event) * epoll_eventmax); |
74 | } |
79 | } |
75 | } |
80 | } |
76 | |
81 | |
77 | static int |
82 | static int |
78 | epoll_init (EV_P_ int flags) |
83 | epoll_init (EV_P_ int flags) |
… | |
… | |
87 | method_fudge = 1e-3; /* needed to compensate for epoll returning early */ |
92 | method_fudge = 1e-3; /* needed to compensate for epoll returning early */ |
88 | method_modify = epoll_modify; |
93 | method_modify = epoll_modify; |
89 | method_poll = epoll_poll; |
94 | method_poll = epoll_poll; |
90 | |
95 | |
91 | epoll_eventmax = 64; /* intiial number of events receivable per poll */ |
96 | epoll_eventmax = 64; /* intiial number of events receivable per poll */ |
92 | epoll_events = malloc (sizeof (struct epoll_event) * epoll_eventmax); |
97 | epoll_events = ev_malloc (sizeof (struct epoll_event) * epoll_eventmax); |
93 | |
98 | |
94 | return EVMETHOD_EPOLL; |
99 | return EVMETHOD_EPOLL; |
95 | } |
100 | } |
96 | |
101 | |
97 | static void |
102 | static void |
98 | epoll_destroy (EV_P) |
103 | epoll_destroy (EV_P) |
99 | { |
104 | { |
100 | close (epoll_fd); |
105 | close (epoll_fd); |
101 | |
106 | |
102 | free (epoll_events); |
107 | ev_free (epoll_events); |
103 | } |
108 | } |
104 | |
109 | |
105 | static void |
110 | static void |
106 | epoll_fork (EV_P) |
111 | epoll_fork (EV_P) |
107 | { |
112 | { |