… | |
… | |
726 | |
726 | |
727 | If you have a watcher you never unregister that should not keep C<ev_loop> |
727 | If you have a watcher you never unregister that should not keep C<ev_loop> |
728 | from returning, call ev_unref() after starting, and ev_ref() before |
728 | from returning, call ev_unref() after starting, and ev_ref() before |
729 | stopping it. |
729 | stopping it. |
730 | |
730 | |
731 | As an example, libev itself uses this for its internal signal pipe: It is |
731 | As an example, libev itself uses this for its internal signal pipe: It |
732 | not visible to the libev user and should not keep C<ev_loop> from exiting |
732 | is not visible to the libev user and should not keep C<ev_loop> from |
733 | if no event watchers registered by it are active. It is also an excellent |
733 | exiting if no event watchers registered by it are active. It is also an |
734 | way to do this for generic recurring timers or from within third-party |
734 | excellent way to do this for generic recurring timers or from within |
735 | libraries. Just remember to I<unref after start> and I<ref before stop> |
735 | third-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, |
736 | before stop> (but only if the watcher wasn't active before, or was active |
737 | respectively). |
737 | before, respectively. Note also that libev might stop watchers itself |
|
|
738 | (e.g. non-repeating timers) in which case you have to C<ev_ref> |
|
|
739 | in the callback). |
738 | |
740 | |
739 | Example: Create a signal watcher, but keep it from keeping C<ev_loop> |
741 | Example: Create a signal watcher, but keep it from keeping C<ev_loop> |
740 | running when nothing else is active. |
742 | running when nothing else is active. |
741 | |
743 | |
742 | ev_signal exitsig; |
744 | ev_signal exitsig; |
… | |
… | |
925 | C<ev_fork>). |
927 | C<ev_fork>). |
926 | |
928 | |
927 | =item C<EV_ASYNC> |
929 | =item C<EV_ASYNC> |
928 | |
930 | |
929 | The given async watcher has been asynchronously notified (see C<ev_async>). |
931 | The given async watcher has been asynchronously notified (see C<ev_async>). |
|
|
932 | |
|
|
933 | =item C<EV_CUSTOM> |
|
|
934 | |
|
|
935 | Not ever sent (or otherwise used) by libev itself, but can be freely used |
|
|
936 | by libev users to signal watchers (e.g. via C<ev_feed_event>). |
930 | |
937 | |
931 | =item C<EV_ERROR> |
938 | =item C<EV_ERROR> |
932 | |
939 | |
933 | An unspecified error has occurred, the watcher has been stopped. This might |
940 | An unspecified error has occurred, the watcher has been stopped. This might |
934 | happen because the watcher could not be properly started because libev |
941 | happen because the watcher could not be properly started because libev |
… | |
… | |
1317 | year, it will still time out after (roughly) one hour. "Roughly" because |
1324 | year, it will still time out after (roughly) one hour. "Roughly" because |
1318 | detecting time jumps is hard, and some inaccuracies are unavoidable (the |
1325 | detecting time jumps is hard, and some inaccuracies are unavoidable (the |
1319 | monotonic clock option helps a lot here). |
1326 | monotonic clock option helps a lot here). |
1320 | |
1327 | |
1321 | The callback is guaranteed to be invoked only I<after> its timeout has |
1328 | The callback is guaranteed to be invoked only I<after> its timeout has |
1322 | passed, but if multiple timers become ready during the same loop iteration |
1329 | passed. If multiple timers become ready during the same loop iteration |
1323 | then order of execution is undefined. |
1330 | then the ones with earlier time-out values are invoked before ones with |
|
|
1331 | later time-out values (but this is no longer true when a callback calls |
|
|
1332 | C<ev_loop> recursively). |
1324 | |
1333 | |
1325 | =head3 Be smart about timeouts |
1334 | =head3 Be smart about timeouts |
1326 | |
1335 | |
1327 | Many real-world problems involve some kind of timeout, usually for error |
1336 | Many real-world problems involve some kind of timeout, usually for error |
1328 | recovery. A typical example is an HTTP request - if the other side hangs, |
1337 | recovery. A typical example is an HTTP request - if the other side hangs, |
… | |
… | |
1617 | timers, such as triggering an event on each "midnight, local time", or |
1626 | timers, such as triggering an event on each "midnight, local time", or |
1618 | other complicated rules. This cannot be done with C<ev_timer> watchers, as |
1627 | other complicated rules. This cannot be done with C<ev_timer> watchers, as |
1619 | those cannot react to time jumps. |
1628 | those cannot react to time jumps. |
1620 | |
1629 | |
1621 | As with timers, the callback is guaranteed to be invoked only when the |
1630 | As with timers, the callback is guaranteed to be invoked only when the |
1622 | point in time where it is supposed to trigger has passed, but if multiple |
1631 | point in time where it is supposed to trigger has passed. If multiple |
1623 | periodic timers become ready during the same loop iteration, then order of |
1632 | timers become ready during the same loop iteration then the ones with |
1624 | execution is undefined. |
1633 | earlier time-out values are invoked before ones with later time-out values |
|
|
1634 | (but this is no longer true when a callback calls C<ev_loop> recursively). |
1625 | |
1635 | |
1626 | =head3 Watcher-Specific Functions and Data Members |
1636 | =head3 Watcher-Specific Functions and Data Members |
1627 | |
1637 | |
1628 | =over 4 |
1638 | =over 4 |
1629 | |
1639 | |
… | |
… | |
3033 | L<http://software.schmorp.de/pkg/EV>. |
3043 | L<http://software.schmorp.de/pkg/EV>. |
3034 | |
3044 | |
3035 | =item Python |
3045 | =item Python |
3036 | |
3046 | |
3037 | Python bindings can be found at L<http://code.google.com/p/pyev/>. It |
3047 | Python bindings can be found at L<http://code.google.com/p/pyev/>. It |
3038 | seems to be quite complete and well-documented. Note, however, that the |
3048 | seems to be quite complete and well-documented. |
3039 | patch they require for libev is outright dangerous as it breaks the ABI |
|
|
3040 | for everybody else, and therefore, should never be applied in an installed |
|
|
3041 | libev (if python requires an incompatible ABI then it needs to embed |
|
|
3042 | libev). |
|
|
3043 | |
3049 | |
3044 | =item Ruby |
3050 | =item Ruby |
3045 | |
3051 | |
3046 | Tony Arcieri has written a ruby extension that offers access to a subset |
3052 | Tony Arcieri has written a ruby extension that offers access to a subset |
3047 | of the libev API and adds file handle abstractions, asynchronous DNS and |
3053 | of the libev API and adds file handle abstractions, asynchronous DNS and |
3048 | more on top of it. It can be found via gem servers. Its homepage is at |
3054 | more on top of it. It can be found via gem servers. Its homepage is at |
3049 | L<http://rev.rubyforge.org/>. |
3055 | L<http://rev.rubyforge.org/>. |
3050 | |
3056 | |
3051 | Roger Pack reports that using the link order C<-lws2_32 -lmsvcrt-ruby-190> |
3057 | Roger Pack reports that using the link order C<-lws2_32 -lmsvcrt-ruby-190> |
3052 | makes rev work even on mingw. |
3058 | makes rev work even on mingw. |
|
|
3059 | |
|
|
3060 | =item Haskell |
|
|
3061 | |
|
|
3062 | A haskell binding to libev is available at |
|
|
3063 | L<http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hlibev>. |
3053 | |
3064 | |
3054 | =item D |
3065 | =item D |
3055 | |
3066 | |
3056 | Leandro Lucarella has written a D language binding (F<ev.d>) for libev, to |
3067 | Leandro Lucarella has written a D language binding (F<ev.d>) for libev, to |
3057 | be found at L<http://proj.llucax.com.ar/wiki/evd>. |
3068 | be found at L<http://proj.llucax.com.ar/wiki/evd>. |