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.296 by root, Tue Jun 29 10:51:18 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
3657define before including (or compiling) any of its files. The default in 3665define before including (or compiling) any of its files. The default in
3658the absence of autoconf is documented for every option. 3666the absence of autoconf is documented for every option.
3659 3667
3660Symbols marked with "(h)" do not change the ABI, and can have different 3668Symbols 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 3669values when compiling libev vs. including F<ev.h>, so it is permissible
3662to redefine them before including F<ev.h> without breakign compatibility 3670to redefine them before including F<ev.h> without breaking compatibility
3663to a compiled library. All other symbols change the ABI, which means all 3671to 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 3672users of libev and the libev code itself must be compiled with compatible
3665settings. 3673settings.
3666 3674
3667=over 4 3675=over 4
4618involves iterating over all running async watchers or all signal numbers. 4626involves iterating over all running async watchers or all signal numbers.
4619 4627
4620=back 4628=back
4621 4629
4622 4630
4623=head1 PORTING FROM 3.X TO 4.X 4631=head1 PORTING FROM LIBEV 3.X TO 4.X
4624 4632
4625The major version 4 introduced some minor incompatible changes to the API. 4633The major version 4 introduced some minor incompatible changes to the API.
4626 4634
4635At the moment, the C<ev.h> header file tries to implement superficial
4636compatibility, so most programs should still compile. Those might be
4637removed in later versions of libev, so better update early than late.
4638
4627=over 4 4639=over 4
4628 4640
4641=item C<ev_loop_count> renamed to C<ev_iteration>
4642
4643=item C<ev_loop_depth> renamed to C<ev_depth>
4644
4645=item C<ev_loop_verify> renamed to C<ev_verify>
4646
4647Most functions working on C<struct ev_loop> objects don't have an
4648C<ev_loop_> prefix, so it was removed. Note that C<ev_loop_fork> is
4649still called C<ev_loop_fork> because it would otherwise clash with the
4650C<ev_fork> typedef.
4651
4629=item C<EV_TIMEOUT> replaced by C<EV_TIMER> in C<revents> 4652=item C<EV_TIMEOUT> renamed to C<EV_TIMER> in C<revents>
4630 4653
4631This is a simple rename - all other watcher types use their name 4654This is a simple rename - all other watcher types use their name
4632as revents flag, and now C<ev_timer> does, too. 4655as revents flag, and now C<ev_timer> does, too.
4633 4656
4634Both C<EV_TIMER> and C<EV_TIMEOUT> symbols were present in 3.x versions 4657Both C<EV_TIMER> and C<EV_TIMEOUT> symbols were present in 3.x versions

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines