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

Comparing libev/ev.pod (file contents):
Revision 1.290 by root, Tue Mar 16 18:03:01 2010 UTC vs.
Revision 1.297 by root, Tue Jun 29 11:49:02 2010 UTC

124this argument. 124this argument.
125 125
126=head2 TIME REPRESENTATION 126=head2 TIME REPRESENTATION
127 127
128Libev represents time as a single floating point number, representing 128Libev represents time as a single floating point number, representing
129the (fractional) number of seconds since the (POSIX) epoch (somewhere 129the (fractional) number of seconds since the (POSIX) epoch (in practise
130near the beginning of 1970, details are complicated, don't ask). This 130somewhere near the beginning of 1970, details are complicated, don't
131type is called C<ev_tstamp>, which is what you should use too. It usually 131ask). This type is called C<ev_tstamp>, which is what you should use
132aliases to the C<double> type in C. When you need to do any calculations 132too. It usually aliases to the C<double> type in C. When you need to do
133on it, you should treat it as some floating point value. Unlike the name 133any calculations on it, you should treat it as some floating point value.
134
134component C<stamp> might indicate, it is also used for time differences 135Unlike the name component C<stamp> might indicate, it is also used for
135throughout libev. 136time differences (e.g. delays) throughout libev.
136 137
137=head1 ERROR HANDLING 138=head1 ERROR HANDLING
138 139
139Libev knows three classes of errors: operating system errors, usage errors 140Libev knows three classes of errors: operating system errors, usage errors
140and internal errors (bugs). 141and internal errors (bugs).
191as this indicates an incompatible change. Minor versions are usually 192as this indicates an incompatible change. Minor versions are usually
192compatible to older versions, so a larger minor version alone is usually 193compatible to older versions, so a larger minor version alone is usually
193not a problem. 194not a problem.
194 195
195Example: Make sure we haven't accidentally been linked against the wrong 196Example: Make sure we haven't accidentally been linked against the wrong
196version. 197version (note, however, that this will not detect ABI mismatches :).
197 198
198 assert (("libev version mismatch", 199 assert (("libev version mismatch",
199 ev_version_major () == EV_VERSION_MAJOR 200 ev_version_major () == EV_VERSION_MAJOR
200 && ev_version_minor () >= EV_VERSION_MINOR)); 201 && ev_version_minor () >= EV_VERSION_MINOR));
201 202
345useful to try out specific backends to test their performance, or to work 346useful to try out specific backends to test their performance, or to work
346around bugs. 347around bugs.
347 348
348=item C<EVFLAG_FORKCHECK> 349=item C<EVFLAG_FORKCHECK>
349 350
350Instead of calling C<ev_default_fork> or C<ev_loop_fork> manually after 351Instead of calling C<ev_loop_fork> manually after a fork, you can also
351a fork, you can also make libev check for a fork in each iteration by 352make libev check for a fork in each iteration by enabling this flag.
352enabling this flag.
353 353
354This works by calling C<getpid ()> on every iteration of the loop, 354This works by calling C<getpid ()> on every iteration of the loop,
355and thus this might slow down your event loop if you do a lot of loop 355and thus this might slow down your event loop if you do a lot of loop
356iterations and little real work, but is usually not noticeable (on my 356iterations and little real work, but is usually not noticeable (on my
357GNU/Linux system for example, C<getpid> is actually a simple 5-insn sequence 357GNU/Linux system for example, C<getpid> is actually a simple 5-insn sequence
611name, you can call it anytime, but it makes most sense after forking, in 611name, you can call it anytime, but it makes most sense after forking, in
612the child process (or both child and parent, but that again makes little 612the child process (or both child and parent, but that again makes little
613sense). You I<must> call it in the child before using any of the libev 613sense). You I<must> call it in the child before using any of the libev
614functions, and it will only take effect at the next C<ev_loop> iteration. 614functions, and it will only take effect at the next C<ev_loop> iteration.
615 615
616Again, you I<have> to call it on I<any> loop that you want to re-use after
617a fork, I<even if you do not plan to use the loop in the parent>. This is
618because some kernel interfaces *cough* I<kqueue> *cough* do funny things
619during fork.
620
616On the other hand, you only need to call this function in the child 621On the other hand, you only need to call this function in the child
617process if and only if you want to use the event library in the child. If 622process if and only if you want to use the event loop in the child. If you
618you just fork+exec, you don't have to call it at all. 623just fork+exec or create a new loop in the child, you don't have to call
624it at all.
619 625
620The function itself is quite fast and it's usually not a problem to call 626The function itself is quite fast and it's usually not a problem to call
621it just in case after a fork. To make this easy, the function will fit in 627it just in case after a fork. To make this easy, the function will fit in
622quite nicely into a call to C<pthread_atfork>: 628quite nicely into a call to C<pthread_atfork>:
623 629
625 631
626=item ev_loop_fork (loop) 632=item ev_loop_fork (loop)
627 633
628Like C<ev_default_fork>, but acts on an event loop created by 634Like C<ev_default_fork>, but acts on an event loop created by
629C<ev_loop_new>. Yes, you have to call this on every allocated event loop 635C<ev_loop_new>. Yes, you have to call this on every allocated event loop
630after fork that you want to re-use in the child, and how you do this is 636after fork that you want to re-use in the child, and how you keep track of
631entirely your own problem. 637them is entirely your own problem.
632 638
633=item int ev_is_default_loop (loop) 639=item int ev_is_default_loop (loop)
634 640
635Returns true when the given loop is, in fact, the default loop, and false 641Returns true when the given loop is, in fact, the default loop, and false
636otherwise. 642otherwise.
637 643
638=item unsigned int ev_loop_count (loop) 644=item unsigned int ev_iteration (loop)
639 645
640Returns the count of loop iterations for the loop, which is identical to 646Returns the current iteration count for the loop, which is identical to
641the number of times libev did poll for new events. It starts at C<0> and 647the number of times libev did poll for new events. It starts at C<0> and
642happily wraps around with enough iterations. 648happily wraps around with enough iterations.
643 649
644This value can sometimes be useful as a generation counter of sorts (it 650This value can sometimes be useful as a generation counter of sorts (it
645"ticks" the number of loop iterations), as it roughly corresponds with 651"ticks" the number of loop iterations), as it roughly corresponds with
646C<ev_prepare> and C<ev_check> calls. 652C<ev_prepare> and C<ev_check> calls - and is incremented between the
653prepare and check phases.
647 654
648=item unsigned int ev_loop_depth (loop) 655=item unsigned int ev_depth (loop)
649 656
650Returns the number of times C<ev_loop> was entered minus the number of 657Returns the number of times C<ev_loop> was entered minus the number of
651times C<ev_loop> was exited, in other words, the recursion depth. 658times C<ev_loop> was exited, in other words, the recursion depth.
652 659
653Outside C<ev_loop>, this number is zero. In a callback, this number is 660Outside C<ev_loop>, this number is zero. In a callback, this number is
654C<1>, unless C<ev_loop> was invoked recursively (or from another thread), 661C<1>, unless C<ev_loop> was invoked recursively (or from another thread),
655in which case it is higher. 662in which case it is higher.
656 663
657Leaving C<ev_loop> abnormally (setjmp/longjmp, cancelling the thread 664Leaving C<ev_loop> abnormally (setjmp/longjmp, cancelling the thread
658etc.), doesn't count as exit. 665etc.), doesn't count as "exit" - consider this as a hint to avoid such
666ungentleman behaviour unless it's really convenient.
659 667
660=item unsigned int ev_backend (loop) 668=item unsigned int ev_backend (loop)
661 669
662Returns one of the C<EVBACKEND_*> flags indicating the event backend in 670Returns one of the C<EVBACKEND_*> flags indicating the event backend in
663use. 671use.
1396 { 1404 {
1397 // stop the I/O watcher, we received the event, but 1405 // stop the I/O watcher, we received the event, but
1398 // are not yet ready to handle it. 1406 // are not yet ready to handle it.
1399 ev_io_stop (EV_A_ w); 1407 ev_io_stop (EV_A_ w);
1400 1408
1401 // start the idle watcher to ahndle the actual event. 1409 // start the idle watcher to handle the actual event.
1402 // it will not be executed as long as other watchers 1410 // it will not be executed as long as other watchers
1403 // with the default priority are receiving events. 1411 // with the default priority are receiving events.
1404 ev_idle_start (EV_A_ &idle); 1412 ev_idle_start (EV_A_ &idle);
1405 } 1413 }
1406 1414
1538somewhere, as that would have given you a big clue). 1546somewhere, as that would have given you a big clue).
1539 1547
1540=head3 The special problem of accept()ing when you can't 1548=head3 The special problem of accept()ing when you can't
1541 1549
1542Many implementations of the POSIX C<accept> function (for example, 1550Many implementations of the POSIX C<accept> function (for example,
1543found in port-2004 Linux) have the peculiar behaviour of not removing a 1551found in post-2004 Linux) have the peculiar behaviour of not removing a
1544connection from the pending queue in all error cases. 1552connection from the pending queue in all error cases.
1545 1553
1546For example, larger servers often run out of file descriptors (because 1554For example, larger servers often run out of file descriptors (because
1547of resource limits), causing C<accept> to fail with C<ENFILE> but not 1555of resource limits), causing C<accept> to fail with C<ENFILE> but not
1548rejecting the connection, leading to libev signalling readiness on 1556rejecting the connection, leading to libev signalling readiness on
1766 callback (loop, timer, EV_TIMER); 1774 callback (loop, timer, EV_TIMER);
1767 1775
1768And when there is some activity, simply store the current time in 1776And when there is some activity, simply store the current time in
1769C<last_activity>, no libev calls at all: 1777C<last_activity>, no libev calls at all:
1770 1778
1771 last_actiivty = ev_now (loop); 1779 last_activity = ev_now (loop);
1772 1780
1773This technique is slightly more complex, but in most cases where the 1781This technique is slightly more complex, but in most cases where the
1774time-out is unlikely to be triggered, much more efficient. 1782time-out is unlikely to be triggered, much more efficient.
1775 1783
1776Changing the timeout is trivial as well (if it isn't hard-coded in the 1784Changing the timeout is trivial as well (if it isn't hard-coded in the
3334 ev::io iow; 3342 ev::io iow;
3335 iow.set <myclass, &myclass::io_cb> (&obj); 3343 iow.set <myclass, &myclass::io_cb> (&obj);
3336 3344
3337=item w->set (object *) 3345=item w->set (object *)
3338 3346
3339This is an B<experimental> feature that might go away in a future version.
3340
3341This is a variation of a method callback - leaving out the method to call 3347This is a variation of a method callback - leaving out the method to call
3342will default the method to C<operator ()>, which makes it possible to use 3348will default the method to C<operator ()>, which makes it possible to use
3343functor objects without having to manually specify the C<operator ()> all 3349functor objects without having to manually specify the C<operator ()> all
3344the time. Incidentally, you can then also leave out the template argument 3350the time. Incidentally, you can then also leave out the template argument
3345list. 3351list.
3657define before including (or compiling) any of its files. The default in 3663define before including (or compiling) any of its files. The default in
3658the absence of autoconf is documented for every option. 3664the absence of autoconf is documented for every option.
3659 3665
3660Symbols marked with "(h)" do not change the ABI, and can have different 3666Symbols marked with "(h)" do not change the ABI, and can have different
3661values when compiling libev vs. including F<ev.h>, so it is permissible 3667values when compiling libev vs. including F<ev.h>, so it is permissible
3662to redefine them before including F<ev.h> without breakign compatibility 3668to redefine them before including F<ev.h> without breaking compatibility
3663to a compiled library. All other symbols change the ABI, which means all 3669to a compiled library. All other symbols change the ABI, which means all
3664users of libev and the libev code itself must be compiled with compatible 3670users of libev and the libev code itself must be compiled with compatible
3665settings. 3671settings.
3666 3672
3667=over 4 3673=over 4
4618involves iterating over all running async watchers or all signal numbers. 4624involves iterating over all running async watchers or all signal numbers.
4619 4625
4620=back 4626=back
4621 4627
4622 4628
4623=head1 PORTING FROM 3.X TO 4.X 4629=head1 PORTING FROM LIBEV 3.X TO 4.X
4624 4630
4625The major version 4 introduced some minor incompatible changes to the API. 4631The major version 4 introduced some minor incompatible changes to the API.
4626 4632
4633At the moment, the C<ev.h> header file tries to implement superficial
4634compatibility, so most programs should still compile. Those might be
4635removed in later versions of libev, so better update early than late.
4636
4627=over 4 4637=over 4
4628 4638
4639=item C<ev_loop_count> renamed to C<ev_iteration>
4640
4641=item C<ev_loop_depth> renamed to C<ev_depth>
4642
4643=item C<ev_loop_verify> renamed to C<ev_verify>
4644
4645Most functions working on C<struct ev_loop> objects don't have an
4646C<ev_loop_> prefix, so it was removed. Note that C<ev_loop_fork> is
4647still called C<ev_loop_fork> because it would otherwise clash with the
4648C<ev_fork> typedef.
4649
4629=item C<EV_TIMEOUT> replaced by C<EV_TIMER> in C<revents> 4650=item C<EV_TIMEOUT> renamed to C<EV_TIMER> in C<revents>
4630 4651
4631This is a simple rename - all other watcher types use their name 4652This is a simple rename - all other watcher types use their name
4632as revents flag, and now C<ev_timer> does, too. 4653as revents flag, and now C<ev_timer> does, too.
4633 4654
4634Both C<EV_TIMER> and C<EV_TIMEOUT> symbols were present in 3.x versions 4655Both C<EV_TIMER> and C<EV_TIMEOUT> symbols were present in 3.x versions

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines