… | |
… | |
54 | |
54 | |
55 | #ifndef EV_STAT_ENABLE |
55 | #ifndef EV_STAT_ENABLE |
56 | # define EV_STAT_ENABLE 1 |
56 | # define EV_STAT_ENABLE 1 |
57 | #endif |
57 | #endif |
58 | |
58 | |
|
|
59 | #ifndef EV_IDLE_ENABLE |
|
|
60 | # define EV_IDLE_ENABLE 1 |
|
|
61 | #endif |
|
|
62 | |
59 | #ifndef EV_FORK_ENABLE |
63 | #ifndef EV_FORK_ENABLE |
60 | # define EV_FORK_ENABLE 1 |
64 | # define EV_FORK_ENABLE 1 |
61 | #endif |
65 | #endif |
62 | |
66 | |
63 | #ifndef EV_EMBED_ENABLE |
67 | #ifndef EV_EMBED_ENABLE |
… | |
… | |
113 | #endif |
117 | #endif |
114 | #ifndef EV_PROTOTYPES |
118 | #ifndef EV_PROTOTYPES |
115 | # define EV_PROTOTYPES 1 |
119 | # define EV_PROTOTYPES 1 |
116 | #endif |
120 | #endif |
117 | |
121 | |
118 | #define EV_VERSION_MAJOR 1 |
122 | #define EV_VERSION_MAJOR 2 |
119 | #define EV_VERSION_MINOR 1 |
123 | #define EV_VERSION_MINOR 0 |
120 | |
124 | |
121 | #ifndef EV_CB_DECLARE |
125 | #ifndef EV_CB_DECLARE |
122 | # define EV_CB_DECLARE(type) void (*cb)(EV_P_ struct type *w, int revents); |
126 | # define EV_CB_DECLARE(type) void (*cb)(EV_P_ struct type *w, int revents); |
123 | #endif |
127 | #endif |
124 | #ifndef EV_CB_INVOKE |
128 | #ifndef EV_CB_INVOKE |
… | |
… | |
189 | /* revent EV_PERIODIC */ |
193 | /* revent EV_PERIODIC */ |
190 | typedef struct ev_periodic |
194 | typedef struct ev_periodic |
191 | { |
195 | { |
192 | EV_WATCHER_TIME (ev_periodic) |
196 | EV_WATCHER_TIME (ev_periodic) |
193 | |
197 | |
|
|
198 | ev_tstamp offset; /* rw */ |
194 | ev_tstamp interval; /* rw */ |
199 | ev_tstamp interval; /* rw */ |
195 | ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now); /* rw */ |
200 | ev_tstamp (*reschedule_cb)(struct ev_periodic *w, ev_tstamp now); /* rw */ |
196 | } ev_periodic; |
201 | } ev_periodic; |
197 | |
202 | |
198 | /* invoked when the given signal has been received */ |
203 | /* invoked when the given signal has been received */ |
… | |
… | |
238 | |
243 | |
239 | int wd; /* wd for inotify, fd for kqueue */ |
244 | int wd; /* wd for inotify, fd for kqueue */ |
240 | } ev_stat; |
245 | } ev_stat; |
241 | #endif |
246 | #endif |
242 | |
247 | |
|
|
248 | #if EV_IDLE_ENABLE |
243 | /* invoked when the nothing else needs to be done, keeps the process from blocking */ |
249 | /* invoked when the nothing else needs to be done, keeps the process from blocking */ |
244 | /* revent EV_IDLE */ |
250 | /* revent EV_IDLE */ |
245 | typedef struct ev_idle |
251 | typedef struct ev_idle |
246 | { |
252 | { |
247 | EV_WATCHER (ev_idle) |
253 | EV_WATCHER (ev_idle) |
248 | } ev_idle; |
254 | } ev_idle; |
|
|
255 | #endif |
249 | |
256 | |
250 | /* invoked for each run of the mainloop, just before the blocking call */ |
257 | /* invoked for each run of the mainloop, just before the blocking call */ |
251 | /* you can still change events in any way you like */ |
258 | /* you can still change events in any way you like */ |
252 | /* revent EV_PREPARE */ |
259 | /* revent EV_PREPARE */ |
253 | typedef struct ev_prepare |
260 | typedef struct ev_prepare |
… | |
… | |
294 | struct ev_signal signal; |
301 | struct ev_signal signal; |
295 | struct ev_child child; |
302 | struct ev_child child; |
296 | #if EV_STAT_ENABLE |
303 | #if EV_STAT_ENABLE |
297 | struct ev_stat stat; |
304 | struct ev_stat stat; |
298 | #endif |
305 | #endif |
|
|
306 | #if EV_IDLE_ENABLE |
299 | struct ev_idle idle; |
307 | struct ev_idle idle; |
|
|
308 | #endif |
300 | struct ev_prepare prepare; |
309 | struct ev_prepare prepare; |
301 | struct ev_check check; |
310 | struct ev_check check; |
302 | #if EV_FORK_ENABLE |
311 | #if EV_FORK_ENABLE |
303 | struct ev_fork fork; |
312 | struct ev_fork fork; |
304 | #endif |
313 | #endif |
… | |
… | |
310 | /* bits for ev_default_loop and ev_loop_new */ |
319 | /* bits for ev_default_loop and ev_loop_new */ |
311 | /* the default */ |
320 | /* the default */ |
312 | #define EVFLAG_AUTO 0x00000000UL /* not quite a mask */ |
321 | #define EVFLAG_AUTO 0x00000000UL /* not quite a mask */ |
313 | /* flag bits */ |
322 | /* flag bits */ |
314 | #define EVFLAG_NOENV 0x01000000UL /* do NOT consult environment */ |
323 | #define EVFLAG_NOENV 0x01000000UL /* do NOT consult environment */ |
|
|
324 | #define EVFLAG_FORKCHECK 0x02000000UL /* check for a fork in each iteration */ |
315 | /* method bits to be ored together */ |
325 | /* method bits to be ored together */ |
316 | #define EVBACKEND_SELECT 0x00000001UL /* about anywhere */ |
326 | #define EVBACKEND_SELECT 0x00000001UL /* about anywhere */ |
317 | #define EVBACKEND_POLL 0x00000002UL /* !win */ |
327 | #define EVBACKEND_POLL 0x00000002UL /* !win */ |
318 | #define EVBACKEND_EPOLL 0x00000004UL /* linux */ |
328 | #define EVBACKEND_EPOLL 0x00000004UL /* linux */ |
319 | #define EVBACKEND_KQUEUE 0x00000008UL /* bsd */ |
329 | #define EVBACKEND_KQUEUE 0x00000008UL /* bsd */ |
… | |
… | |
385 | /* you can call it in either the parent or the child */ |
395 | /* you can call it in either the parent or the child */ |
386 | /* you can actually call it at any time, anywhere :) */ |
396 | /* you can actually call it at any time, anywhere :) */ |
387 | void ev_default_fork (void); |
397 | void ev_default_fork (void); |
388 | |
398 | |
389 | unsigned int ev_backend (EV_P); |
399 | unsigned int ev_backend (EV_P); |
|
|
400 | unsigned int ev_loop_count (EV_P); |
390 | #endif |
401 | #endif |
391 | |
402 | |
392 | #define EVLOOP_NONBLOCK 1 /* do not block/wait */ |
403 | #define EVLOOP_NONBLOCK 1 /* do not block/wait */ |
393 | #define EVLOOP_ONESHOT 2 /* block *once* only */ |
404 | #define EVLOOP_ONESHOT 2 /* block *once* only */ |
394 | #define EVUNLOOP_CANCEL 0 /* undo unloop */ |
405 | #define EVUNLOOP_CANCEL 0 /* undo unloop */ |
… | |
… | |
412 | void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg); |
423 | void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg); |
413 | #endif |
424 | #endif |
414 | |
425 | |
415 | /* these may evaluate ev multiple times, and the other arguments at most once */ |
426 | /* these may evaluate ev multiple times, and the other arguments at most once */ |
416 | /* either use ev_init + ev_TYPE_set, or the ev_TYPE_init macro, below, to first initialise a watcher */ |
427 | /* either use ev_init + ev_TYPE_set, or the ev_TYPE_init macro, below, to first initialise a watcher */ |
417 | #define ev_init(ev,cb_) do { \ |
428 | #define ev_init(ev,cb_) do { \ |
418 | ((ev_watcher *)(void *)(ev))->active = \ |
429 | ((ev_watcher *)(void *)(ev))->active = \ |
419 | ((ev_watcher *)(void *)(ev))->pending = \ |
430 | ((ev_watcher *)(void *)(ev))->pending = \ |
420 | ((ev_watcher *)(void *)(ev))->priority = 0; \ |
431 | ((ev_watcher *)(void *)(ev))->priority = 0; \ |
421 | ev_set_cb ((ev), cb_); \ |
432 | ev_set_cb ((ev), cb_); \ |
422 | } while (0) |
433 | } while (0) |
423 | |
434 | |
424 | #define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0) |
435 | #define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0) |
425 | #define ev_timer_set(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); } while (0) |
436 | #define ev_timer_set(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); } while (0) |
426 | #define ev_periodic_set(ev,at_,ival_,res_) do { (ev)->at = (at_); (ev)->interval = (ival_); (ev)->reschedule_cb= (res_); } while (0) |
437 | #define ev_periodic_set(ev,ofs_,ival_,res_) do { (ev)->offset = (ofs_); (ev)->interval = (ival_); (ev)->reschedule_cb= (res_); } while (0) |
427 | #define ev_signal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0) |
438 | #define ev_signal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0) |
428 | #define ev_child_set(ev,pid_) do { (ev)->pid = (pid_); } while (0) |
439 | #define ev_child_set(ev,pid_) do { (ev)->pid = (pid_); } while (0) |
429 | #define ev_stat_set(ev,path_,interval_) do { (ev)->path = (path_); (ev)->interval = (interval_); (ev)->wd = -2; } while (0) |
440 | #define ev_stat_set(ev,path_,interval_) do { (ev)->path = (path_); (ev)->interval = (interval_); (ev)->wd = -2; } while (0) |
430 | #define ev_idle_set(ev) /* nop, yes, this is a serious in-joke */ |
441 | #define ev_idle_set(ev) /* nop, yes, this is a serious in-joke */ |
431 | #define ev_prepare_set(ev) /* nop, yes, this is a serious in-joke */ |
442 | #define ev_prepare_set(ev) /* nop, yes, this is a serious in-joke */ |
… | |
… | |
446 | #define ev_fork_init(ev,cb) do { ev_init ((ev), (cb)); ev_fork_set ((ev)); } while (0) |
457 | #define ev_fork_init(ev,cb) do { ev_init ((ev), (cb)); ev_fork_set ((ev)); } while (0) |
447 | |
458 | |
448 | #define ev_is_pending(ev) (0 + ((ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */ |
459 | #define ev_is_pending(ev) (0 + ((ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */ |
449 | #define ev_is_active(ev) (0 + ((ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */ |
460 | #define ev_is_active(ev) (0 + ((ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */ |
450 | |
461 | |
451 | #define ev_priority(ev) ((ev_watcher *)(void *)(ev))->priority /* rw */ |
462 | #define ev_priority(ev) ((((ev_watcher *)(void *)(ev))->priority) + 0) |
452 | #define ev_cb(ev) (ev)->cb /* rw */ |
463 | #define ev_cb(ev) (ev)->cb /* rw */ |
453 | #define ev_set_priority(ev,pri) ev_priority (ev) = (pri) |
464 | #define ev_set_priority(ev,pri) ((ev_watcher *)(void *)(ev))->priority = (pri) |
454 | |
465 | |
455 | #ifndef ev_set_cb |
466 | #ifndef ev_set_cb |
456 | # define ev_set_cb(ev,cb_) ev_cb (ev) = (cb_) |
467 | # define ev_set_cb(ev,cb_) ev_cb (ev) = (cb_) |
457 | #endif |
468 | #endif |
458 | |
469 | |
… | |
… | |
463 | /* feeds an event into a watcher as if the event actually occured */ |
474 | /* feeds an event into a watcher as if the event actually occured */ |
464 | /* accepts any ev_watcher type */ |
475 | /* accepts any ev_watcher type */ |
465 | void ev_feed_event (EV_P_ void *w, int revents); |
476 | void ev_feed_event (EV_P_ void *w, int revents); |
466 | void ev_feed_fd_event (EV_P_ int fd, int revents); |
477 | void ev_feed_fd_event (EV_P_ int fd, int revents); |
467 | void ev_feed_signal_event (EV_P_ int signum); |
478 | void ev_feed_signal_event (EV_P_ int signum); |
|
|
479 | void ev_invoke (EV_P_ void *w, int revents); |
|
|
480 | int ev_clear_pending (EV_P_ void *w); |
468 | |
481 | |
469 | void ev_io_start (EV_P_ ev_io *w); |
482 | void ev_io_start (EV_P_ ev_io *w); |
470 | void ev_io_stop (EV_P_ ev_io *w); |
483 | void ev_io_stop (EV_P_ ev_io *w); |
471 | |
484 | |
472 | void ev_timer_start (EV_P_ ev_timer *w); |
485 | void ev_timer_start (EV_P_ ev_timer *w); |
… | |
… | |
492 | void ev_stat_start (EV_P_ ev_stat *w); |
505 | void ev_stat_start (EV_P_ ev_stat *w); |
493 | void ev_stat_stop (EV_P_ ev_stat *w); |
506 | void ev_stat_stop (EV_P_ ev_stat *w); |
494 | void ev_stat_stat (EV_P_ ev_stat *w); |
507 | void ev_stat_stat (EV_P_ ev_stat *w); |
495 | # endif |
508 | # endif |
496 | |
509 | |
|
|
510 | # if EV_IDLE_ENABLE |
497 | void ev_idle_start (EV_P_ ev_idle *w); |
511 | void ev_idle_start (EV_P_ ev_idle *w); |
498 | void ev_idle_stop (EV_P_ ev_idle *w); |
512 | void ev_idle_stop (EV_P_ ev_idle *w); |
|
|
513 | # endif |
499 | |
514 | |
500 | void ev_prepare_start (EV_P_ ev_prepare *w); |
515 | void ev_prepare_start (EV_P_ ev_prepare *w); |
501 | void ev_prepare_stop (EV_P_ ev_prepare *w); |
516 | void ev_prepare_stop (EV_P_ ev_prepare *w); |
502 | |
517 | |
503 | void ev_check_start (EV_P_ ev_check *w); |
518 | void ev_check_start (EV_P_ ev_check *w); |