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

Comparing libev/ev.pod (file contents):
Revision 1.394 by root, Tue Jan 24 16:37:12 2012 UTC vs.
Revision 1.399 by root, Mon Apr 2 23:14:41 2012 UTC

567 567
568It scales in the same way as the epoll backend, but the interface to the 568It scales in the same way as the epoll backend, but the interface to the
569kernel is more efficient (which says nothing about its actual speed, of 569kernel is more efficient (which says nothing about its actual speed, of
570course). While stopping, setting and starting an I/O watcher does never 570course). While stopping, setting and starting an I/O watcher does never
571cause an extra system call as with C<EVBACKEND_EPOLL>, it still adds up to 571cause an extra system call as with C<EVBACKEND_EPOLL>, it still adds up to
572two event changes per incident. Support for C<fork ()> is very bad (but 572two event changes per incident. Support for C<fork ()> is very bad (you
573sane, unlike epoll) and it drops fds silently in similarly hard-to-detect 573might have to leak fd's on fork, but it's more sane than epoll) and it
574cases 574drops fds silently in similarly hard-to-detect cases
575 575
576This backend usually performs well under most conditions. 576This backend usually performs well under most conditions.
577 577
578While nominally embeddable in other event loops, this doesn't work 578While nominally embeddable in other event loops, this doesn't work
579everywhere, so you might need to test for this. And since it is broken 579everywhere, so you might need to test for this. And since it is broken
792without a previous call to C<ev_suspend>. 792without a previous call to C<ev_suspend>.
793 793
794Calling C<ev_suspend>/C<ev_resume> has the side effect of updating the 794Calling C<ev_suspend>/C<ev_resume> has the side effect of updating the
795event loop time (see C<ev_now_update>). 795event loop time (see C<ev_now_update>).
796 796
797=item ev_run (loop, int flags) 797=item bool ev_run (loop, int flags)
798 798
799Finally, this is it, the event handler. This function usually is called 799Finally, this is it, the event handler. This function usually is called
800after you have initialised all your watchers and you want to start 800after you have initialised all your watchers and you want to start
801handling events. It will ask the operating system for any new events, call 801handling events. It will ask the operating system for any new events, call
802the watcher callbacks, an then repeat the whole process indefinitely: This 802the watcher callbacks, and then repeat the whole process indefinitely: This
803is why event loops are called I<loops>. 803is why event loops are called I<loops>.
804 804
805If the flags argument is specified as C<0>, it will keep handling events 805If the flags argument is specified as C<0>, it will keep handling events
806until either no event watchers are active anymore or C<ev_break> was 806until either no event watchers are active anymore or C<ev_break> was
807called. 807called.
808
809The return value is false if there are no more active watchers (which
810usually means "all jobs done" or "deadlock"), and true in all other cases
811(which usually means " you should call C<ev_run> again").
808 812
809Please note that an explicit C<ev_break> is usually better than 813Please note that an explicit C<ev_break> is usually better than
810relying on all watchers to be stopped when deciding when a program has 814relying on all watchers to be stopped when deciding when a program has
811finished (especially in interactive programs), but having a program 815finished (especially in interactive programs), but having a program
812that automatically loops as long as it has to and no longer by virtue 816that automatically loops as long as it has to and no longer by virtue
813of relying on its watchers stopping correctly, that is truly a thing of 817of relying on its watchers stopping correctly, that is truly a thing of
814beauty. 818beauty.
815 819
816This function is also I<mostly> exception-safe - you can break out of 820This function is I<mostly> exception-safe - you can break out of a
817a C<ev_run> call by calling C<longjmp> in a callback, throwing a C++ 821C<ev_run> call by calling C<longjmp> in a callback, throwing a C++
818exception and so on. This does not decrement the C<ev_depth> value, nor 822exception and so on. This does not decrement the C<ev_depth> value, nor
819will it clear any outstanding C<EVBREAK_ONE> breaks. 823will it clear any outstanding C<EVBREAK_ONE> breaks.
820 824
821A flags value of C<EVRUN_NOWAIT> will look for new events, will handle 825A flags value of C<EVRUN_NOWAIT> will look for new events, will handle
822those events and any already outstanding ones, but will not wait and 826those events and any already outstanding ones, but will not wait and
2112 2116
2113This will act as if the timer timed out, and restarts it again if it is 2117This will act as if the timer timed out, and restarts it again if it is
2114repeating. It basically works like calling C<ev_timer_stop>, updating the 2118repeating. It basically works like calling C<ev_timer_stop>, updating the
2115timeout to the C<repeat> value and calling C<ev_timer_start>. 2119timeout to the C<repeat> value and calling C<ev_timer_start>.
2116 2120
2117The exact semantics are as in the wollofing rules, all of which will be 2121The exact semantics are as in the following rules, all of which will be
2118applied to the watcher: 2122applied to the watcher:
2119 2123
2120=over 4 2124=over 4
2121 2125
2122=item If the timer is pending, the pending status is always cleared. 2126=item If the timer is pending, the pending status is always cleared.
3917with C<operator ()> can be used as callbacks. Other types should be easy 3921with C<operator ()> can be used as callbacks. Other types should be easy
3918to add as long as they only need one additional pointer for context. If 3922to add as long as they only need one additional pointer for context. If
3919you need support for other types of functors please contact the author 3923you need support for other types of functors please contact the author
3920(preferably after implementing it). 3924(preferably after implementing it).
3921 3925
3926For all this to work, your C++ compiler either has to use the same calling
3927conventions as your C compiler (for static member functions), or you have
3928to embed libev and compile libev itself as C++.
3929
3922Here is a list of things available in the C<ev> namespace: 3930Here is a list of things available in the C<ev> namespace:
3923 3931
3924=over 4 3932=over 4
3925 3933
3926=item C<ev::READ>, C<ev::WRITE> etc. 3934=item C<ev::READ>, C<ev::WRITE> etc.
4504If defined to be C<1>, libev will compile in support for the Linux inotify 4512If defined to be C<1>, libev will compile in support for the Linux inotify
4505interface to speed up C<ev_stat> watchers. Its actual availability will 4513interface to speed up C<ev_stat> watchers. Its actual availability will
4506be detected at runtime. If undefined, it will be enabled if the headers 4514be detected at runtime. If undefined, it will be enabled if the headers
4507indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled. 4515indicate GNU/Linux + Glibc 2.4 or newer, otherwise disabled.
4508 4516
4517=item EV_NO_SMP
4518
4519If defined to be C<1>, libev will assume that memory is always coherent
4520between threads, that is, threads can be used, but threads never run on
4521different cpus (or different cpu cores). This reduces dependencies
4522and makes libev faster.
4523
4524=item EV_NO_THREADS
4525
4526If defined to be C<1>, libev will assume that it will never be called
4527from different threads, which is a stronger assumption than C<EV_NO_SMP>,
4528above. This reduces dependencies and makes libev faster.
4529
4509=item EV_ATOMIC_T 4530=item EV_ATOMIC_T
4510 4531
4511Libev requires an integer type (suitable for storing C<0> or C<1>) whose 4532Libev requires an integer type (suitable for storing C<0> or C<1>) whose
4512access is atomic and serialised with respect to other threads or signal 4533access is atomic and serialised with respect to other threads or signal
4513contexts. No such type is easily found in the C language, so you can 4534contexts. No such type is easily found in the C language, so you can

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines