ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.pod
(Generate patch)

Comparing libev/ev.pod (file contents):
Revision 1.228 by root, Sat Mar 28 08:22:30 2009 UTC vs.
Revision 1.231 by root, Wed Apr 15 19:35:53 2009 UTC

633This function is rarely useful, but when some event callback runs for a 633This function is rarely useful, but when some event callback runs for a
634very long time without entering the event loop, updating libev's idea of 634very long time without entering the event loop, updating libev's idea of
635the current time is a good idea. 635the current time is a good idea.
636 636
637See also "The special problem of time updates" in the C<ev_timer> section. 637See also "The special problem of time updates" in the C<ev_timer> section.
638
639=item ev_suspend (loop)
640
641=item ev_resume (loop)
642
643These two functions suspend and resume a loop, for use when the loop is
644not used for a while and timeouts should not be processed.
645
646A typical use case would be an interactive program such as a game: When
647the user presses C<^Z> to suspend the game and resumes it an hour later it
648would be best to handle timeouts as if no time had actually passed while
649the program was suspended. This can be achieved by calling C<ev_suspend>
650in your C<SIGTSTP> handler, sending yourself a C<SIGSTOP> and calling
651C<ev_resume> directly afterwards to resume timer processing.
652
653Effectively, all C<ev_timer> watchers will be delayed by the time spend
654between C<ev_suspend> and C<ev_resume>, and all C<ev_periodic> watchers
655will be rescheduled (that is, they will lose any events that would have
656occured while suspended).
657
658After calling C<ev_suspend> you B<must not> call I<any> function on the
659given loop other than C<ev_resume>, and you B<must not> call C<ev_resume>
660without a previous call to C<ev_suspend>.
661
662Calling C<ev_suspend>/C<ev_resume> has the side effect of updating the
663event loop time (see C<ev_now_update>).
638 664
639=item ev_loop (loop, int flags) 665=item ev_loop (loop, int flags)
640 666
641Finally, this is it, the event handler. This function usually is called 667Finally, this is it, the event handler. This function usually is called
642after you initialised all your watchers and you want to start handling 668after you initialised all your watchers and you want to start handling
726 752
727If you have a watcher you never unregister that should not keep C<ev_loop> 753If you have a watcher you never unregister that should not keep C<ev_loop>
728from returning, call ev_unref() after starting, and ev_ref() before 754from returning, call ev_unref() after starting, and ev_ref() before
729stopping it. 755stopping it.
730 756
731As an example, libev itself uses this for its internal signal pipe: It is 757As an example, libev itself uses this for its internal signal pipe: It
732not visible to the libev user and should not keep C<ev_loop> from exiting 758is not visible to the libev user and should not keep C<ev_loop> from
733if no event watchers registered by it are active. It is also an excellent 759exiting if no event watchers registered by it are active. It is also an
734way to do this for generic recurring timers or from within third-party 760excellent way to do this for generic recurring timers or from within
735libraries. Just remember to I<unref after start> and I<ref before stop> 761third-party libraries. Just remember to I<unref after start> and I<ref
736(but only if the watcher wasn't active before, or was active before, 762before stop> (but only if the watcher wasn't active before, or was active
737respectively). 763before, respectively. Note also that libev might stop watchers itself
764(e.g. non-repeating timers) in which case you have to C<ev_ref>
765in the callback).
738 766
739Example: Create a signal watcher, but keep it from keeping C<ev_loop> 767Example: Create a signal watcher, but keep it from keeping C<ev_loop>
740running when nothing else is active. 768running when nothing else is active.
741 769
742 ev_signal exitsig; 770 ev_signal exitsig;
925C<ev_fork>). 953C<ev_fork>).
926 954
927=item C<EV_ASYNC> 955=item C<EV_ASYNC>
928 956
929The given async watcher has been asynchronously notified (see C<ev_async>). 957The given async watcher has been asynchronously notified (see C<ev_async>).
958
959=item C<EV_CUSTOM>
960
961Not ever sent (or otherwise used) by libev itself, but can be freely used
962by libev users to signal watchers (e.g. via C<ev_feed_event>).
930 963
931=item C<EV_ERROR> 964=item C<EV_ERROR>
932 965
933An unspecified error has occurred, the watcher has been stopped. This might 966An unspecified error has occurred, the watcher has been stopped. This might
934happen because the watcher could not be properly started because libev 967happen because the watcher could not be properly started because libev
1317year, it will still time out after (roughly) one hour. "Roughly" because 1350year, it will still time out after (roughly) one hour. "Roughly" because
1318detecting time jumps is hard, and some inaccuracies are unavoidable (the 1351detecting time jumps is hard, and some inaccuracies are unavoidable (the
1319monotonic clock option helps a lot here). 1352monotonic clock option helps a lot here).
1320 1353
1321The callback is guaranteed to be invoked only I<after> its timeout has 1354The callback is guaranteed to be invoked only I<after> its timeout has
1322passed, but if multiple timers become ready during the same loop iteration 1355passed. If multiple timers become ready during the same loop iteration
1323then order of execution is undefined. 1356then the ones with earlier time-out values are invoked before ones with
1357later time-out values (but this is no longer true when a callback calls
1358C<ev_loop> recursively).
1324 1359
1325=head3 Be smart about timeouts 1360=head3 Be smart about timeouts
1326 1361
1327Many real-world problems involve some kind of timeout, usually for error 1362Many real-world problems involve some kind of timeout, usually for error
1328recovery. A typical example is an HTTP request - if the other side hangs, 1363recovery. A typical example is an HTTP request - if the other side hangs,
1617timers, such as triggering an event on each "midnight, local time", or 1652timers, such as triggering an event on each "midnight, local time", or
1618other complicated rules. This cannot be done with C<ev_timer> watchers, as 1653other complicated rules. This cannot be done with C<ev_timer> watchers, as
1619those cannot react to time jumps. 1654those cannot react to time jumps.
1620 1655
1621As with timers, the callback is guaranteed to be invoked only when the 1656As with timers, the callback is guaranteed to be invoked only when the
1622point in time where it is supposed to trigger has passed, but if multiple 1657point in time where it is supposed to trigger has passed. If multiple
1623periodic timers become ready during the same loop iteration, then order of 1658timers become ready during the same loop iteration then the ones with
1624execution is undefined. 1659earlier time-out values are invoked before ones with later time-out values
1660(but this is no longer true when a callback calls C<ev_loop> recursively).
1625 1661
1626=head3 Watcher-Specific Functions and Data Members 1662=head3 Watcher-Specific Functions and Data Members
1627 1663
1628=over 4 1664=over 4
1629 1665

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines