… | |
… | |
46 | |
46 | |
47 | #ifndef EV_MULTIPLICITY |
47 | #ifndef EV_MULTIPLICITY |
48 | # define EV_MULTIPLICITY 1 |
48 | # define EV_MULTIPLICITY 1 |
49 | #endif |
49 | #endif |
50 | |
50 | |
|
|
51 | #ifndef EV_PERIODICS |
|
|
52 | # define EV_PERIODICS 1 |
|
|
53 | #endif |
|
|
54 | |
51 | /* support multiple event loops? */ |
55 | /* support multiple event loops? */ |
52 | #if EV_MULTIPLICITY |
56 | #if EV_MULTIPLICITY |
53 | struct ev_loop; |
57 | struct ev_loop; |
54 | # define EV_P struct ev_loop *loop |
58 | # define EV_P struct ev_loop *loop |
55 | # define EV_P_ EV_P, |
59 | # define EV_P_ EV_P, |
56 | # define EV_A loop |
60 | # define EV_A loop |
57 | # define EV_A_ EV_A, |
61 | # define EV_A_ EV_A, |
|
|
62 | # define EV_DEFAULT_A ev_default_loop (0) |
|
|
63 | # define EV_DEFAULT_A_ EV_DEFAULT_A, |
58 | #else |
64 | #else |
59 | # define EV_P void |
65 | # define EV_P void |
60 | # define EV_P_ |
66 | # define EV_P_ |
61 | # define EV_A |
67 | # define EV_A |
62 | # define EV_A_ |
68 | # define EV_A_ |
|
|
69 | # define EV_DEFAULT_A |
|
|
70 | # define EV_DEFAULT_A_ |
63 | #endif |
71 | #endif |
64 | |
72 | |
65 | /* eventmask, revents, events... */ |
73 | /* eventmask, revents, events... */ |
66 | #define EV_UNDEF -1 /* guaranteed to be invalid */ |
74 | #define EV_UNDEF -1 /* guaranteed to be invalid */ |
67 | #define EV_NONE 0x00 |
75 | #define EV_NONE 0x00 |
68 | #define EV_READ 0x01 |
76 | #define EV_READ 0x01 /* io only */ |
69 | #define EV_WRITE 0x02 |
77 | #define EV_WRITE 0x02 /* io only */ |
70 | #define EV_TIMEOUT 0x000100 |
78 | #define EV_TIMEOUT 0x000100 /* timer only */ |
71 | #define EV_PERIODIC 0x000200 |
79 | #define EV_PERIODIC 0x000200 /* periodic timer only */ |
72 | #define EV_SIGNAL 0x000400 |
80 | #define EV_SIGNAL 0x000400 /* signal only */ |
73 | #define EV_IDLE 0x000800 |
81 | #define EV_IDLE 0x000800 /* idle only */ |
74 | #define EV_CHECK 0x001000 |
82 | #define EV_CHECK 0x001000 /* check only */ |
75 | #define EV_PREPARE 0x002000 |
83 | #define EV_PREPARE 0x002000 /* prepare only */ |
76 | #define EV_CHILD 0x004000 |
84 | #define EV_CHILD 0x004000 /* child/pid only */ |
77 | #define EV_ERROR 0x800000 /* sent when an error occurs */ |
85 | #define EV_ERROR 0x800000 /* sent when an error occurs */ |
78 | |
86 | |
79 | /* can be used to add custom fields to all watchers */ |
87 | /* can be used to add custom fields to all watchers, while losing binary compatibility */ |
80 | #ifndef EV_COMMON |
88 | #ifndef EV_COMMON |
81 | # define EV_COMMON void *data |
89 | # define EV_COMMON void *data |
82 | #endif |
90 | #endif |
83 | #ifndef EV_PROTOTYPES |
91 | #ifndef EV_PROTOTYPES |
84 | # define EV_PROTOTYPES 1 |
92 | # define EV_PROTOTYPES 1 |
… | |
… | |
86 | |
94 | |
87 | #define EV_VERSION_MAJOR 1 |
95 | #define EV_VERSION_MAJOR 1 |
88 | #define EV_VERSION_MINOR 1 |
96 | #define EV_VERSION_MINOR 1 |
89 | |
97 | |
90 | #ifndef EV_CB_DECLARE |
98 | #ifndef EV_CB_DECLARE |
91 | # define EV_CB_DECLARE(type) void (*cb)(EV_P_ struct type *w, int revents) |
99 | # define EV_CB_DECLARE(type) void (*cb)(EV_P_ struct type *w, int revents); |
92 | #endif |
100 | #endif |
93 | #ifndef EV_CB_INVOKE |
101 | #ifndef EV_CB_INVOKE |
94 | # define EV_CB_INVOKE(watcher,revents) (watcher)->cb (EV_A_ (watcher), (revents)) |
102 | # define EV_CB_INVOKE(watcher,revents) (watcher)->cb (EV_A_ (watcher), (revents)) |
95 | #endif |
103 | #endif |
96 | |
104 | |
… | |
… | |
210 | /* the presence of this union forces similar struct layout */ |
218 | /* the presence of this union forces similar struct layout */ |
211 | union ev_any_watcher |
219 | union ev_any_watcher |
212 | { |
220 | { |
213 | struct ev_watcher w; |
221 | struct ev_watcher w; |
214 | struct ev_watcher_list wl; |
222 | struct ev_watcher_list wl; |
|
|
223 | |
215 | struct ev_io io; |
224 | struct ev_io io; |
216 | struct ev_timer timer; |
225 | struct ev_timer timer; |
217 | struct ev_periodic periodic; |
226 | struct ev_periodic periodic; |
218 | struct ev_signal signal; |
|
|
219 | struct ev_idle idle; |
227 | struct ev_idle idle; |
220 | struct ev_child child; |
|
|
221 | struct ev_prepare prepare; |
228 | struct ev_prepare prepare; |
222 | struct ev_check check; |
229 | struct ev_check check; |
|
|
230 | struct ev_signal signal; |
|
|
231 | struct ev_child child; |
223 | }; |
232 | }; |
224 | |
233 | |
225 | #define EVMETHOD_AUTO 0 /* consults environment */ |
234 | #define EVMETHOD_AUTO 0 /* consults environment */ |
226 | #define EVMETHOD_SELECT 1 |
235 | #define EVMETHOD_SELECT 1 |
227 | #define EVMETHOD_POLL 2 |
236 | #define EVMETHOD_POLL 2 |
… | |
… | |
259 | |
268 | |
260 | /* create and destroy alternative loops that don't handle signals */ |
269 | /* create and destroy alternative loops that don't handle signals */ |
261 | struct ev_loop *ev_loop_new (int methods); |
270 | struct ev_loop *ev_loop_new (int methods); |
262 | void ev_loop_destroy (EV_P); |
271 | void ev_loop_destroy (EV_P); |
263 | void ev_loop_fork (EV_P); |
272 | void ev_loop_fork (EV_P); |
|
|
273 | |
|
|
274 | ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ |
|
|
275 | |
264 | # else |
276 | # else |
|
|
277 | |
265 | int ev_default_loop (int methods); /* returns true when successful */ |
278 | int ev_default_loop (int methods); /* returns true when successful */ |
|
|
279 | |
|
|
280 | static ev_tstamp |
|
|
281 | ev_now () |
|
|
282 | { |
|
|
283 | extern ev_tstamp ev_rt_now; |
|
|
284 | |
|
|
285 | return ev_rt_now; |
|
|
286 | } |
266 | # endif |
287 | # endif |
267 | |
288 | |
268 | void ev_default_destroy (void); /* destroy the default loop */ |
289 | void ev_default_destroy (void); /* destroy the default loop */ |
269 | /* this needs to be called after fork, to duplicate the default loop */ |
290 | /* this needs to be called after fork, to duplicate the default loop */ |
270 | /* if you create alternative loops you have to call ev_loop_fork on them */ |
291 | /* if you create alternative loops you have to call ev_loop_fork on them */ |
… | |
… | |
281 | #define EVUNLOOP_ALL 2 /* unloop all loops */ |
302 | #define EVUNLOOP_ALL 2 /* unloop all loops */ |
282 | |
303 | |
283 | #if EV_PROTOTYPES |
304 | #if EV_PROTOTYPES |
284 | void ev_loop (EV_P_ int flags); |
305 | void ev_loop (EV_P_ int flags); |
285 | void ev_unloop (EV_P_ int how); /* set to 1 to break out of event loop, set to 2 to break out of all event loops */ |
306 | void ev_unloop (EV_P_ int how); /* set to 1 to break out of event loop, set to 2 to break out of all event loops */ |
286 | |
|
|
287 | ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ |
|
|
288 | |
307 | |
289 | /* |
308 | /* |
290 | * ref/unref can be used to add or remove a refcount on the mainloop. every watcher |
309 | * ref/unref can be used to add or remove a refcount on the mainloop. every watcher |
291 | * keeps one reference. if you have a long-runing watcher you never unregister that |
310 | * keeps one reference. if you have a long-runing watcher you never unregister that |
292 | * should not keep ev_loop from running, unref() after starting, and ref() before stopping. |
311 | * should not keep ev_loop from running, unref() after starting, and ref() before stopping. |
… | |
… | |
353 | void ev_timer_start (EV_P_ struct ev_timer *w); |
372 | void ev_timer_start (EV_P_ struct ev_timer *w); |
354 | void ev_timer_stop (EV_P_ struct ev_timer *w); |
373 | void ev_timer_stop (EV_P_ struct ev_timer *w); |
355 | /* stops if active and no repeat, restarts if active and repeating, starts if inactive and repeating */ |
374 | /* stops if active and no repeat, restarts if active and repeating, starts if inactive and repeating */ |
356 | void ev_timer_again (EV_P_ struct ev_timer *w); |
375 | void ev_timer_again (EV_P_ struct ev_timer *w); |
357 | |
376 | |
|
|
377 | #if EV_PERIODICS |
358 | void ev_periodic_start (EV_P_ struct ev_periodic *w); |
378 | void ev_periodic_start (EV_P_ struct ev_periodic *w); |
359 | void ev_periodic_stop (EV_P_ struct ev_periodic *w); |
379 | void ev_periodic_stop (EV_P_ struct ev_periodic *w); |
360 | void ev_periodic_again (EV_P_ struct ev_periodic *w); |
380 | void ev_periodic_again (EV_P_ struct ev_periodic *w); |
|
|
381 | #endif |
361 | |
382 | |
362 | void ev_idle_start (EV_P_ struct ev_idle *w); |
383 | void ev_idle_start (EV_P_ struct ev_idle *w); |
363 | void ev_idle_stop (EV_P_ struct ev_idle *w); |
384 | void ev_idle_stop (EV_P_ struct ev_idle *w); |
364 | |
385 | |
365 | void ev_prepare_start (EV_P_ struct ev_prepare *w); |
386 | void ev_prepare_start (EV_P_ struct ev_prepare *w); |