… | |
… | |
37 | static void |
37 | static void |
38 | kqueue_change (EV_P_ int fd, int filter, int flags, int fflags) |
38 | kqueue_change (EV_P_ int fd, int filter, int flags, int fflags) |
39 | { |
39 | { |
40 | struct kevent *ke; |
40 | struct kevent *ke; |
41 | |
41 | |
|
|
42 | ++kqueue_changecnt; |
42 | array_needsize (struct kevent, kqueue_changes, kqueue_changemax, ++kqueue_changecnt, ); |
43 | array_needsize (struct kevent, kqueue_changes, kqueue_changemax, kqueue_changecnt, EMPTY2); |
43 | |
44 | |
44 | ke = &kqueue_changes [kqueue_changecnt - 1]; |
45 | ke = &kqueue_changes [kqueue_changecnt - 1]; |
45 | memset (ke, 0, sizeof (struct kevent)); |
46 | memset (ke, 0, sizeof (struct kevent)); |
46 | ke->ident = fd; |
47 | ke->ident = fd; |
47 | ke->filter = filter; |
48 | ke->filter = filter; |
… | |
… | |
81 | /* need to resize so there is enough space for errors */ |
82 | /* need to resize so there is enough space for errors */ |
82 | if (kqueue_changecnt > kqueue_eventmax) |
83 | if (kqueue_changecnt > kqueue_eventmax) |
83 | { |
84 | { |
84 | ev_free (kqueue_events); |
85 | ev_free (kqueue_events); |
85 | kqueue_eventmax = array_roundsize (struct kevent, kqueue_changecnt); |
86 | kqueue_eventmax = array_roundsize (struct kevent, kqueue_changecnt); |
86 | kqueue_events = ev_malloc (sizeof (struct kevent) * kqueue_eventmax); |
87 | kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax); |
87 | } |
88 | } |
88 | |
89 | |
89 | ts.tv_sec = (time_t)timeout; |
90 | ts.tv_sec = (time_t)timeout; |
90 | ts.tv_nsec = (long)(timeout - (ev_tstamp)ts.tv_sec) * 1e9; |
91 | ts.tv_nsec = (long)((timeout - (ev_tstamp)ts.tv_sec) * 1e9); |
91 | res = kevent (kqueue_fd, kqueue_changes, kqueue_changecnt, kqueue_events, kqueue_eventmax, &ts); |
92 | res = kevent (kqueue_fd, kqueue_changes, kqueue_changecnt, kqueue_events, kqueue_eventmax, &ts); |
92 | kqueue_changecnt = 0; |
93 | kqueue_changecnt = 0; |
93 | |
94 | |
94 | if (res < 0) |
95 | if (res < 0) |
95 | { |
96 | { |
… | |
… | |
145 | |
146 | |
146 | if (expect_false (res == kqueue_eventmax)) |
147 | if (expect_false (res == kqueue_eventmax)) |
147 | { |
148 | { |
148 | ev_free (kqueue_events); |
149 | ev_free (kqueue_events); |
149 | kqueue_eventmax = array_roundsize (struct kevent, kqueue_eventmax << 1); |
150 | kqueue_eventmax = array_roundsize (struct kevent, kqueue_eventmax << 1); |
150 | kqueue_events = ev_malloc (sizeof (struct kevent) * kqueue_eventmax); |
151 | kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax); |
151 | } |
152 | } |
152 | } |
153 | } |
153 | |
154 | |
154 | static int |
155 | static int |
155 | kqueue_init (EV_P_ int flags) |
156 | kqueue_init (EV_P_ int flags) |
… | |
… | |
184 | method_fudge = 1e-3; /* needed to compensate for kevent returning early */ |
185 | method_fudge = 1e-3; /* needed to compensate for kevent returning early */ |
185 | method_modify = kqueue_modify; |
186 | method_modify = kqueue_modify; |
186 | method_poll = kqueue_poll; |
187 | method_poll = kqueue_poll; |
187 | |
188 | |
188 | kqueue_eventmax = 64; /* intiial number of events receivable per poll */ |
189 | kqueue_eventmax = 64; /* intiial number of events receivable per poll */ |
189 | kqueue_events = ev_malloc (sizeof (struct kevent) * kqueue_eventmax); |
190 | kqueue_events = (struct kevent *)ev_malloc (sizeof (struct kevent) * kqueue_eventmax); |
190 | |
191 | |
191 | kqueue_changes = 0; |
192 | kqueue_changes = 0; |
192 | kqueue_changemax = 0; |
193 | kqueue_changemax = 0; |
193 | kqueue_changecnt = 0; |
194 | kqueue_changecnt = 0; |
194 | |
195 | |
195 | return EVMETHOD_KQUEUE; |
196 | return EVBACKEND_KQUEUE; |
196 | } |
197 | } |
197 | |
198 | |
198 | static void |
199 | static void |
199 | kqueue_destroy (EV_P) |
200 | kqueue_destroy (EV_P) |
200 | { |
201 | { |