… | |
… | |
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | */ |
30 | */ |
31 | |
31 | |
32 | #include <stddef.h> |
32 | #include <stddef.h> |
33 | #include <stdlib.h> |
33 | #include <stdlib.h> |
34 | #include <sys/time.h> |
|
|
35 | #include <assert.h> |
34 | #include <assert.h> |
|
|
35 | |
|
|
36 | #ifndef WIN32 |
|
|
37 | # include <sys/time.h> |
|
|
38 | #endif |
36 | |
39 | |
37 | #include "ev.h" |
40 | #include "ev.h" |
38 | #include "event.h" |
41 | #include "event.h" |
39 | |
42 | |
40 | #if EV_MULTIPLICITY |
43 | #if EV_MULTIPLICITY |
… | |
… | |
89 | else |
92 | else |
90 | x_cur = (struct event_base *)ev_default_loop (EVMETHOD_AUTO); |
93 | x_cur = (struct event_base *)ev_default_loop (EVMETHOD_AUTO); |
91 | #else |
94 | #else |
92 | assert (("multiple event bases not supported when not compiled with EV_MULTIPLICITY", !x_cur)); |
95 | assert (("multiple event bases not supported when not compiled with EV_MULTIPLICITY", !x_cur)); |
93 | |
96 | |
94 | x_cur = (struct event_base *)ev_default_loop (EVMETHOD_AUTO); |
97 | x_cur = (struct event_base *)(long)ev_default_loop (EVMETHOD_AUTO); |
95 | #endif |
98 | #endif |
96 | |
99 | |
97 | return x_cur; |
100 | return x_cur; |
98 | } |
101 | } |
99 | |
102 | |
… | |
… | |
223 | { |
226 | { |
224 | /* sig */ |
227 | /* sig */ |
225 | if (ev_is_active (&ev->iosig.sig)) |
228 | if (ev_is_active (&ev->iosig.sig)) |
226 | ev_signal_stop (EV_A_ &ev->iosig.sig); |
229 | ev_signal_stop (EV_A_ &ev->iosig.sig); |
227 | } |
230 | } |
228 | else |
231 | else if (ev->ev_events & (EV_READ | EV_WRITE)) |
229 | { |
232 | { |
230 | /* io */ |
233 | /* io */ |
231 | if (ev_is_active (&ev->iosig.io)) |
234 | if (ev_is_active (&ev->iosig.io)) |
232 | ev_io_stop (EV_A_ &ev->iosig.io); |
235 | ev_io_stop (EV_A_ &ev->iosig.io); |
233 | } |
236 | } |
… | |
… | |
238 | return 0; |
241 | return 0; |
239 | } |
242 | } |
240 | |
243 | |
241 | int event_pending (struct event *ev, short events, struct timeval *tv) |
244 | int event_pending (struct event *ev, short events, struct timeval *tv) |
242 | { |
245 | { |
|
|
246 | short revents = 0; |
243 | dLOOPev; |
247 | dLOOPev; |
244 | |
248 | |
245 | short revents = 0; |
|
|
246 | |
249 | |
247 | if (ev->ev_events & EV_SIGNAL) |
250 | if (ev->ev_events & EV_SIGNAL) |
248 | { |
251 | { |
249 | /* sig */ |
252 | /* sig */ |
250 | if (ev_is_active (&ev->iosig.sig) || ev_is_pending (&ev->iosig.sig)) |
253 | if (ev_is_active (&ev->iosig.sig) || ev_is_pending (&ev->iosig.sig)) |
251 | revents |= EV_SIGNAL; |
254 | revents |= EV_SIGNAL; |
252 | } |
255 | } |
253 | else |
256 | else if (ev->ev_events & (EV_READ | EV_WRITE)) |
254 | { |
257 | { |
255 | /* io */ |
258 | /* io */ |
256 | if (ev_is_active (&ev->iosig.io) || ev_is_pending (&ev->iosig.io)) |
259 | if (ev_is_active (&ev->iosig.io) || ev_is_pending (&ev->iosig.io)) |
257 | revents |= ev->ev_events & (EV_READ | EV_WRITE); |
260 | revents |= ev->ev_events & (EV_READ | EV_WRITE); |
258 | } |
261 | } |
… | |
… | |
309 | ev_unloop (EV_A_ EVUNLOOP_ONCE); |
312 | ev_unloop (EV_A_ EVUNLOOP_ONCE); |
310 | } |
313 | } |
311 | |
314 | |
312 | int event_base_loopexit (struct event_base *base, struct timeval *tv) |
315 | int event_base_loopexit (struct event_base *base, struct timeval *tv) |
313 | { |
316 | { |
314 | dLOOPbase; |
|
|
315 | ev_tstamp after = tv_get (tv); |
317 | ev_tstamp after = tv_get (tv); |
|
|
318 | dLOOPbase; |
316 | |
319 | |
317 | ev_once (EV_A_ -1, 0, after >= 0. ? after : 0., x_loopexit_cb, (void *)base); |
320 | ev_once (EV_A_ -1, 0, after >= 0. ? after : 0., x_loopexit_cb, (void *)base); |
318 | |
321 | |
319 | return -1; |
322 | return -1; |
320 | } |
323 | } |
… | |
… | |
335 | free (once); |
338 | free (once); |
336 | } |
339 | } |
337 | |
340 | |
338 | int event_base_once (struct event_base *base, int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv) |
341 | int event_base_once (struct event_base *base, int fd, short events, void (*cb)(int, short, void *), void *arg, struct timeval *tv) |
339 | { |
342 | { |
340 | dLOOPbase; |
|
|
341 | struct x_once *once = malloc (sizeof (struct x_once)); |
343 | struct x_once *once = malloc (sizeof (struct x_once)); |
|
|
344 | dLOOPbase; |
342 | |
345 | |
343 | if (!once) |
346 | if (!once) |
344 | return -1; |
347 | return -1; |
345 | |
348 | |
346 | once->fd = fd; |
349 | once->fd = fd; |