… | |
… | |
42 | #endif |
42 | #endif |
43 | #ifndef EV_MAXPRI |
43 | #ifndef EV_MAXPRI |
44 | # define EV_MAXPRI +2 |
44 | # define EV_MAXPRI +2 |
45 | #endif |
45 | #endif |
46 | |
46 | |
|
|
47 | #ifndef EV_MULTIPLICITY |
|
|
48 | # define EV_MULTIPLICITY 1 |
|
|
49 | #endif |
|
|
50 | |
|
|
51 | /* support multiple event loops? */ |
|
|
52 | #if EV_MULTIPLICITY |
|
|
53 | struct ev_loop; |
|
|
54 | # define EV_P struct ev_loop *loop |
|
|
55 | # define EV_P_ EV_P, |
|
|
56 | # define EV_A loop |
|
|
57 | # define EV_A_ EV_A, |
|
|
58 | #else |
47 | #define EV_P void |
59 | # define EV_P void |
48 | #define EV_P_ |
60 | # define EV_P_ |
49 | #define EV_A |
61 | # define EV_A |
50 | #define EV_A_ |
62 | # define EV_A_ |
|
|
63 | #endif |
51 | |
64 | |
52 | /* eventmask, revents, events... */ |
65 | /* eventmask, revents, events... */ |
53 | #define EV_UNDEF -1 /* guaranteed to be invalid */ |
66 | #define EV_UNDEF -1 /* guaranteed to be invalid */ |
54 | #define EV_NONE 0x00 |
67 | #define EV_NONE 0x00 |
55 | #define EV_READ 0x01 |
68 | #define EV_READ 0x01 |
… | |
… | |
143 | /* invoked when the given signal has been received */ |
156 | /* invoked when the given signal has been received */ |
144 | /* revent EV_SIGNAL */ |
157 | /* revent EV_SIGNAL */ |
145 | struct ev_signal |
158 | struct ev_signal |
146 | { |
159 | { |
147 | EV_WATCHER_LIST (ev_signal); |
160 | EV_WATCHER_LIST (ev_signal); |
|
|
161 | #if EV_MULTIPLICITY |
|
|
162 | struct ev_loop *loop; |
|
|
163 | #endif |
148 | |
164 | |
149 | int signum; /* ro */ |
165 | int signum; /* ro */ |
150 | }; |
166 | }; |
151 | |
167 | |
152 | /* invoked when the nothing else needs to be done, keeps the process from blocking */ |
168 | /* invoked when the nothing else needs to be done, keeps the process from blocking */ |
… | |
… | |
189 | #define EVMETHOD_EPOLL 4 |
205 | #define EVMETHOD_EPOLL 4 |
190 | #define EVMETHOD_KQUEUE 8 |
206 | #define EVMETHOD_KQUEUE 8 |
191 | #define EVMETHOD_DEVPOLL 16 /* NYI */ |
207 | #define EVMETHOD_DEVPOLL 16 /* NYI */ |
192 | #define EVMETHOD_PORT 32 /* NYI */ |
208 | #define EVMETHOD_PORT 32 /* NYI */ |
193 | #define EVMETHOD_ANY ~0 /* any method, do not consult env */ |
209 | #define EVMETHOD_ANY ~0 /* any method, do not consult env */ |
|
|
210 | |
194 | #if EV_PROTOTYPES |
211 | #if EV_PROTOTYPES |
195 | int ev_method (EV_P); |
|
|
196 | int ev_init (EV_P_ int methods); /* returns ev_method */ |
|
|
197 | int ev_version_major (void); |
212 | int ev_version_major (void); |
198 | int ev_version_minor (void); |
213 | int ev_version_minor (void); |
199 | |
214 | |
200 | /* these three calls are suitable for plugging into pthread_atfork */ |
|
|
201 | void ev_fork_prepare (void); |
|
|
202 | void ev_fork_parent (void); |
|
|
203 | void ev_fork_child (void); |
|
|
204 | |
|
|
205 | ev_tstamp ev_time (void); |
215 | ev_tstamp ev_time (void); |
|
|
216 | |
|
|
217 | # if EV_MULTIPLICITY |
|
|
218 | /* the default loop is the only one that handles signals and child watchers */ |
|
|
219 | /* you can call this as often as you like */ |
|
|
220 | struct ev_loop *ev_default_loop (int methods); /* returns default loop */ |
|
|
221 | |
|
|
222 | /* create and destroy alternative loops that don't handle signals */ |
|
|
223 | struct ev_loop *ev_loop_new (int methods); |
|
|
224 | void ev_loop_destroy (EV_P); |
|
|
225 | void ev_loop_fork (EV_P); |
|
|
226 | # else |
|
|
227 | int ev_default_loop (int methods); /* returns true when successful */ |
|
|
228 | # endif |
|
|
229 | |
|
|
230 | void ev_default_destroy (void); /* destroy the default loop */ |
|
|
231 | /* this needs to be called after fork, to duplicate the default loop */ |
|
|
232 | /* if you create alternative loops you have to call ev_loop_fork on them */ |
|
|
233 | /* you can call it in either the parent or the child */ |
|
|
234 | /* you can actually call it at any time, anywhere :) */ |
|
|
235 | void ev_default_fork (void); |
|
|
236 | |
|
|
237 | int ev_method (EV_P); |
206 | #endif |
238 | #endif |
207 | |
239 | |
208 | #define EVLOOP_NONBLOCK 1 /* do not block/wait */ |
240 | #define EVLOOP_NONBLOCK 1 /* do not block/wait */ |
209 | #define EVLOOP_ONESHOT 2 /* block *once* only */ |
241 | #define EVLOOP_ONESHOT 2 /* block *once* only */ |
|
|
242 | #define EVUNLOOP_ONCE 1 /* unloop once */ |
|
|
243 | #define EVUNLOOP_ALL 2 /* unloop all loops */ |
|
|
244 | |
210 | #if EV_PROTOTYPES |
245 | #if EV_PROTOTYPES |
211 | void ev_loop (EV_P_ int flags); |
246 | void ev_loop (EV_P_ int flags); |
212 | void ev_unloop (EV_P_ int status); /* set to 1 to break out of event loop, set to 2 to break out of all event loops */ |
247 | 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 */ |
213 | |
248 | |
214 | ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ |
249 | ev_tstamp ev_now (EV_P); /* time w.r.t. timers and the eventloop, updated after each poll */ |
215 | |
250 | |
216 | /* |
251 | /* |
217 | * ref/unref can be used to add or remove a refcount on the mainloop. every watcher |
252 | * ref/unref can be used to add or remove a refcount on the mainloop. every watcher |
… | |
… | |
246 | #define ev_idle_init(ev,cb) do { ev_watcher_init ((ev), (cb)); ev_idle_set ((ev)); } while (0) |
281 | #define ev_idle_init(ev,cb) do { ev_watcher_init ((ev), (cb)); ev_idle_set ((ev)); } while (0) |
247 | #define ev_prepare_init(ev,cb) do { ev_watcher_init ((ev), (cb)); ev_prepare_set ((ev)); } while (0) |
282 | #define ev_prepare_init(ev,cb) do { ev_watcher_init ((ev), (cb)); ev_prepare_set ((ev)); } while (0) |
248 | #define ev_check_init(ev,cb) do { ev_watcher_init ((ev), (cb)); ev_check_set ((ev)); } while (0) |
283 | #define ev_check_init(ev,cb) do { ev_watcher_init ((ev), (cb)); ev_check_set ((ev)); } while (0) |
249 | #define ev_child_init(ev,cb,pid) do { ev_watcher_init ((ev), (cb)); ev_child_set ((ev),(pid)); } while (0) |
284 | #define ev_child_init(ev,cb,pid) do { ev_watcher_init ((ev), (cb)); ev_child_set ((ev),(pid)); } while (0) |
250 | |
285 | |
|
|
286 | #define ev_is_pending(ev) (0 + (ev)->pending) /* true when watcher is waiting for callback invocation */ |
251 | #define ev_is_active(ev) (0 + (ev)->active) /* true when the watcher has been started */ |
287 | #define ev_is_active(ev) (0 + (ev)->active) /* true when the watcher has been started */ |
252 | #define ev_set_priority(ev,pri) (ev)->priority = pri |
288 | #define ev_set_priority(ev,pri) (ev)->priority = pri |
253 | |
289 | |
254 | /* stopping (enabling, adding) a watcher does nothing if it is already running */ |
290 | /* stopping (enabling, adding) a watcher does nothing if it is already running */ |
255 | /* stopping (disabling, deleting) a watcher does nothing unless its already running */ |
291 | /* stopping (disabling, deleting) a watcher does nothing unless its already running */ |
… | |
… | |
257 | void ev_io_start (EV_P_ struct ev_io *w); |
293 | void ev_io_start (EV_P_ struct ev_io *w); |
258 | void ev_io_stop (EV_P_ struct ev_io *w); |
294 | void ev_io_stop (EV_P_ struct ev_io *w); |
259 | |
295 | |
260 | void ev_timer_start (EV_P_ struct ev_timer *w); |
296 | void ev_timer_start (EV_P_ struct ev_timer *w); |
261 | void ev_timer_stop (EV_P_ struct ev_timer *w); |
297 | void ev_timer_stop (EV_P_ struct ev_timer *w); |
262 | void ev_timer_again (EV_P_ struct ev_timer *w); /* stops if active and no repeat, restarts if active and repeating, starts if inactive and repeating */ |
298 | /* stops if active and no repeat, restarts if active and repeating, starts if inactive and repeating */ |
|
|
299 | void ev_timer_again (EV_P_ struct ev_timer *w); |
263 | |
300 | |
264 | void ev_periodic_start (EV_P_ struct ev_periodic *w); |
301 | void ev_periodic_start (EV_P_ struct ev_periodic *w); |
265 | void ev_periodic_stop (EV_P_ struct ev_periodic *w); |
302 | void ev_periodic_stop (EV_P_ struct ev_periodic *w); |
266 | |
303 | |
|
|
304 | void ev_idle_start (EV_P_ struct ev_idle *w); |
|
|
305 | void ev_idle_stop (EV_P_ struct ev_idle *w); |
|
|
306 | |
|
|
307 | void ev_prepare_start (EV_P_ struct ev_prepare *w); |
|
|
308 | void ev_prepare_stop (EV_P_ struct ev_prepare *w); |
|
|
309 | |
|
|
310 | void ev_check_start (EV_P_ struct ev_check *w); |
|
|
311 | void ev_check_stop (EV_P_ struct ev_check *w); |
|
|
312 | |
|
|
313 | /* only supported in the default loop */ |
267 | void ev_signal_start (EV_P_ struct ev_signal *w); |
314 | void ev_signal_start (EV_P_ struct ev_signal *w); |
268 | void ev_signal_stop (EV_P_ struct ev_signal *w); |
315 | void ev_signal_stop (EV_P_ struct ev_signal *w); |
269 | |
316 | |
270 | void ev_idle_start (EV_P_ struct ev_idle *w); |
317 | /* only supported in the default loop */ |
271 | void ev_idle_stop (EV_P_ struct ev_idle *w); |
|
|
272 | |
|
|
273 | void ev_prepare_start (EV_P_ struct ev_prepare *w); |
|
|
274 | void ev_prepare_stop (EV_P_ struct ev_prepare *w); |
|
|
275 | |
|
|
276 | void ev_check_start (EV_P_ struct ev_check *w); |
|
|
277 | void ev_check_stop (EV_P_ struct ev_check *w); |
|
|
278 | |
|
|
279 | void ev_child_start (EV_P_ struct ev_child *w); |
318 | void ev_child_start (EV_P_ struct ev_child *w); |
280 | void ev_child_stop (EV_P_ struct ev_child *w); |
319 | void ev_child_stop (EV_P_ struct ev_child *w); |
281 | #endif |
320 | #endif |
282 | |
321 | |
283 | #ifdef __cplusplus |
322 | #ifdef __cplusplus |