… | |
… | |
39 | |
39 | |
40 | #ifndef EV_H_ |
40 | #ifndef EV_H_ |
41 | #define EV_H_ |
41 | #define EV_H_ |
42 | |
42 | |
43 | #ifdef __cplusplus |
43 | #ifdef __cplusplus |
|
|
44 | # define EV_CPP(x) x |
|
|
45 | #else |
|
|
46 | # define EV_CPP(x) |
|
|
47 | #endif |
|
|
48 | |
44 | extern "C" { |
49 | EV_CPP(extern "C" {) |
45 | #endif |
|
|
46 | |
50 | |
47 | /*****************************************************************************/ |
51 | /*****************************************************************************/ |
48 | |
52 | |
49 | /* pre-4.0 compatibility */ |
53 | /* pre-4.0 compatibility */ |
50 | #ifndef EV_COMPAT3 |
54 | #ifndef EV_COMPAT3 |
… | |
… | |
143 | # ifdef _WIN32 |
147 | # ifdef _WIN32 |
144 | # include <time.h> |
148 | # include <time.h> |
145 | # include <sys/types.h> |
149 | # include <sys/types.h> |
146 | # endif |
150 | # endif |
147 | # include <sys/stat.h> |
151 | # include <sys/stat.h> |
148 | #endif |
|
|
149 | |
|
|
150 | /* in C++ we can use this to provide default arguments */ |
|
|
151 | #ifdef __cplusplus |
|
|
152 | # define EV_DEFARG(x) = x |
|
|
153 | #else |
|
|
154 | # define EV_DEFARG(x) |
|
|
155 | #endif |
152 | #endif |
156 | |
153 | |
157 | /* support multiple event loops? */ |
154 | /* support multiple event loops? */ |
158 | #if EV_MULTIPLICITY |
155 | #if EV_MULTIPLICITY |
159 | struct ev_loop; |
156 | struct ev_loop; |
… | |
… | |
163 | # define EV_A_ EV_A, /* a loop as first of multiple arguments */ |
160 | # define EV_A_ EV_A, /* a loop as first of multiple arguments */ |
164 | # define EV_DEFAULT_UC ev_default_loop_uc () /* the default loop, if initialised, as sole arg */ |
161 | # define EV_DEFAULT_UC ev_default_loop_uc () /* the default loop, if initialised, as sole arg */ |
165 | # define EV_DEFAULT_UC_ EV_DEFAULT_UC, /* the default loop as first of multiple arguments */ |
162 | # define EV_DEFAULT_UC_ EV_DEFAULT_UC, /* the default loop as first of multiple arguments */ |
166 | # define EV_DEFAULT ev_default_loop (0) /* the default loop as sole arg */ |
163 | # define EV_DEFAULT ev_default_loop (0) /* the default loop as sole arg */ |
167 | # define EV_DEFAULT_ EV_DEFAULT, /* the default loop as first of multiple arguments */ |
164 | # define EV_DEFAULT_ EV_DEFAULT, /* the default loop as first of multiple arguments */ |
168 | # define EV_PDEF EV_P EV_DEFARG (EV_DEFAULT_UC) /* EV_P, but with default argument in C++ */ |
|
|
169 | # define EV_PDEF_ EV_P EV_DEFARG (EV_DEFAULT_UC), /* EV_P_, but with default argument in C++ */ |
|
|
170 | #else |
165 | #else |
171 | # define EV_P void |
166 | # define EV_P void |
172 | # define EV_P_ |
167 | # define EV_P_ |
173 | # define EV_A |
168 | # define EV_A |
174 | # define EV_A_ |
169 | # define EV_A_ |
175 | # define EV_DEFAULT |
170 | # define EV_DEFAULT |
176 | # define EV_DEFAULT_ |
171 | # define EV_DEFAULT_ |
177 | # define EV_DEFAULT_UC |
172 | # define EV_DEFAULT_UC |
178 | # define EV_DEFAULT_UC_ |
173 | # define EV_DEFAULT_UC_ |
179 | # define EV_PDEF EV_P |
|
|
180 | # define EV_PDEF_ EV_P_ |
|
|
181 | # undef EV_EMBED_ENABLE |
174 | # undef EV_EMBED_ENABLE |
182 | #endif |
175 | #endif |
183 | |
176 | |
184 | /* EV_INLINE is used for functions in header files */ |
177 | /* EV_INLINE is used for functions in header files */ |
185 | #if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3 |
178 | #if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3 |
… | |
… | |
526 | } |
519 | } |
527 | |
520 | |
528 | /* the default loop is the only one that handles signals and child watchers */ |
521 | /* the default loop is the only one that handles signals and child watchers */ |
529 | /* you can call this as often as you like */ |
522 | /* you can call this as often as you like */ |
530 | EV_INLINE struct ev_loop * |
523 | EV_INLINE struct ev_loop * |
531 | ev_default_loop (unsigned int flags EV_DEFARG (0)) |
524 | ev_default_loop (unsigned int flags EV_CPP (= 0)) |
532 | { |
525 | { |
533 | struct ev_loop *loop = ev_default_loop_uc (); |
526 | struct ev_loop *loop = ev_default_loop_uc (); |
534 | |
527 | |
535 | if (!loop) |
528 | if (!loop) |
536 | { |
529 | { |
… | |
… | |
541 | |
534 | |
542 | return loop; |
535 | return loop; |
543 | } |
536 | } |
544 | |
537 | |
545 | /* create and destroy alternative loops that don't handle signals */ |
538 | /* create and destroy alternative loops that don't handle signals */ |
546 | struct ev_loop *ev_loop_new (unsigned int flags EV_DEFARG (0)); |
539 | struct ev_loop *ev_loop_new (unsigned int flags EV_CPP (= 0)); |
547 | void ev_loop_destroy (EV_PDEF); |
540 | void ev_loop_destroy (EV_P); |
548 | void ev_loop_fork (EV_PDEF); |
541 | void ev_loop_fork (EV_P); |
549 | |
542 | |
550 | ev_tstamp ev_now (EV_PDEF); /* time w.r.t. timers and the eventloop, updated after each poll */ |
543 | ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ |
551 | |
544 | |
552 | #else |
545 | #else |
553 | |
546 | |
554 | int ev_default_loop (unsigned int flags EV_DEFARG (0)); /* returns true when successful */ |
547 | int ev_default_loop (unsigned int flags EV_CPP (= 0)); /* returns true when successful */ |
555 | |
548 | |
556 | EV_INLINE ev_tstamp |
549 | EV_INLINE ev_tstamp |
557 | ev_now (void) |
550 | ev_now (void) |
558 | { |
551 | { |
559 | extern ev_tstamp ev_rt_now; |
552 | extern ev_tstamp ev_rt_now; |
… | |
… | |
561 | return ev_rt_now; |
554 | return ev_rt_now; |
562 | } |
555 | } |
563 | #endif /* multiplicity */ |
556 | #endif /* multiplicity */ |
564 | |
557 | |
565 | EV_INLINE int |
558 | EV_INLINE int |
566 | ev_is_default_loop (EV_PDEF) |
559 | ev_is_default_loop (EV_P) |
567 | { |
560 | { |
568 | #if EV_MULTIPLICITY |
561 | #if EV_MULTIPLICITY |
569 | extern struct ev_loop *ev_default_loop_ptr; |
562 | extern struct ev_loop *ev_default_loop_ptr; |
570 | |
563 | |
571 | return !!(EV_A == ev_default_loop_ptr); |
564 | return !!(EV_A == ev_default_loop_ptr); |
… | |
… | |
579 | /* if you create alternative loops you have to call ev_loop_fork on them */ |
572 | /* if you create alternative loops you have to call ev_loop_fork on them */ |
580 | /* you can call it in either the parent or the child */ |
573 | /* you can call it in either the parent or the child */ |
581 | /* you can actually call it at any time, anywhere :) */ |
574 | /* you can actually call it at any time, anywhere :) */ |
582 | void ev_default_fork (void); |
575 | void ev_default_fork (void); |
583 | |
576 | |
584 | unsigned int ev_backend (EV_PDEF); /* backend in use by loop */ |
577 | unsigned int ev_backend (EV_P); /* backend in use by loop */ |
585 | |
578 | |
586 | void ev_now_update (EV_PDEF); /* update event loop time */ |
579 | void ev_now_update (EV_P); /* update event loop time */ |
587 | |
580 | |
588 | #if EV_WALK_ENABLE |
581 | #if EV_WALK_ENABLE |
589 | /* walk (almost) all watchers in the loop of a given type, invoking the */ |
582 | /* walk (almost) all watchers in the loop of a given type, invoking the */ |
590 | /* callback on every such watcher. The callback might stop the watcher, */ |
583 | /* callback on every such watcher. The callback might stop the watcher, */ |
591 | /* but do nothing else with the loop */ |
584 | /* but do nothing else with the loop */ |
… | |
… | |
606 | EVBREAK_ONE = 1, /* unloop once */ |
599 | EVBREAK_ONE = 1, /* unloop once */ |
607 | EVBREAK_ALL = 2 /* unloop all loops */ |
600 | EVBREAK_ALL = 2 /* unloop all loops */ |
608 | }; |
601 | }; |
609 | |
602 | |
610 | #if EV_PROTOTYPES |
603 | #if EV_PROTOTYPES |
611 | void ev_run (EV_PDEF_ int flags EV_DEFARG (0)); |
604 | void ev_run (EV_P_ int flags EV_CPP (= 0)); |
612 | void ev_break (EV_PDEF_ int how EV_DEFARG (EVBREAK_ONE)); /* break out of the loop */ |
605 | void ev_break (EV_P_ int how EV_CPP (= EVBREAK_ONE)); /* break out of the loop */ |
613 | |
606 | |
614 | /* |
607 | /* |
615 | * ref/unref can be used to add or remove a refcount on the mainloop. every watcher |
608 | * ref/unref can be used to add or remove a refcount on the mainloop. every watcher |
616 | * keeps one reference. if you have a long-running watcher you never unregister that |
609 | * keeps one reference. if you have a long-running watcher you never unregister that |
617 | * should not keep ev_loop from running, unref() after starting, and ref() before stopping. |
610 | * should not keep ev_loop from running, unref() after starting, and ref() before stopping. |
618 | */ |
611 | */ |
619 | void ev_ref (EV_PDEF); |
612 | void ev_ref (EV_P); |
620 | void ev_unref (EV_PDEF); |
613 | void ev_unref (EV_P); |
621 | |
614 | |
622 | /* |
615 | /* |
623 | * convenience function, wait for a single event, without registering an event watcher |
616 | * convenience function, wait for a single event, without registering an event watcher |
624 | * if timeout is < 0, do wait indefinitely |
617 | * if timeout is < 0, do wait indefinitely |
625 | */ |
618 | */ |
626 | void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg); |
619 | void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg); |
627 | |
620 | |
628 | # if EV_FEATURE_API |
621 | # if EV_FEATURE_API |
629 | unsigned int ev_iteration (EV_PDEF); /* number of loop iterations */ |
622 | unsigned int ev_iteration (EV_P); /* number of loop iterations */ |
630 | unsigned int ev_depth (EV_PDEF); /* #ev_loop enters - #ev_loop leaves */ |
623 | unsigned int ev_depth (EV_P); /* #ev_loop enters - #ev_loop leaves */ |
631 | void ev_verify (EV_PDEF); /* abort if loop data corrupted */ |
624 | void ev_verify (EV_P); /* abort if loop data corrupted */ |
632 | |
625 | |
633 | void ev_set_io_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */ |
626 | void ev_set_io_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */ |
634 | void ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */ |
627 | void ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */ |
635 | |
628 | |
636 | /* advanced stuff for threading etc. support, see docs */ |
629 | /* advanced stuff for threading etc. support, see docs */ |
637 | void ev_set_userdata (EV_P_ void *data); |
630 | void ev_set_userdata (EV_P_ void *data); |
638 | void *ev_userdata (EV_PDEF); |
631 | void *ev_userdata (EV_P); |
639 | void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)); |
632 | void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)); |
640 | void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)); |
633 | void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)); |
641 | |
634 | |
642 | unsigned int ev_pending_count (EV_PDEF); /* number of pending events, if any */ |
635 | unsigned int ev_pending_count (EV_P); /* number of pending events, if any */ |
643 | void ev_invoke_pending (EV_PDEF); /* invoke all pending watchers */ |
636 | void ev_invoke_pending (EV_P); /* invoke all pending watchers */ |
644 | |
637 | |
645 | /* |
638 | /* |
646 | * stop/start the timer handling. |
639 | * stop/start the timer handling. |
647 | */ |
640 | */ |
648 | void ev_suspend (EV_PDEF); |
641 | void ev_suspend (EV_P); |
649 | void ev_resume (EV_PDEF); |
642 | void ev_resume (EV_P); |
650 | #endif |
643 | #endif |
651 | |
644 | |
652 | #endif |
645 | #endif |
653 | |
646 | |
654 | /* these may evaluate ev multiple times, and the other arguments at most once */ |
647 | /* these may evaluate ev multiple times, and the other arguments at most once */ |
… | |
… | |
805 | typedef struct ev_loop ev_loop; |
798 | typedef struct ev_loop ev_loop; |
806 | #endif |
799 | #endif |
807 | |
800 | |
808 | #endif |
801 | #endif |
809 | |
802 | |
810 | #ifdef __cplusplus |
803 | EV_CPP(}) |
811 | } |
|
|
812 | #endif |
|
|
813 | |
804 | |
814 | #endif |
805 | #endif |
815 | |
806 | |