… | |
… | |
54 | |
54 | |
55 | #ifndef EV_STAT_ENABLE |
55 | #ifndef EV_STAT_ENABLE |
56 | # define EV_STAT_ENABLE 1 |
56 | # define EV_STAT_ENABLE 1 |
57 | #endif |
57 | #endif |
58 | |
58 | |
|
|
59 | #ifndef EV_IDLE_ENABLE |
|
|
60 | # define EV_IDLE_ENABLE 1 |
|
|
61 | #endif |
|
|
62 | |
59 | #ifndef EV_FORK_ENABLE |
63 | #ifndef EV_FORK_ENABLE |
60 | # define EV_FORK_ENABLE 1 |
64 | # define EV_FORK_ENABLE 1 |
61 | #endif |
65 | #endif |
62 | |
66 | |
63 | #ifndef EV_EMBED_ENABLE |
67 | #ifndef EV_EMBED_ENABLE |
… | |
… | |
216 | int rstatus; /* rw, holds the exit status, use the macros from sys/wait.h */ |
220 | int rstatus; /* rw, holds the exit status, use the macros from sys/wait.h */ |
217 | } ev_child; |
221 | } ev_child; |
218 | |
222 | |
219 | #if EV_STAT_ENABLE |
223 | #if EV_STAT_ENABLE |
220 | /* st_nlink = 0 means missing file or other error */ |
224 | /* st_nlink = 0 means missing file or other error */ |
221 | #ifdef _WIN32 |
225 | # ifdef _WIN32 |
222 | typedef struct _stati64 ev_statdata; |
226 | typedef struct _stati64 ev_statdata; |
223 | #else |
227 | # else |
224 | typedef struct stat ev_statdata; |
228 | typedef struct stat ev_statdata; |
225 | #endif |
229 | # endif |
226 | |
230 | |
227 | /* invoked each time the stat data changes for a given path */ |
231 | /* invoked each time the stat data changes for a given path */ |
228 | /* revent EV_STAT */ |
232 | /* revent EV_STAT */ |
229 | typedef struct ev_stat |
233 | typedef struct ev_stat |
230 | { |
234 | { |
231 | EV_WATCHER (ev_stat) |
235 | EV_WATCHER_LIST (ev_stat) |
232 | |
236 | |
233 | ev_timer timer; /* private */ |
237 | ev_timer timer; /* private */ |
234 | ev_tstamp interval; /* ro */ |
238 | ev_tstamp interval; /* ro */ |
235 | const char *path; /* ro */ |
239 | const char *path; /* ro */ |
236 | ev_statdata prev; /* ro */ |
240 | ev_statdata prev; /* ro */ |
237 | ev_statdata attr; /* ro */ |
241 | ev_statdata attr; /* ro */ |
|
|
242 | |
|
|
243 | int wd; /* wd for inotify, fd for kqueue */ |
238 | } ev_stat; |
244 | } ev_stat; |
239 | #endif |
245 | #endif |
240 | |
246 | |
|
|
247 | #if EV_IDLE_ENABLE |
241 | /* invoked when the nothing else needs to be done, keeps the process from blocking */ |
248 | /* invoked when the nothing else needs to be done, keeps the process from blocking */ |
242 | /* revent EV_IDLE */ |
249 | /* revent EV_IDLE */ |
243 | typedef struct ev_idle |
250 | typedef struct ev_idle |
244 | { |
251 | { |
245 | EV_WATCHER (ev_idle) |
252 | EV_WATCHER (ev_idle) |
246 | } ev_idle; |
253 | } ev_idle; |
|
|
254 | #endif |
247 | |
255 | |
248 | /* invoked for each run of the mainloop, just before the blocking call */ |
256 | /* invoked for each run of the mainloop, just before the blocking call */ |
249 | /* you can still change events in any way you like */ |
257 | /* you can still change events in any way you like */ |
250 | /* revent EV_PREPARE */ |
258 | /* revent EV_PREPARE */ |
251 | typedef struct ev_prepare |
259 | typedef struct ev_prepare |
… | |
… | |
292 | struct ev_signal signal; |
300 | struct ev_signal signal; |
293 | struct ev_child child; |
301 | struct ev_child child; |
294 | #if EV_STAT_ENABLE |
302 | #if EV_STAT_ENABLE |
295 | struct ev_stat stat; |
303 | struct ev_stat stat; |
296 | #endif |
304 | #endif |
|
|
305 | #if EV_IDLE_ENABLE |
297 | struct ev_idle idle; |
306 | struct ev_idle idle; |
|
|
307 | #endif |
298 | struct ev_prepare prepare; |
308 | struct ev_prepare prepare; |
299 | struct ev_check check; |
309 | struct ev_check check; |
300 | #if EV_FORK_ENABLE |
310 | #if EV_FORK_ENABLE |
301 | struct ev_fork fork; |
311 | struct ev_fork fork; |
302 | #endif |
312 | #endif |
… | |
… | |
308 | /* bits for ev_default_loop and ev_loop_new */ |
318 | /* bits for ev_default_loop and ev_loop_new */ |
309 | /* the default */ |
319 | /* the default */ |
310 | #define EVFLAG_AUTO 0x00000000UL /* not quite a mask */ |
320 | #define EVFLAG_AUTO 0x00000000UL /* not quite a mask */ |
311 | /* flag bits */ |
321 | /* flag bits */ |
312 | #define EVFLAG_NOENV 0x01000000UL /* do NOT consult environment */ |
322 | #define EVFLAG_NOENV 0x01000000UL /* do NOT consult environment */ |
|
|
323 | #define EVFLAG_FORKCHECK 0x02000000UL /* check for a fork in each iteration */ |
313 | /* method bits to be ored together */ |
324 | /* method bits to be ored together */ |
314 | #define EVBACKEND_SELECT 0x00000001UL /* about anywhere */ |
325 | #define EVBACKEND_SELECT 0x00000001UL /* about anywhere */ |
315 | #define EVBACKEND_POLL 0x00000002UL /* !win */ |
326 | #define EVBACKEND_POLL 0x00000002UL /* !win */ |
316 | #define EVBACKEND_EPOLL 0x00000004UL /* linux */ |
327 | #define EVBACKEND_EPOLL 0x00000004UL /* linux */ |
317 | #define EVBACKEND_KQUEUE 0x00000008UL /* bsd */ |
328 | #define EVBACKEND_KQUEUE 0x00000008UL /* bsd */ |
… | |
… | |
383 | /* you can call it in either the parent or the child */ |
394 | /* you can call it in either the parent or the child */ |
384 | /* you can actually call it at any time, anywhere :) */ |
395 | /* you can actually call it at any time, anywhere :) */ |
385 | void ev_default_fork (void); |
396 | void ev_default_fork (void); |
386 | |
397 | |
387 | unsigned int ev_backend (EV_P); |
398 | unsigned int ev_backend (EV_P); |
|
|
399 | unsigned int ev_loop_count (EV_P); |
388 | #endif |
400 | #endif |
389 | |
401 | |
390 | #define EVLOOP_NONBLOCK 1 /* do not block/wait */ |
402 | #define EVLOOP_NONBLOCK 1 /* do not block/wait */ |
391 | #define EVLOOP_ONESHOT 2 /* block *once* only */ |
403 | #define EVLOOP_ONESHOT 2 /* block *once* only */ |
392 | #define EVUNLOOP_CANCEL 0 /* undo unloop */ |
404 | #define EVUNLOOP_CANCEL 0 /* undo unloop */ |
… | |
… | |
410 | void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg); |
422 | void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg); |
411 | #endif |
423 | #endif |
412 | |
424 | |
413 | /* these may evaluate ev multiple times, and the other arguments at most once */ |
425 | /* these may evaluate ev multiple times, and the other arguments at most once */ |
414 | /* either use ev_init + ev_TYPE_set, or the ev_TYPE_init macro, below, to first initialise a watcher */ |
426 | /* either use ev_init + ev_TYPE_set, or the ev_TYPE_init macro, below, to first initialise a watcher */ |
415 | #define ev_init(ev,cb_) do { \ |
427 | #define ev_init(ev,cb_) do { \ |
416 | ((ev_watcher *)(void *)(ev))->active = \ |
428 | ((ev_watcher *)(void *)(ev))->active = \ |
417 | ((ev_watcher *)(void *)(ev))->pending = \ |
429 | ((ev_watcher *)(void *)(ev))->pending = \ |
418 | ((ev_watcher *)(void *)(ev))->priority = 0; \ |
430 | ((ev_watcher *)(void *)(ev))->priority = 0; \ |
419 | ev_set_cb ((ev), cb_); \ |
431 | ev_set_cb ((ev), cb_); \ |
420 | } while (0) |
432 | } while (0) |
421 | |
433 | |
422 | #define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0) |
434 | #define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_); } while (0) |
423 | #define ev_timer_set(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); } while (0) |
435 | #define ev_timer_set(ev,after_,repeat_) do { (ev)->at = (after_); (ev)->repeat = (repeat_); } while (0) |
424 | #define ev_periodic_set(ev,at_,ival_,res_) do { (ev)->at = (at_); (ev)->interval = (ival_); (ev)->reschedule_cb= (res_); } while (0) |
436 | #define ev_periodic_set(ev,at_,ival_,res_) do { (ev)->at = (at_); (ev)->interval = (ival_); (ev)->reschedule_cb= (res_); } while (0) |
425 | #define ev_signal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0) |
437 | #define ev_signal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0) |
426 | #define ev_child_set(ev,pid_) do { (ev)->pid = (pid_); } while (0) |
438 | #define ev_child_set(ev,pid_) do { (ev)->pid = (pid_); } while (0) |
427 | #define ev_stat_set(ev,path_,interval_) do { (ev)->path = (path_); (ev)->interval = (interval_); } while (0) |
439 | #define ev_stat_set(ev,path_,interval_) do { (ev)->path = (path_); (ev)->interval = (interval_); (ev)->wd = -2; } while (0) |
428 | #define ev_idle_set(ev) /* nop, yes, this is a serious in-joke */ |
440 | #define ev_idle_set(ev) /* nop, yes, this is a serious in-joke */ |
429 | #define ev_prepare_set(ev) /* nop, yes, this is a serious in-joke */ |
441 | #define ev_prepare_set(ev) /* nop, yes, this is a serious in-joke */ |
430 | #define ev_check_set(ev) /* nop, yes, this is a serious in-joke */ |
442 | #define ev_check_set(ev) /* nop, yes, this is a serious in-joke */ |
431 | #define ev_embed_set(ev,loop_) do { (ev)->loop = (loop_); } while (0) |
443 | #define ev_embed_set(ev,loop_) do { (ev)->loop = (loop_); } while (0) |
432 | #define ev_fork_set(ev) /* nop, yes, this is a serious in-joke */ |
444 | #define ev_fork_set(ev) /* nop, yes, this is a serious in-joke */ |
… | |
… | |
444 | #define ev_fork_init(ev,cb) do { ev_init ((ev), (cb)); ev_fork_set ((ev)); } while (0) |
456 | #define ev_fork_init(ev,cb) do { ev_init ((ev), (cb)); ev_fork_set ((ev)); } while (0) |
445 | |
457 | |
446 | #define ev_is_pending(ev) (0 + ((ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */ |
458 | #define ev_is_pending(ev) (0 + ((ev_watcher *)(void *)(ev))->pending) /* ro, true when watcher is waiting for callback invocation */ |
447 | #define ev_is_active(ev) (0 + ((ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */ |
459 | #define ev_is_active(ev) (0 + ((ev_watcher *)(void *)(ev))->active) /* ro, true when the watcher has been started */ |
448 | |
460 | |
449 | #define ev_priority(ev) ((ev_watcher *)(void *)(ev))->priority /* rw */ |
461 | #define ev_priority(ev) ((((ev_watcher *)(void *)(ev))->priority) + 0) |
450 | #define ev_cb(ev) (ev)->cb /* rw */ |
462 | #define ev_cb(ev) (ev)->cb /* rw */ |
451 | #define ev_set_priority(ev,pri) ev_priority (ev) = (pri) |
463 | #define ev_set_priority(ev,pri) ((ev_watcher *)(void *)(ev))->priority = (pri) |
452 | |
464 | |
453 | #ifndef ev_set_cb |
465 | #ifndef ev_set_cb |
454 | # define ev_set_cb(ev,cb_) ev_cb (ev) = (cb_) |
466 | # define ev_set_cb(ev,cb_) ev_cb (ev) = (cb_) |
455 | #endif |
467 | #endif |
456 | |
468 | |
… | |
… | |
461 | /* feeds an event into a watcher as if the event actually occured */ |
473 | /* feeds an event into a watcher as if the event actually occured */ |
462 | /* accepts any ev_watcher type */ |
474 | /* accepts any ev_watcher type */ |
463 | void ev_feed_event (EV_P_ void *w, int revents); |
475 | void ev_feed_event (EV_P_ void *w, int revents); |
464 | void ev_feed_fd_event (EV_P_ int fd, int revents); |
476 | void ev_feed_fd_event (EV_P_ int fd, int revents); |
465 | void ev_feed_signal_event (EV_P_ int signum); |
477 | void ev_feed_signal_event (EV_P_ int signum); |
|
|
478 | int ev_clear_pending (EV_P_ void *w); |
466 | |
479 | |
467 | void ev_io_start (EV_P_ ev_io *w); |
480 | void ev_io_start (EV_P_ ev_io *w); |
468 | void ev_io_stop (EV_P_ ev_io *w); |
481 | void ev_io_stop (EV_P_ ev_io *w); |
469 | |
482 | |
470 | void ev_timer_start (EV_P_ ev_timer *w); |
483 | void ev_timer_start (EV_P_ ev_timer *w); |
… | |
… | |
490 | void ev_stat_start (EV_P_ ev_stat *w); |
503 | void ev_stat_start (EV_P_ ev_stat *w); |
491 | void ev_stat_stop (EV_P_ ev_stat *w); |
504 | void ev_stat_stop (EV_P_ ev_stat *w); |
492 | void ev_stat_stat (EV_P_ ev_stat *w); |
505 | void ev_stat_stat (EV_P_ ev_stat *w); |
493 | # endif |
506 | # endif |
494 | |
507 | |
|
|
508 | # if EV_IDLE_ENABLE |
495 | void ev_idle_start (EV_P_ ev_idle *w); |
509 | void ev_idle_start (EV_P_ ev_idle *w); |
496 | void ev_idle_stop (EV_P_ ev_idle *w); |
510 | void ev_idle_stop (EV_P_ ev_idle *w); |
|
|
511 | # endif |
497 | |
512 | |
498 | void ev_prepare_start (EV_P_ ev_prepare *w); |
513 | void ev_prepare_start (EV_P_ ev_prepare *w); |
499 | void ev_prepare_stop (EV_P_ ev_prepare *w); |
514 | void ev_prepare_stop (EV_P_ ev_prepare *w); |
500 | |
515 | |
501 | void ev_check_start (EV_P_ ev_check *w); |
516 | void ev_check_start (EV_P_ ev_check *w); |