… | |
… | |
582 | (that is, the lowest time value larger than to the second argument). It |
582 | (that is, the lowest time value larger than to the second argument). It |
583 | will usually be called just before the callback will be triggered, but |
583 | will usually be called just before the callback will be triggered, but |
584 | might be called at other times, too. |
584 | might be called at other times, too. |
585 | |
585 | |
586 | NOTE: I<< This callback must always return a time that is later than the |
586 | NOTE: I<< This callback must always return a time that is later than the |
587 | passed C<now> value >>. Not even C<now> itself will do, it must be larger. |
587 | passed C<now> value >>. Not even C<now> itself will do, it I<must> be larger. |
588 | |
588 | |
589 | This can be used to create very complex timers, such as a timer that |
589 | This can be used to create very complex timers, such as a timer that |
590 | triggers on each midnight, local time. To do this, you would calculate the |
590 | triggers on each midnight, local time. To do this, you would calculate the |
591 | next midnight after C<now> and return the timestamp value for this. How you do this |
591 | next midnight after C<now> and return the timestamp value for this. How |
592 | is, again, up to you (but it is not trivial). |
592 | you do this is, again, up to you (but it is not trivial, which is the main |
|
|
593 | reason I omitted it as an example). |
593 | |
594 | |
594 | =back |
595 | =back |
595 | |
596 | |
596 | =item ev_periodic_again (loop, ev_periodic *) |
597 | =item ev_periodic_again (loop, ev_periodic *) |
597 | |
598 | |
… | |
… | |
676 | =back |
677 | =back |
677 | |
678 | |
678 | =head2 C<ev_prepare> and C<ev_check> - customise your event loop |
679 | =head2 C<ev_prepare> and C<ev_check> - customise your event loop |
679 | |
680 | |
680 | Prepare and check watchers are usually (but not always) used in tandem: |
681 | Prepare and check watchers are usually (but not always) used in tandem: |
681 | Prepare watchers get invoked before the process blocks and check watchers |
682 | prepare watchers get invoked before the process blocks and check watchers |
682 | afterwards. |
683 | afterwards. |
683 | |
684 | |
684 | Their main purpose is to integrate other event mechanisms into libev. This |
685 | Their main purpose is to integrate other event mechanisms into libev. This |
685 | could be used, for example, to track variable changes, implement your own |
686 | could be used, for example, to track variable changes, implement your own |
686 | watchers, integrate net-snmp or a coroutine library and lots more. |
687 | watchers, integrate net-snmp or a coroutine library and lots more. |
… | |
… | |
689 | to be watched by the other library, registering C<ev_io> watchers for |
690 | to be watched by the other library, registering C<ev_io> watchers for |
690 | them and starting an C<ev_timer> watcher for any timeouts (many libraries |
691 | them and starting an C<ev_timer> watcher for any timeouts (many libraries |
691 | provide just this functionality). Then, in the check watcher you check for |
692 | provide just this functionality). Then, in the check watcher you check for |
692 | any events that occured (by checking the pending status of all watchers |
693 | any events that occured (by checking the pending status of all watchers |
693 | and stopping them) and call back into the library. The I/O and timer |
694 | and stopping them) and call back into the library. The I/O and timer |
694 | callbacks will never actually be called (but must be valid neverthelles, |
695 | callbacks will never actually be called (but must be valid nevertheless, |
695 | because you never know, you know?). |
696 | because you never know, you know?). |
696 | |
697 | |
697 | As another example, the Perl Coro module uses these hooks to integrate |
698 | As another example, the Perl Coro module uses these hooks to integrate |
698 | coroutines into libev programs, by yielding to other active coroutines |
699 | coroutines into libev programs, by yielding to other active coroutines |
699 | during each prepare and only letting the process block if no coroutines |
700 | during each prepare and only letting the process block if no coroutines |
700 | are ready to run (its actually more complicated, it only runs coroutines |
701 | are ready to run (it's actually more complicated: it only runs coroutines |
701 | with priority higher than the event loop and one lower priority once, |
702 | with priority higher than or equal to the event loop and one coroutine |
702 | using idle watchers to keep the event loop from blocking if lower-priority |
703 | of lower priority, but only once, using idle watchers to keep the event |
703 | coroutines exist, thus mapping low-priority coroutines to idle/background |
704 | loop from blocking if lower-priority coroutines are active, thus mapping |
704 | tasks). |
705 | low-priority coroutines to idle/background tasks). |
705 | |
706 | |
706 | =over 4 |
707 | =over 4 |
707 | |
708 | |
708 | =item ev_prepare_init (ev_prepare *, callback) |
709 | =item ev_prepare_init (ev_prepare *, callback) |
709 | |
710 | |
… | |
… | |
737 | started. Otherwise an C<ev_timer> watcher with after = C<timeout> (and |
738 | started. Otherwise an C<ev_timer> watcher with after = C<timeout> (and |
738 | repeat = 0) will be started. While C<0> is a valid timeout, it is of |
739 | repeat = 0) will be started. While C<0> is a valid timeout, it is of |
739 | dubious value. |
740 | dubious value. |
740 | |
741 | |
741 | The callback has the type C<void (*cb)(int revents, void *arg)> and gets |
742 | The callback has the type C<void (*cb)(int revents, void *arg)> and gets |
742 | passed an events set like normal event callbacks (with a combination of |
743 | passed an C<revents> set like normal event callbacks (a combination of |
743 | C<EV_ERROR>, C<EV_READ>, C<EV_WRITE> or C<EV_TIMEOUT>) and the C<arg> |
744 | C<EV_ERROR>, C<EV_READ>, C<EV_WRITE> or C<EV_TIMEOUT>) and the C<arg> |
744 | value passed to C<ev_once>: |
745 | value passed to C<ev_once>: |
745 | |
746 | |
746 | static void stdin_ready (int revents, void *arg) |
747 | static void stdin_ready (int revents, void *arg) |
747 | { |
748 | { |
… | |
… | |
768 | |
769 | |
769 | Feed an event as if the given signal occured (loop must be the default loop!). |
770 | Feed an event as if the given signal occured (loop must be the default loop!). |
770 | |
771 | |
771 | =back |
772 | =back |
772 | |
773 | |
|
|
774 | =head1 LIBEVENT EMULATION |
|
|
775 | |
|
|
776 | TBD. |
|
|
777 | |
|
|
778 | =head1 C++ SUPPORT |
|
|
779 | |
|
|
780 | TBD. |
|
|
781 | |
773 | =head1 AUTHOR |
782 | =head1 AUTHOR |
774 | |
783 | |
775 | Marc Lehmann <libev@schmorp.de>. |
784 | Marc Lehmann <libev@schmorp.de>. |
776 | |
785 | |