… | |
… | |
213 | #endif |
213 | #endif |
214 | |
214 | |
215 | /*****************************************************************************/ |
215 | /*****************************************************************************/ |
216 | |
216 | |
217 | #define EV_VERSION_MAJOR 4 |
217 | #define EV_VERSION_MAJOR 4 |
218 | #define EV_VERSION_MINOR 27 |
218 | #define EV_VERSION_MINOR 31 |
219 | |
219 | |
220 | /* eventmask, revents, events... */ |
220 | /* eventmask, revents, events... */ |
221 | enum { |
221 | enum { |
222 | EV_UNDEF = (int)0xFFFFFFFF, /* guaranteed to be invalid */ |
222 | EV_UNDEF = (int)0xFFFFFFFF, /* guaranteed to be invalid */ |
223 | EV_NONE = 0x00, /* no events */ |
223 | EV_NONE = 0x00, /* no events */ |
… | |
… | |
390 | |
390 | |
391 | int wd; /* wd for inotify, fd for kqueue */ |
391 | int wd; /* wd for inotify, fd for kqueue */ |
392 | } ev_stat; |
392 | } ev_stat; |
393 | #endif |
393 | #endif |
394 | |
394 | |
395 | #if EV_IDLE_ENABLE |
|
|
396 | /* invoked when the nothing else needs to be done, keeps the process from blocking */ |
395 | /* invoked when the nothing else needs to be done, keeps the process from blocking */ |
397 | /* revent EV_IDLE */ |
396 | /* revent EV_IDLE */ |
398 | typedef struct ev_idle |
397 | typedef struct ev_idle |
399 | { |
398 | { |
400 | EV_WATCHER (ev_idle) |
399 | EV_WATCHER (ev_idle) |
401 | } ev_idle; |
400 | } ev_idle; |
402 | #endif |
|
|
403 | |
401 | |
404 | /* invoked for each run of the mainloop, just before the blocking call */ |
402 | /* invoked for each run of the mainloop, just before the blocking call */ |
405 | /* you can still change events in any way you like */ |
403 | /* you can still change events in any way you like */ |
406 | /* revent EV_PREPARE */ |
404 | /* revent EV_PREPARE */ |
407 | typedef struct ev_prepare |
405 | typedef struct ev_prepare |
… | |
… | |
414 | typedef struct ev_check |
412 | typedef struct ev_check |
415 | { |
413 | { |
416 | EV_WATCHER (ev_check) |
414 | EV_WATCHER (ev_check) |
417 | } ev_check; |
415 | } ev_check; |
418 | |
416 | |
419 | #if EV_FORK_ENABLE |
|
|
420 | /* the callback gets invoked before check in the child process when a fork was detected */ |
417 | /* the callback gets invoked before check in the child process when a fork was detected */ |
421 | /* revent EV_FORK */ |
418 | /* revent EV_FORK */ |
422 | typedef struct ev_fork |
419 | typedef struct ev_fork |
423 | { |
420 | { |
424 | EV_WATCHER (ev_fork) |
421 | EV_WATCHER (ev_fork) |
425 | } ev_fork; |
422 | } ev_fork; |
426 | #endif |
|
|
427 | |
423 | |
428 | #if EV_CLEANUP_ENABLE |
|
|
429 | /* is invoked just before the loop gets destroyed */ |
424 | /* is invoked just before the loop gets destroyed */ |
430 | /* revent EV_CLEANUP */ |
425 | /* revent EV_CLEANUP */ |
431 | typedef struct ev_cleanup |
426 | typedef struct ev_cleanup |
432 | { |
427 | { |
433 | EV_WATCHER (ev_cleanup) |
428 | EV_WATCHER (ev_cleanup) |
434 | } ev_cleanup; |
429 | } ev_cleanup; |
435 | #endif |
|
|
436 | |
430 | |
437 | #if EV_EMBED_ENABLE |
431 | #if EV_EMBED_ENABLE |
438 | /* used to embed an event loop inside another */ |
432 | /* used to embed an event loop inside another */ |
439 | /* the callback gets invoked when the event loop has handled events, and can be 0 */ |
433 | /* the callback gets invoked when the event loop has handled events, and can be 0 */ |
440 | typedef struct ev_embed |
434 | typedef struct ev_embed |
441 | { |
435 | { |
442 | EV_WATCHER (ev_embed) |
436 | EV_WATCHER (ev_embed) |
443 | |
437 | |
444 | struct ev_loop *other; /* ro */ |
438 | struct ev_loop *other; /* ro */ |
|
|
439 | #undef EV_IO_ENABLE |
|
|
440 | #define EV_IO_ENABLE 1 |
445 | ev_io io; /* private */ |
441 | ev_io io; /* private */ |
|
|
442 | #undef EV_PREPARE_ENABLE |
|
|
443 | #define EV_PREPARE_ENABLE 1 |
446 | ev_prepare prepare; /* private */ |
444 | ev_prepare prepare; /* private */ |
447 | ev_check check; /* unused */ |
445 | ev_check check; /* unused */ |
448 | ev_timer timer; /* unused */ |
446 | ev_timer timer; /* unused */ |
449 | ev_periodic periodic; /* unused */ |
447 | ev_periodic periodic; /* unused */ |
450 | ev_idle idle; /* unused */ |
448 | ev_idle idle; /* unused */ |
451 | ev_fork fork; /* private */ |
449 | ev_fork fork; /* private */ |
452 | #if EV_CLEANUP_ENABLE |
|
|
453 | ev_cleanup cleanup; /* unused */ |
450 | ev_cleanup cleanup; /* unused */ |
454 | #endif |
|
|
455 | } ev_embed; |
451 | } ev_embed; |
456 | #endif |
452 | #endif |
457 | |
453 | |
458 | #if EV_ASYNC_ENABLE |
454 | #if EV_ASYNC_ENABLE |
459 | /* invoked when somebody calls ev_async_send on the watcher */ |
455 | /* invoked when somebody calls ev_async_send on the watcher */ |
… | |
… | |
502 | }; |
498 | }; |
503 | |
499 | |
504 | /* flag bits for ev_default_loop and ev_loop_new */ |
500 | /* flag bits for ev_default_loop and ev_loop_new */ |
505 | enum { |
501 | enum { |
506 | /* the default */ |
502 | /* the default */ |
507 | EVFLAG_AUTO = 0x00000000U, /* not quite a mask */ |
503 | EVFLAG_AUTO = 0x00000000U, /* not quite a mask */ |
508 | /* flag bits */ |
504 | /* flag bits */ |
509 | EVFLAG_NOENV = 0x01000000U, /* do NOT consult environment */ |
505 | EVFLAG_NOENV = 0x01000000U, /* do NOT consult environment */ |
510 | EVFLAG_FORKCHECK = 0x02000000U, /* check for a fork in each iteration */ |
506 | EVFLAG_FORKCHECK = 0x02000000U, /* check for a fork in each iteration */ |
511 | /* debugging/feature disable */ |
507 | /* debugging/feature disable */ |
512 | EVFLAG_NOINOTIFY = 0x00100000U, /* do not attempt to use inotify */ |
508 | EVFLAG_NOINOTIFY = 0x00100000U, /* do not attempt to use inotify */ |
513 | #if EV_COMPAT3 |
509 | #if EV_COMPAT3 |
514 | EVFLAG_NOSIGFD = 0, /* compatibility to pre-3.9 */ |
510 | EVFLAG_NOSIGFD = 0, /* compatibility to pre-3.9 */ |
515 | #endif |
511 | #endif |
516 | EVFLAG_SIGNALFD = 0x00200000U, /* attempt to use signalfd */ |
512 | EVFLAG_SIGNALFD = 0x00200000U, /* attempt to use signalfd */ |
517 | EVFLAG_NOSIGMASK = 0x00400000U /* avoid modifying the signal mask */ |
513 | EVFLAG_NOSIGMASK = 0x00400000U, /* avoid modifying the signal mask */ |
|
|
514 | EVFLAG_NOTIMERFD = 0x00800000U /* avoid creating a timerfd */ |
518 | }; |
515 | }; |
519 | |
516 | |
520 | /* method bits to be ored together */ |
517 | /* method bits to be ored together */ |
521 | enum { |
518 | enum { |
522 | EVBACKEND_SELECT = 0x00000001U, /* available just about anywhere */ |
519 | EVBACKEND_SELECT = 0x00000001U, /* available just about anywhere */ |
523 | EVBACKEND_POLL = 0x00000002U, /* !win, !aix, broken on osx */ |
520 | EVBACKEND_POLL = 0x00000002U, /* !win, !aix, broken on osx */ |
524 | EVBACKEND_EPOLL = 0x00000004U, /* linux */ |
521 | EVBACKEND_EPOLL = 0x00000004U, /* linux */ |
525 | EVBACKEND_KQUEUE = 0x00000008U, /* bsd, broken on osx */ |
522 | EVBACKEND_KQUEUE = 0x00000008U, /* bsd, broken on osx */ |
526 | EVBACKEND_DEVPOLL = 0x00000010U, /* solaris 8 */ /* NYI */ |
523 | EVBACKEND_DEVPOLL = 0x00000010U, /* solaris 8 */ /* NYI */ |
527 | EVBACKEND_PORT = 0x00000020U, /* solaris 10 */ |
524 | EVBACKEND_PORT = 0x00000020U, /* solaris 10 */ |
528 | EVBACKEND_LINUXAIO = 0x00000040U, /* linuix AIO, 4.19+ */ |
525 | EVBACKEND_LINUXAIO = 0x00000040U, /* linux AIO, 4.19+ */ |
529 | EVBACKEND_IOURING = 0x00000080U, /* linux io_uring, 5.1+ */ |
526 | EVBACKEND_IOURING = 0x00000080U, /* linux io_uring, 5.1+ */ |
530 | EVBACKEND_ALL = 0x000000FFU, /* all known backends */ |
527 | EVBACKEND_ALL = 0x000000FFU, /* all known backends */ |
531 | EVBACKEND_MASK = 0x0000FFFFU /* all future backends */ |
528 | EVBACKEND_MASK = 0x0000FFFFU /* all future backends */ |
532 | }; |
529 | }; |
533 | |
530 | |
… | |
… | |
657 | * convenience function, wait for a single event, without registering an event watcher |
654 | * convenience function, wait for a single event, without registering an event watcher |
658 | * if timeout is < 0, do wait indefinitely |
655 | * if timeout is < 0, do wait indefinitely |
659 | */ |
656 | */ |
660 | EV_API_DECL void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT; |
657 | EV_API_DECL void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT; |
661 | |
658 | |
|
|
659 | EV_API_DECL void ev_invoke_pending (EV_P); /* invoke all pending watchers */ |
|
|
660 | |
662 | # if EV_FEATURE_API |
661 | # if EV_FEATURE_API |
663 | EV_API_DECL unsigned int ev_iteration (EV_P) EV_NOEXCEPT; /* number of loop iterations */ |
662 | EV_API_DECL unsigned int ev_iteration (EV_P) EV_NOEXCEPT; /* number of loop iterations */ |
664 | EV_API_DECL unsigned int ev_depth (EV_P) EV_NOEXCEPT; /* #ev_loop enters - #ev_loop leaves */ |
663 | EV_API_DECL unsigned int ev_depth (EV_P) EV_NOEXCEPT; /* #ev_loop enters - #ev_loop leaves */ |
665 | EV_API_DECL void ev_verify (EV_P) EV_NOEXCEPT; /* abort if loop data corrupted */ |
664 | EV_API_DECL void ev_verify (EV_P) EV_NOEXCEPT; /* abort if loop data corrupted */ |
666 | |
665 | |
… | |
… | |
674 | EV_API_DECL void ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_NOEXCEPT; |
673 | EV_API_DECL void ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_NOEXCEPT; |
675 | /* C++ doesn't allow the use of the ev_loop_callback typedef here, so we need to spell it out */ |
674 | /* C++ doesn't allow the use of the ev_loop_callback typedef here, so we need to spell it out */ |
676 | EV_API_DECL void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_NOEXCEPT, void (*acquire)(EV_P) EV_NOEXCEPT) EV_NOEXCEPT; |
675 | EV_API_DECL void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_NOEXCEPT, void (*acquire)(EV_P) EV_NOEXCEPT) EV_NOEXCEPT; |
677 | |
676 | |
678 | EV_API_DECL unsigned int ev_pending_count (EV_P) EV_NOEXCEPT; /* number of pending events, if any */ |
677 | EV_API_DECL unsigned int ev_pending_count (EV_P) EV_NOEXCEPT; /* number of pending events, if any */ |
679 | EV_API_DECL void ev_invoke_pending (EV_P); /* invoke all pending watchers */ |
|
|
680 | |
678 | |
681 | /* |
679 | /* |
682 | * stop/start the timer handling. |
680 | * stop/start the timer handling. |
683 | */ |
681 | */ |
684 | EV_API_DECL void ev_suspend (EV_P) EV_NOEXCEPT; |
682 | EV_API_DECL void ev_suspend (EV_P) EV_NOEXCEPT; |
… | |
… | |
694 | ((ev_watcher *)(void *)(ev))->pending = 0; \ |
692 | ((ev_watcher *)(void *)(ev))->pending = 0; \ |
695 | ev_set_priority ((ev), 0); \ |
693 | ev_set_priority ((ev), 0); \ |
696 | ev_set_cb ((ev), cb_); \ |
694 | ev_set_cb ((ev), cb_); \ |
697 | } while (0) |
695 | } while (0) |
698 | |
696 | |
|
|
697 | #define ev_io_modify(ev,events_) do { (ev)->events = (ev)->events & EV__IOMASK | (events_); } while (0) |
699 | #define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_) | EV__IOFDSET; } while (0) |
698 | #define ev_io_set(ev,fd_,events_) do { (ev)->fd = (fd_); (ev)->events = (events_) | EV__IOFDSET; } while (0) |
700 | #define ev_timer_set(ev,after_,repeat_) do { ((ev_watcher_time *)(ev))->at = (after_); (ev)->repeat = (repeat_); } while (0) |
699 | #define ev_timer_set(ev,after_,repeat_) do { ((ev_watcher_time *)(ev))->at = (after_); (ev)->repeat = (repeat_); } while (0) |
701 | #define ev_periodic_set(ev,ofs_,ival_,rcb_) do { (ev)->offset = (ofs_); (ev)->interval = (ival_); (ev)->reschedule_cb = (rcb_); } while (0) |
700 | #define ev_periodic_set(ev,ofs_,ival_,rcb_) do { (ev)->offset = (ofs_); (ev)->interval = (ival_); (ev)->reschedule_cb = (rcb_); } while (0) |
702 | #define ev_signal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0) |
701 | #define ev_signal_set(ev,signum_) do { (ev)->signum = (signum_); } while (0) |
703 | #define ev_child_set(ev,pid_,trace_) do { (ev)->pid = (pid_); (ev)->flags = !!(trace_); } while (0) |
702 | #define ev_child_set(ev,pid_,trace_) do { (ev)->pid = (pid_); (ev)->flags = !!(trace_); } while (0) |