… | |
… | |
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 |
… | |
… | |
148 | #endif |
152 | #endif |
149 | |
153 | |
150 | /* support multiple event loops? */ |
154 | /* support multiple event loops? */ |
151 | #if EV_MULTIPLICITY |
155 | #if EV_MULTIPLICITY |
152 | struct ev_loop; |
156 | struct ev_loop; |
153 | # define EV_P struct ev_loop *loop |
157 | # define EV_P struct ev_loop *loop /* a loop as sole parameter in a declaration */ |
154 | # define EV_P_ EV_P, |
158 | # define EV_P_ EV_P, /* a loop as first of multiple parameters */ |
155 | # define EV_A loop |
159 | # define EV_A loop /* a loop as sole argument to a function call */ |
156 | # define EV_A_ EV_A, |
160 | # define EV_A_ EV_A, /* a loop as first of multiple arguments */ |
157 | # define EV_DEFAULT_UC ev_default_loop_uc () |
161 | # define EV_DEFAULT_UC ev_default_loop_uc () /* the default loop, if initialised, as sole arg */ |
158 | # define EV_DEFAULT_UC_ EV_DEFAULT_UC, |
162 | # define EV_DEFAULT_UC_ EV_DEFAULT_UC, /* the default loop as first of multiple arguments */ |
159 | # define EV_DEFAULT ev_default_loop (0) |
163 | # define EV_DEFAULT ev_default_loop (0) /* the default loop as sole arg */ |
160 | # define EV_DEFAULT_ EV_DEFAULT, |
164 | # define EV_DEFAULT_ EV_DEFAULT, /* the default loop as first of multiple arguments */ |
161 | #else |
165 | #else |
162 | # define EV_P void |
166 | # define EV_P void |
163 | # define EV_P_ |
167 | # define EV_P_ |
164 | # define EV_A |
168 | # define EV_A |
165 | # define EV_A_ |
169 | # define EV_A_ |
… | |
… | |
168 | # define EV_DEFAULT_UC |
172 | # define EV_DEFAULT_UC |
169 | # define EV_DEFAULT_UC_ |
173 | # define EV_DEFAULT_UC_ |
170 | # undef EV_EMBED_ENABLE |
174 | # undef EV_EMBED_ENABLE |
171 | #endif |
175 | #endif |
172 | |
176 | |
|
|
177 | /* EV_INLINE is used for functions in header files */ |
173 | #if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3 |
178 | #if __STDC_VERSION__ >= 199901L || __GNUC__ >= 3 |
174 | # define EV_INLINE static inline |
179 | # define EV_INLINE static inline |
175 | #else |
180 | #else |
176 | # define EV_INLINE static |
181 | # define EV_INLINE static |
177 | #endif |
182 | #endif |
178 | |
183 | |
|
|
184 | /* EV_PROTOTYPES can be sued to switch of prototype declarations */ |
179 | #ifndef EV_PROTOTYPES |
185 | #ifndef EV_PROTOTYPES |
180 | # define EV_PROTOTYPES 1 |
186 | # define EV_PROTOTYPES 1 |
181 | #endif |
187 | #endif |
182 | |
188 | |
183 | /*****************************************************************************/ |
189 | /*****************************************************************************/ |
… | |
… | |
192 | EV_READ = 0x01, /* ev_io detected read will not block */ |
198 | EV_READ = 0x01, /* ev_io detected read will not block */ |
193 | EV_WRITE = 0x02, /* ev_io detected write will not block */ |
199 | EV_WRITE = 0x02, /* ev_io detected write will not block */ |
194 | EV__IOFDSET = 0x80, /* internal use only */ |
200 | EV__IOFDSET = 0x80, /* internal use only */ |
195 | EV_IO = EV_READ, /* alias for type-detection */ |
201 | EV_IO = EV_READ, /* alias for type-detection */ |
196 | EV_TIMER = 0x00000100, /* timer timed out */ |
202 | EV_TIMER = 0x00000100, /* timer timed out */ |
|
|
203 | #if EV_COMPAT3 |
197 | EV_TIMEOUT = EV_TIMER, /* pre 4.0 API compatibility */ |
204 | EV_TIMEOUT = EV_TIMER, /* pre 4.0 API compatibility */ |
|
|
205 | #endif |
198 | EV_PERIODIC = 0x00000200, /* periodic timer timed out */ |
206 | EV_PERIODIC = 0x00000200, /* periodic timer timed out */ |
199 | EV_SIGNAL = 0x00000400, /* signal was received */ |
207 | EV_SIGNAL = 0x00000400, /* signal was received */ |
200 | EV_CHILD = 0x00000800, /* child/pid had status change */ |
208 | EV_CHILD = 0x00000800, /* child/pid had status change */ |
201 | EV_STAT = 0x00001000, /* stat data changed */ |
209 | EV_STAT = 0x00001000, /* stat data changed */ |
202 | EV_IDLE = 0x00002000, /* event loop is idling */ |
210 | EV_IDLE = 0x00002000, /* event loop is idling */ |
… | |
… | |
500 | * (such as failed select, poll, epoll_wait) |
508 | * (such as failed select, poll, epoll_wait) |
501 | */ |
509 | */ |
502 | void ev_set_syserr_cb (void (*cb)(const char *msg)); |
510 | void ev_set_syserr_cb (void (*cb)(const char *msg)); |
503 | |
511 | |
504 | #if EV_MULTIPLICITY |
512 | #if EV_MULTIPLICITY |
|
|
513 | |
|
|
514 | /* the default loop is the only one that handles signals and child watchers */ |
|
|
515 | /* you can call this as often as you like */ |
|
|
516 | struct ev_loop *ev_default_loop (unsigned int flags EV_CPP (= 0)); |
|
|
517 | |
505 | EV_INLINE struct ev_loop * |
518 | EV_INLINE struct ev_loop * |
506 | ev_default_loop_uc (void) |
519 | ev_default_loop_uc (void) |
507 | { |
520 | { |
508 | extern struct ev_loop *ev_default_loop_ptr; |
521 | extern struct ev_loop *ev_default_loop_ptr; |
509 | |
522 | |
510 | return ev_default_loop_ptr; |
523 | return ev_default_loop_ptr; |
511 | } |
524 | } |
512 | |
525 | |
513 | /* the default loop is the only one that handles signals and child watchers */ |
526 | EV_INLINE int |
514 | /* you can call this as often as you like */ |
527 | ev_is_default_loop (EV_P) |
515 | EV_INLINE struct ev_loop * |
|
|
516 | ev_default_loop (unsigned int flags) |
|
|
517 | { |
528 | { |
518 | struct ev_loop *loop = ev_default_loop_uc (); |
529 | return EV_A == ev_default_loop_uc (); |
519 | |
|
|
520 | if (!loop) |
|
|
521 | { |
|
|
522 | extern struct ev_loop *ev_default_loop_init (unsigned int flags); |
|
|
523 | |
|
|
524 | loop = ev_default_loop_init (flags); |
|
|
525 | } |
|
|
526 | |
|
|
527 | return loop; |
|
|
528 | } |
530 | } |
529 | |
531 | |
530 | /* create and destroy alternative loops that don't handle signals */ |
532 | /* create and destroy alternative loops that don't handle signals */ |
531 | struct ev_loop *ev_loop_new (unsigned int flags); |
533 | struct ev_loop *ev_loop_new (unsigned int flags EV_CPP (= 0)); |
532 | void ev_loop_destroy (EV_P); |
534 | void ev_loop_destroy (EV_P); |
533 | void ev_loop_fork (EV_P); |
535 | void ev_loop_fork (EV_P); |
534 | |
536 | |
535 | ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ |
537 | ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ |
536 | |
538 | |
537 | #else |
539 | #else |
538 | |
540 | |
539 | int ev_default_loop (unsigned int flags); /* returns true when successful */ |
541 | int ev_default_loop (unsigned int flags EV_CPP (= 0)); /* returns true when successful */ |
540 | |
542 | |
541 | EV_INLINE ev_tstamp |
543 | EV_INLINE ev_tstamp |
542 | ev_now (void) |
544 | ev_now (void) |
543 | { |
545 | { |
544 | extern ev_tstamp ev_rt_now; |
546 | extern ev_tstamp ev_rt_now; |
545 | |
547 | |
546 | return ev_rt_now; |
548 | return ev_rt_now; |
547 | } |
549 | } |
|
|
550 | |
|
|
551 | /* looks weird, but ev_is_default_loop (EV_A) still works if this exists */ |
|
|
552 | EV_INLINE int |
|
|
553 | ev_is_default_loop (void) |
|
|
554 | { |
|
|
555 | return 1; |
|
|
556 | } |
|
|
557 | |
548 | #endif /* multiplicity */ |
558 | #endif /* multiplicity */ |
549 | |
|
|
550 | EV_INLINE int |
|
|
551 | ev_is_default_loop (EV_P) |
|
|
552 | { |
|
|
553 | #if EV_MULTIPLICITY |
|
|
554 | extern struct ev_loop *ev_default_loop_ptr; |
|
|
555 | |
|
|
556 | return !!(EV_A == ev_default_loop_ptr); |
|
|
557 | #else |
|
|
558 | return 1; |
|
|
559 | #endif |
|
|
560 | } |
|
|
561 | |
559 | |
562 | void ev_default_destroy (void); /* destroy the default loop */ |
560 | void ev_default_destroy (void); /* destroy the default loop */ |
563 | /* this needs to be called after fork, to duplicate the default loop */ |
561 | /* this needs to be called after fork, to duplicate the default loop */ |
564 | /* if you create alternative loops you have to call ev_loop_fork on them */ |
562 | /* 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 */ |
563 | /* you can call it in either the parent or the child */ |
… | |
… | |
591 | EVBREAK_ONE = 1, /* unloop once */ |
589 | EVBREAK_ONE = 1, /* unloop once */ |
592 | EVBREAK_ALL = 2 /* unloop all loops */ |
590 | EVBREAK_ALL = 2 /* unloop all loops */ |
593 | }; |
591 | }; |
594 | |
592 | |
595 | #if EV_PROTOTYPES |
593 | #if EV_PROTOTYPES |
596 | void ev_run (EV_P_ int flags); |
594 | void ev_run (EV_P_ int flags EV_CPP (= 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 */ |
595 | void ev_break (EV_P_ int how EV_CPP (= EVBREAK_ONE)); /* break out of the loop */ |
598 | |
596 | |
599 | /* |
597 | /* |
600 | * ref/unref can be used to add or remove a refcount on the mainloop. every watcher |
598 | * 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 |
599 | * 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. |
600 | * should not keep ev_loop from running, unref() after starting, and ref() before stopping. |
… | |
… | |
790 | typedef struct ev_loop ev_loop; |
788 | typedef struct ev_loop ev_loop; |
791 | #endif |
789 | #endif |
792 | |
790 | |
793 | #endif |
791 | #endif |
794 | |
792 | |
795 | #ifdef __cplusplus |
793 | EV_CPP(}) |
796 | } |
|
|
797 | #endif |
|
|
798 | |
794 | |
799 | #endif |
795 | #endif |
800 | |
796 | |