… | |
… | |
145 | # include <sys/types.h> |
145 | # include <sys/types.h> |
146 | # endif |
146 | # endif |
147 | # include <sys/stat.h> |
147 | # include <sys/stat.h> |
148 | #endif |
148 | #endif |
149 | |
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 |
|
|
156 | |
150 | /* support multiple event loops? */ |
157 | /* support multiple event loops? */ |
151 | #if EV_MULTIPLICITY |
158 | #if EV_MULTIPLICITY |
152 | struct ev_loop; |
159 | struct ev_loop; |
153 | # define EV_P struct ev_loop *loop |
160 | # define EV_P struct ev_loop *loop /* a loop as sole parameter in a declaration */ |
154 | # define EV_P_ EV_P, |
161 | # define EV_P_ EV_P, /* a loop as first of multiple parameters */ |
155 | # define EV_A loop |
162 | # define EV_A loop /* a loop as sole argument to a function call */ |
156 | # define EV_A_ EV_A, |
163 | # define EV_A_ EV_A, /* a loop as first of multiple arguments */ |
157 | # define EV_DEFAULT_UC ev_default_loop_uc () |
164 | # define EV_DEFAULT_UC ev_default_loop_uc () /* the default loop, if initialised, as sole arg */ |
158 | # define EV_DEFAULT_UC_ EV_DEFAULT_UC, |
165 | # define EV_DEFAULT_UC_ EV_DEFAULT_UC, /* the default loop as first of multiple arguments */ |
159 | # define EV_DEFAULT ev_default_loop (0) |
166 | # define EV_DEFAULT ev_default_loop (0) /* the default loop as sole arg */ |
160 | # define EV_DEFAULT_ EV_DEFAULT, |
167 | # 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++ */ |
161 | #else |
170 | #else |
162 | # define EV_P void |
171 | # define EV_P void |
163 | # define EV_P_ |
172 | # define EV_P_ |
164 | # define EV_A |
173 | # define EV_A |
165 | # define EV_A_ |
174 | # define EV_A_ |
166 | # define EV_DEFAULT |
175 | # define EV_DEFAULT |
167 | # define EV_DEFAULT_ |
176 | # define EV_DEFAULT_ |
168 | # define EV_DEFAULT_UC |
177 | # define EV_DEFAULT_UC |
169 | # define EV_DEFAULT_UC_ |
178 | # define EV_DEFAULT_UC_ |
|
|
179 | # define EV_PDEF EV_P |
|
|
180 | # define EV_PDEF_ EV_P_ |
170 | # undef EV_EMBED_ENABLE |
181 | # undef EV_EMBED_ENABLE |
171 | #endif |
182 | #endif |
172 | |
183 | |
|
|
184 | /* EV_INLINE is used for functions in header files */ |
173 | #if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3 |
185 | #if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3 |
174 | # define EV_INLINE static inline |
186 | # define EV_INLINE static inline |
175 | #else |
187 | #else |
176 | # define EV_INLINE static |
188 | # define EV_INLINE static |
177 | #endif |
189 | #endif |
178 | |
190 | |
|
|
191 | /* EV_PROTOTYPES can be sued to switch of prototype declarations */ |
179 | #ifndef EV_PROTOTYPES |
192 | #ifndef EV_PROTOTYPES |
180 | # define EV_PROTOTYPES 1 |
193 | # define EV_PROTOTYPES 1 |
181 | #endif |
194 | #endif |
182 | |
195 | |
183 | /*****************************************************************************/ |
196 | /*****************************************************************************/ |
… | |
… | |
192 | EV_READ = 0x01, /* ev_io detected read will not block */ |
205 | EV_READ = 0x01, /* ev_io detected read will not block */ |
193 | EV_WRITE = 0x02, /* ev_io detected write will not block */ |
206 | EV_WRITE = 0x02, /* ev_io detected write will not block */ |
194 | EV__IOFDSET = 0x80, /* internal use only */ |
207 | EV__IOFDSET = 0x80, /* internal use only */ |
195 | EV_IO = EV_READ, /* alias for type-detection */ |
208 | EV_IO = EV_READ, /* alias for type-detection */ |
196 | EV_TIMER = 0x00000100, /* timer timed out */ |
209 | EV_TIMER = 0x00000100, /* timer timed out */ |
|
|
210 | #if EV_COMPAT3 |
197 | EV_TIMEOUT = EV_TIMER, /* pre 4.0 API compatibility */ |
211 | EV_TIMEOUT = EV_TIMER, /* pre 4.0 API compatibility */ |
|
|
212 | #endif |
198 | EV_PERIODIC = 0x00000200, /* periodic timer timed out */ |
213 | EV_PERIODIC = 0x00000200, /* periodic timer timed out */ |
199 | EV_SIGNAL = 0x00000400, /* signal was received */ |
214 | EV_SIGNAL = 0x00000400, /* signal was received */ |
200 | EV_CHILD = 0x00000800, /* child/pid had status change */ |
215 | EV_CHILD = 0x00000800, /* child/pid had status change */ |
201 | EV_STAT = 0x00001000, /* stat data changed */ |
216 | EV_STAT = 0x00001000, /* stat data changed */ |
202 | EV_IDLE = 0x00002000, /* event loop is idling */ |
217 | EV_IDLE = 0x00002000, /* event loop is idling */ |
… | |
… | |
511 | } |
526 | } |
512 | |
527 | |
513 | /* the default loop is the only one that handles signals and child watchers */ |
528 | /* the default loop is the only one that handles signals and child watchers */ |
514 | /* you can call this as often as you like */ |
529 | /* you can call this as often as you like */ |
515 | EV_INLINE struct ev_loop * |
530 | EV_INLINE struct ev_loop * |
516 | ev_default_loop (unsigned int flags) |
531 | ev_default_loop (unsigned int flags EV_DEFARG (0)) |
517 | { |
532 | { |
518 | struct ev_loop *loop = ev_default_loop_uc (); |
533 | struct ev_loop *loop = ev_default_loop_uc (); |
519 | |
534 | |
520 | if (!loop) |
535 | if (!loop) |
521 | { |
536 | { |
… | |
… | |
526 | |
541 | |
527 | return loop; |
542 | return loop; |
528 | } |
543 | } |
529 | |
544 | |
530 | /* create and destroy alternative loops that don't handle signals */ |
545 | /* create and destroy alternative loops that don't handle signals */ |
531 | struct ev_loop *ev_loop_new (unsigned int flags); |
546 | struct ev_loop *ev_loop_new (unsigned int flags EV_DEFARG (0)); |
532 | void ev_loop_destroy (EV_P); |
547 | void ev_loop_destroy (EV_PDEF); |
533 | void ev_loop_fork (EV_P); |
548 | void ev_loop_fork (EV_PDEF); |
534 | |
549 | |
535 | ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ |
550 | ev_tstamp ev_now (EV_PDEF); /* time w.r.t. timers and the eventloop, updated after each poll */ |
536 | |
551 | |
537 | #else |
552 | #else |
538 | |
553 | |
539 | int ev_default_loop (unsigned int flags); /* returns true when successful */ |
554 | int ev_default_loop (unsigned int flags EV_DEFARG (0)); /* returns true when successful */ |
540 | |
555 | |
541 | EV_INLINE ev_tstamp |
556 | EV_INLINE ev_tstamp |
542 | ev_now (void) |
557 | ev_now (void) |
543 | { |
558 | { |
544 | extern ev_tstamp ev_rt_now; |
559 | extern ev_tstamp ev_rt_now; |
… | |
… | |
546 | return ev_rt_now; |
561 | return ev_rt_now; |
547 | } |
562 | } |
548 | #endif /* multiplicity */ |
563 | #endif /* multiplicity */ |
549 | |
564 | |
550 | EV_INLINE int |
565 | EV_INLINE int |
551 | ev_is_default_loop (EV_P) |
566 | ev_is_default_loop (EV_PDEF) |
552 | { |
567 | { |
553 | #if EV_MULTIPLICITY |
568 | #if EV_MULTIPLICITY |
554 | extern struct ev_loop *ev_default_loop_ptr; |
569 | extern struct ev_loop *ev_default_loop_ptr; |
555 | |
570 | |
556 | return !!(EV_A == ev_default_loop_ptr); |
571 | return !!(EV_A == ev_default_loop_ptr); |
… | |
… | |
564 | /* if you create alternative loops you have to call ev_loop_fork on them */ |
579 | /* if you create alternative loops you have to call ev_loop_fork on them */ |
565 | /* you can call it in either the parent or the child */ |
580 | /* you can call it in either the parent or the child */ |
566 | /* you can actually call it at any time, anywhere :) */ |
581 | /* you can actually call it at any time, anywhere :) */ |
567 | void ev_default_fork (void); |
582 | void ev_default_fork (void); |
568 | |
583 | |
569 | unsigned int ev_backend (EV_P); /* backend in use by loop */ |
584 | unsigned int ev_backend (EV_PDEF); /* backend in use by loop */ |
570 | |
585 | |
571 | void ev_now_update (EV_P); /* update event loop time */ |
586 | void ev_now_update (EV_PDEF); /* update event loop time */ |
572 | |
587 | |
573 | #if EV_WALK_ENABLE |
588 | #if EV_WALK_ENABLE |
574 | /* walk (almost) all watchers in the loop of a given type, invoking the */ |
589 | /* walk (almost) all watchers in the loop of a given type, invoking the */ |
575 | /* callback on every such watcher. The callback might stop the watcher, */ |
590 | /* callback on every such watcher. The callback might stop the watcher, */ |
576 | /* but do nothing else with the loop */ |
591 | /* but do nothing else with the loop */ |
… | |
… | |
591 | EVBREAK_ONE = 1, /* unloop once */ |
606 | EVBREAK_ONE = 1, /* unloop once */ |
592 | EVBREAK_ALL = 2 /* unloop all loops */ |
607 | EVBREAK_ALL = 2 /* unloop all loops */ |
593 | }; |
608 | }; |
594 | |
609 | |
595 | #if EV_PROTOTYPES |
610 | #if EV_PROTOTYPES |
596 | void ev_run (EV_P_ int flags); |
611 | void ev_run (EV_PDEF_ int flags EV_DEFARG (0)); |
597 | void ev_break (EV_P_ int how); /* set to 1 to break out of event loop, set to 2 to break out of all event loops */ |
612 | void ev_break (EV_PDEF_ int how EV_DEFARG (EVBREAK_ONE)); /* break out of the loop */ |
598 | |
613 | |
599 | /* |
614 | /* |
600 | * ref/unref can be used to add or remove a refcount on the mainloop. every watcher |
615 | * ref/unref can be used to add or remove a refcount on the mainloop. every watcher |
601 | * keeps one reference. if you have a long-running watcher you never unregister that |
616 | * keeps one reference. if you have a long-running watcher you never unregister that |
602 | * should not keep ev_loop from running, unref() after starting, and ref() before stopping. |
617 | * should not keep ev_loop from running, unref() after starting, and ref() before stopping. |
603 | */ |
618 | */ |
604 | void ev_ref (EV_P); |
619 | void ev_ref (EV_PDEF); |
605 | void ev_unref (EV_P); |
620 | void ev_unref (EV_PDEF); |
606 | |
621 | |
607 | /* |
622 | /* |
608 | * convenience function, wait for a single event, without registering an event watcher |
623 | * convenience function, wait for a single event, without registering an event watcher |
609 | * if timeout is < 0, do wait indefinitely |
624 | * if timeout is < 0, do wait indefinitely |
610 | */ |
625 | */ |
611 | void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg); |
626 | void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg); |
612 | |
627 | |
613 | # if EV_FEATURE_API |
628 | # if EV_FEATURE_API |
614 | unsigned int ev_iteration (EV_P); /* number of loop iterations */ |
629 | unsigned int ev_iteration (EV_PDEF); /* number of loop iterations */ |
615 | unsigned int ev_depth (EV_P); /* #ev_loop enters - #ev_loop leaves */ |
630 | unsigned int ev_depth (EV_PDEF); /* #ev_loop enters - #ev_loop leaves */ |
616 | void ev_verify (EV_P); /* abort if loop data corrupted */ |
631 | void ev_verify (EV_PDEF); /* abort if loop data corrupted */ |
617 | |
632 | |
618 | void ev_set_io_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */ |
633 | void ev_set_io_collect_interval (EV_P_ ev_tstamp interval); /* sleep at least this time, default 0 */ |
619 | void ev_set_timeout_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 */ |
620 | |
635 | |
621 | /* advanced stuff for threading etc. support, see docs */ |
636 | /* advanced stuff for threading etc. support, see docs */ |
622 | void ev_set_userdata (EV_P_ void *data); |
637 | void ev_set_userdata (EV_P_ void *data); |
623 | void *ev_userdata (EV_P); |
638 | void *ev_userdata (EV_PDEF); |
624 | void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)); |
639 | void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)); |
625 | void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)); |
640 | void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)); |
626 | |
641 | |
627 | unsigned int ev_pending_count (EV_P); /* number of pending events, if any */ |
642 | unsigned int ev_pending_count (EV_PDEF); /* number of pending events, if any */ |
628 | void ev_invoke_pending (EV_P); /* invoke all pending watchers */ |
643 | void ev_invoke_pending (EV_PDEF); /* invoke all pending watchers */ |
629 | |
644 | |
630 | /* |
645 | /* |
631 | * stop/start the timer handling. |
646 | * stop/start the timer handling. |
632 | */ |
647 | */ |
633 | void ev_suspend (EV_P); |
648 | void ev_suspend (EV_PDEF); |
634 | void ev_resume (EV_P); |
649 | void ev_resume (EV_PDEF); |
635 | #endif |
650 | #endif |
636 | |
651 | |
637 | #endif |
652 | #endif |
638 | |
653 | |
639 | /* these may evaluate ev multiple times, and the other arguments at most once */ |
654 | /* these may evaluate ev multiple times, and the other arguments at most once */ |