--- libev/ev.pod 2010/03/16 18:03:01 1.290 +++ libev/ev.pod 2010/10/14 04:29:34 1.303 @@ -77,7 +77,7 @@ on event-based programming, nor will it introduce event-based programming with libev. -Familarity with event based programming techniques in general is assumed +Familiarity with event based programming techniques in general is assumed throughout this document. =head1 ABOUT LIBEV @@ -126,13 +126,14 @@ =head2 TIME REPRESENTATION Libev represents time as a single floating point number, representing -the (fractional) number of seconds since the (POSIX) epoch (somewhere -near the beginning of 1970, details are complicated, don't ask). This -type is called C, which is what you should use too. It usually -aliases to the C type in C. When you need to do any calculations -on it, you should treat it as some floating point value. Unlike the name -component C might indicate, it is also used for time differences -throughout libev. +the (fractional) number of seconds since the (POSIX) epoch (in practise +somewhere near the beginning of 1970, details are complicated, don't +ask). This type is called C, which is what you should use +too. It usually aliases to the C type in C. When you need to do +any calculations on it, you should treat it as some floating point value. + +Unlike the name component C might indicate, it is also used for +time differences (e.g. delays) throughout libev. =head1 ERROR HANDLING @@ -193,7 +194,7 @@ not a problem. Example: Make sure we haven't accidentally been linked against the wrong -version. +version (note, however, that this will not detect ABI mismatches :). assert (("libev version mismatch", ev_version_major () == EV_VERSION_MAJOR @@ -347,9 +348,8 @@ =item C -Instead of calling C or C manually after -a fork, you can also make libev check for a fork in each iteration by -enabling this flag. +Instead of calling C manually after a fork, you can also +make libev check for a fork in each iteration by enabling this flag. This works by calling C on every iteration of the loop, and thus this might slow down your event loop if you do a lot of loop @@ -613,9 +613,15 @@ sense). You I call it in the child before using any of the libev functions, and it will only take effect at the next C iteration. +Again, you I to call it on I loop that you want to re-use after +a fork, I. This is +because some kernel interfaces *cough* I *cough* do funny things +during fork. + On the other hand, you only need to call this function in the child -process if and only if you want to use the event library in the child. If -you just fork+exec, you don't have to call it at all. +process if and only if you want to use the event loop in the child. If you +just fork+exec or create a new loop in the child, you don't have to call +it at all. The function itself is quite fast and it's usually not a problem to call it just in case after a fork. To make this easy, the function will fit in @@ -627,25 +633,26 @@ Like C, but acts on an event loop created by C. Yes, you have to call this on every allocated event loop -after fork that you want to re-use in the child, and how you do this is -entirely your own problem. +after fork that you want to re-use in the child, and how you keep track of +them is entirely your own problem. =item int ev_is_default_loop (loop) Returns true when the given loop is, in fact, the default loop, and false otherwise. -=item unsigned int ev_loop_count (loop) +=item unsigned int ev_iteration (loop) -Returns the count of loop iterations for the loop, which is identical to +Returns the current iteration count for the loop, which is identical to the number of times libev did poll for new events. It starts at C<0> and happily wraps around with enough iterations. This value can sometimes be useful as a generation counter of sorts (it "ticks" the number of loop iterations), as it roughly corresponds with -C and C calls. +C and C calls - and is incremented between the +prepare and check phases. -=item unsigned int ev_loop_depth (loop) +=item unsigned int ev_depth (loop) Returns the number of times C was entered minus the number of times C was exited, in other words, the recursion depth. @@ -655,7 +662,8 @@ in which case it is higher. Leaving C abnormally (setjmp/longjmp, cancelling the thread -etc.), doesn't count as exit. +etc.), doesn't count as "exit" - consider this as a hint to avoid such +ungentleman behaviour unless it's really convenient. =item unsigned int ev_backend (loop) @@ -699,7 +707,7 @@ Effectively, all C watchers will be delayed by the time spend between C and C, and all C watchers will be rescheduled (that is, they will lose any events that would have -occured while suspended). +occurred while suspended). After calling C you B call I function on the given loop other than C, and you B call C @@ -786,7 +794,7 @@ This "unloop state" will be cleared when entering C again. -It is safe to call C from otuside any C calls. +It is safe to call C from outside any C calls. =item ev_ref (loop) @@ -866,7 +874,7 @@ you do transactions with the outside world and you can't increase the parallelity, then this setting will limit your transaction rate (if you need to poll once per transaction and the I/O collect interval is 0.01, -then you can't do more than 100 transations per second). +then you can't do more than 100 transactions per second). Setting the I can improve the opportunity for saving power, as the program will "bundle" timer callback invocations that @@ -1374,7 +1382,7 @@ you can associate an C watcher to each such watcher, and in the normal watcher callback, you just start the idle watcher. The real processing is done in the idle watcher callback. This causes libev to -continously poll and process kernel event data for the watcher, but when +continuously poll and process kernel event data for the watcher, but when the lock-out case is known to be rare (which in turn is rare :), this is workable. @@ -1398,7 +1406,7 @@ // are not yet ready to handle it. ev_io_stop (EV_A_ w); - // start the idle watcher to ahndle the actual event. + // start the idle watcher to handle the actual event. // it will not be executed as long as other watchers // with the default priority are receiving events. ev_idle_start (EV_A_ &idle); @@ -1462,7 +1470,7 @@ known-to-be-good backend (at the time of this writing, this includes only C and C). The same applies to file descriptors for which non-blocking operation makes no sense (such as -files) - libev doesn't guarentee any specific behaviour in that case. +files) - libev doesn't guarantee any specific behaviour in that case. Another thing you have to watch out for is that it is quite easy to receive "spurious" readiness notifications, that is your callback might @@ -1540,7 +1548,7 @@ =head3 The special problem of accept()ing when you can't Many implementations of the POSIX C function (for example, -found in port-2004 Linux) have the peculiar behaviour of not removing a +found in post-2004 Linux) have the peculiar behaviour of not removing a connection from the pending queue in all error cases. For example, larger servers often run out of file descriptors (because @@ -1731,7 +1739,7 @@ // if last_activity + 60. is older than now, we did time out if (timeout < now) { - // timeout occured, take action + // timeout occurred, take action } else { @@ -1768,7 +1776,7 @@ And when there is some activity, simply store the current time in C, no libev calls at all: - last_actiivty = ev_now (loop); + last_activity = ev_now (loop); This technique is slightly more complex, but in most cases where the time-out is unlikely to be triggered, much more efficient. @@ -2117,7 +2125,7 @@ potentially a lot of jitter, but good long-term stability. static void - clock_cb (struct ev_loop *loop, ev_io *w, int revents) + clock_cb (struct ev_loop *loop, ev_periodic *w, int revents) { ... its now a full hour (UTC, or TAI or whatever your clock follows) } @@ -2959,7 +2967,7 @@ =head3 The special problem of life after fork - how is it possible? -Most uses of C consist of forking, then some simple calls to ste +Most uses of C consist of forking, then some simple calls to set up/change the process environment, followed by a call to C. This sequence should be handled by libev without any problems. @@ -3003,17 +3011,16 @@ =back -=head2 C - how to wake up another event loop +=head2 C - how to wake up an event loop In general, you cannot use an C from multiple threads or other asynchronous sources such as signal handlers (as opposed to multiple event loops - those are of course safe to use in different threads). -Sometimes, however, you need to wake up another event loop you do not -control, for example because it belongs to another thread. This is what -C watchers do: as long as the C watcher is active, you -can signal it by calling C, which is thread- and signal -safe. +Sometimes, however, you need to wake up an event loop you do not control, +for example because it belongs to another thread. This is what C +watchers do: as long as the C watcher is active, you can signal +it by calling C, which is thread- and signal safe. This functionality is very similar to C watchers, as signals, too, are asynchronous in nature, and signals, too, will be compressed @@ -3336,8 +3343,6 @@ =item w->set (object *) -This is an B feature that might go away in a future version. - This is a variation of a method callback - leaving out the method to call will default the method to C, which makes it possible to use functor objects without having to manually specify the C all @@ -3659,7 +3664,7 @@ Symbols marked with "(h)" do not change the ABI, and can have different values when compiling libev vs. including F, so it is permissible -to redefine them before including F without breakign compatibility +to redefine them before including F without breaking compatibility to a compiled library. All other symbols change the ABI, which means all users of libev and the libev code itself must be compiled with compatible settings. @@ -3881,7 +3886,7 @@ If undefined or defined to be C<1> (and the platform supports it), then the respective watcher type is supported. If defined to be C<0>, then it -is not. Disabling watcher types mainly saves codesize. +is not. Disabling watcher types mainly saves code size. =item EV_FEATURES @@ -3911,17 +3916,17 @@ Use larger code to speed up some operations. -Currently this is used to override some inlining decisions (enlarging the roughly -30% code size on amd64. +Currently this is used to override some inlining decisions (enlarging the +code size by roughly 30% on amd64). When optimising for size, use of compiler flags such as C<-Os> with -gcc recommended, as well as C<-DNDEBUG>, as libev contains a number of +gcc is recommended, as well as C<-DNDEBUG>, as libev contains a number of assertions. =item C<2> - faster/larger data structures Replaces the small 2-heap for timer management by a faster 4-heap, larger -hash table sizes and so on. This will usually further increase codesize +hash table sizes and so on. This will usually further increase code size and can additionally have an effect on the size of data structures at runtime. @@ -3968,7 +3973,7 @@ =item EV_AVOID_STDIO If this is set to C<1> at compiletime, then libev will avoid using stdio -functions (printf, scanf, perror etc.). This will increase the codesize +functions (printf, scanf, perror etc.). This will increase the code size somewhat, but if your program doesn't otherwise depend on stdio and your libc allows it, this avoids linking in the stdio library which is quite big. @@ -3982,7 +3987,7 @@ signals): Normally, libev tries to deduce the maximum number of signals automatically, but sometimes this fails, in which case it can be specified. Also, using a lower number than detected (C<32> should be -good for about any system in existance) can save some memory, as libev +good for about any system in existence) can save some memory, as libev statically allocates some 12-24 bytes per signal number. =item EV_PID_HASHSIZE @@ -4038,7 +4043,7 @@ =item EV_COMMON By default, all watchers have a C member. By redefining -this macro to a something else you can include more and other types of +this macro to something else you can include more and other types of members. You have to define it each time you include one of the files, though, and it must be identical each time. @@ -4347,7 +4352,7 @@ And of course, some compiler warnings are just plain stupid, or simply wrong (because they don't actually warn about the condition their message seems to warn about). For example, certain older gcc versions had some -warnings that resulted an extreme number of false positives. These have +warnings that resulted in an extreme number of false positives. These have been fixed, but some people still insist on making code warn-free with such buggy versions. @@ -4393,19 +4398,101 @@ =head1 PORTABILITY NOTES +=head2 GNU/LINUX 32 BIT LIMITATIONS + +GNU/Linux is the only common platform that supports 64 bit file/large file +interfaces but I them by default. + +That means that libev compiled in the default environment doesn't support +files larger than 2GiB or so, which mainly affects C watchers. + +Unfortunately, many programs try to work around this GNU/Linux issue +by enabling the large file API, which makes them incompatible with the +standard libev compiled for their system. + +Likewise, libev cannot enable the large file API itself as this would +suddenly make it incompatible to the default compile time environment, +i.e. all programs not using special compile switches. + +=head2 OS/X AND DARWIN BUGS + +The whole thing is a bug if you ask me - basically any system interface +you touch is broken, whether it is locales, poll, kqueue or even the +OpenGL drivers. + +=head3 C is buggy + +The kqueue syscall is broken in all known versions - most versions support +only sockets, many support pipes. + +=head3 C is buggy + +Instead of fixing C, Apple replaced their (working) C +implementation by something calling C internally around the 10.5.6 +release, so now C I C are broken. + +Libev tries to work around this by neither using C nor C by +default on this rotten platform, but of course you cna still ask for them +when creating a loop. + +=head3 C, and of course Apple found a way to fuck this +one up as well: On OS/X, C backends. + +=head2 AIX POLL BUG + +AIX unfortunately has a broken C header. Libev works around +this by trying to avoid the poll backend altogether (i.e. it's not even +compiled in), which normally isn't a big problem as C function The winsocket C