--- libev/ev.pod 2008/10/28 12:31:38 1.206 +++ libev/ev.pod 2008/10/30 08:09:30 1.210 @@ -300,7 +300,7 @@ Note that this function is I thread-safe, so if you want to use it from multiple threads, you have to lock (note also that this is unlikely, -as loops cannot bes hared easily between threads anyway). +as loops cannot be shared easily between threads anyway). The default loop is the only loop that can handle C and C watchers, and to do this, it always registers a handler @@ -388,27 +388,29 @@ like O(total_fds) where n is the total number of fds (or the highest fd), epoll scales either O(1) or O(active_fds). -The epoll syscalls are the most misdesigned of the more advanced event -mechanisms: problems include silently dropping fds, requiring a system -call per change per fd (and unnecessary guessing of parameters), problems -with dup and so on. The biggest issue is fork races, however - if a -program forks then I parent and child process have to recreate the -epoll set, which can take considerable time (one syscall per fd) and is of -course hard to detect. +The epoll mechanism deserves honorable mention as the most misdesigned +of the more advanced event mechanisms: mere annoyances include silently +dropping file descriptors, requiring a system call per change per file +descriptor (and unnecessary guessing of parameters), problems with dup and +so on. The biggest issue is fork races, however - if a program forks then +I parent and child process have to recreate the epoll set, which can +take considerable time (one syscall per file descriptor) and is of course +hard to detect. -Epoll is also notoriously buggy - embedding epoll fds should work, but -of course doesn't, and epoll just loves to report events for totally +Epoll is also notoriously buggy - embedding epoll fds I work, but +of course I, and epoll just loves to report events for totally I file descriptors (even already closed ones, so one cannot even remove them from the set) than registered in the set (especially on SMP systems). Libev tries to counter these spurious notifications by employing an additional generation counter and comparing that against the -events to filter out spurious ones. +events to filter out spurious ones, recreating the set when required. While stopping, setting and starting an I/O watcher in the same iteration -will result in some caching, there is still a system call per such incident -(because the fd could point to a different file description now), so its -best to avoid that. Also, C'ed file descriptors might not work -very well if you register events for both fds. +will result in some caching, there is still a system call per such +incident (because the same I could point to a different +I now), so its best to avoid that. Also, C'ed +file descriptors might not work very well if you register events for both +file descriptors. Best performance from this backend is achieved by not unregistering all watchers for a file descriptor until it has been closed, if possible, @@ -426,12 +428,15 @@ =item C (value 8, most BSD clones) -Kqueue deserves special mention, as at the time of this writing, it was -broken on all BSDs except NetBSD (usually it doesn't work reliably with -anything but sockets and pipes, except on Darwin, where of course it's -completely useless). For this reason it's not being "auto-detected" unless -you explicitly specify it in the flags (i.e. using C) or -libev was compiled on a known-to-be-good (-enough) system like NetBSD. +Kqueue deserves special mention, as at the time of this writing, it +was broken on all BSDs except NetBSD (usually it doesn't work reliably +with anything but sockets and pipes, except on Darwin, where of course +it's completely useless). Unlike epoll, however, whose brokenness +is by design, these kqueue bugs can (and eventually will) be fixed +without API changes to existing programs. For this reason it's not being +"auto-detected" unless you explicitly specify it in the flags (i.e. using +C) or libev was compiled on a known-to-be-good (-enough) +system like NetBSD. You still can embed kqueue into a normal poll or select backend and use it only for sockets (after having made sure that sockets work with kqueue on @@ -649,7 +654,7 @@ A flags value of C will look for new events (waiting if necessary) and will handle those and any already outstanding ones. It will block your process until at least one new event arrives (which could -be an event internal to libev itself, so there is no guarentee that a +be an event internal to libev itself, so there is no guarantee that a user-registered callback will be called), and will return after one iteration of the loop. @@ -1924,8 +1929,9 @@ =head2 C - did the file attributes just change? This watches a file system path for attribute changes. That is, it calls -C regularly (or when the OS says it changed) and sees if it changed -compared to the last time, invoking the callback if it did. +C on that path in regular intervals (or when the OS says it changed) +and sees if it changed compared to the last time, invoking the callback if +it did. The path does not need to exist: changing from "path exists" to "path does not exist" is a status change like any other. The condition "path does @@ -1933,17 +1939,18 @@ otherwise always forced to be at least one) and all the other fields of the stat buffer having unspecified contents. -The path I be absolute and I end in a slash. If it is -relative and your working directory changes, the behaviour is undefined. - -Since there is no standard kernel interface to do this, the portable -implementation simply calls C regularly on the path to see if -it changed somehow. You can specify a recommended polling interval for -this case. If you specify a polling interval of C<0> (highly recommended!) -then a I value will be used (which -you can expect to be around five seconds, although this might change -dynamically). Libev will also impose a minimum interval which is currently -around C<0.1>, but thats usually overkill. +The path I end in a slash or contain special components such as +C<.> or C<..>. The path I be absolute: If it is relative and +your working directory changes, then the behaviour is undefined. + +Since there is no portable change notification interface available, the +portable implementation simply calls C regularly on the path +to see if it changed somehow. You can specify a recommended polling +interval for this case. If you specify a polling interval of C<0> (highly +recommended!) then a I value will be used +(which you can expect to be around five seconds, although this might +change dynamically). Libev will also impose a minimum interval which is +currently around C<0.1>, but that's usually overkill. This watcher type is not meant for massive numbers of stat watchers, as even with OS-supported change notifications, this can be @@ -1963,7 +1970,7 @@ use 64 bit file offsets the programs will fail. In that case you have to compile libev with the same flags to get binary compatibility. This is obviously the case with any flags that change the ABI, but the problem is -most noticeably disabled with ev_stat and large file support. +most noticeably displayed with ev_stat and large file support. The solution for this is to lobby your distribution maker to make large file interfaces available by default (as e.g. FreeBSD does) and not @@ -1992,9 +1999,9 @@ =head3 The special problem of stat time resolution -The C system call only supports full-second resolution portably, and -even on systems where the resolution is higher, most file systems still -only support whole seconds. +The C system call only supports full-second resolution portably, +and even on systems where the resolution is higher, most file systems +still only support whole seconds. That means that, if the time is the only thing that changes, you can easily miss updates: on the first update, C detects a change and @@ -2643,7 +2650,7 @@ =item ev_async_init (ev_async *, callback) Initialises and configures the async watcher - it has no parameters of any -kind. There is a C macro, but using it is utterly pointless, +kind. There is a C macro, but using it is utterly pointless, trust me. =item ev_async_send (loop, ev_async *) @@ -3086,7 +3093,7 @@ #include "ev.h" Both header files and implementation files can be compiled with a C++ -compiler (at least, thats a stated goal, and breakage will be treated +compiler (at least, that's a stated goal, and breakage will be treated as a bug). You need the following files in your source tree, or in a directory @@ -3568,7 +3575,7 @@ Care has been taken to ensure that libev does not keep local state inside C, and other calls do not usually allow for coroutine switches as -they do not clal any callbacks. +they do not call any callbacks. =head2 COMPILER WARNINGS @@ -3612,7 +3619,7 @@ ==2274== still reachable: 256 bytes in 1 blocks. Then there is no memory leak, just as memory accounted to global variables -is not a memleak - the memory is still being refernced, and didn't leak. +is not a memleak - the memory is still being referenced, and didn't leak. Similarly, under some circumstances, valgrind might report kernel bugs as if it were a bug in libev (e.g. in realloc or in the poll backend, @@ -3860,5 +3867,5 @@ =head1 AUTHOR -Marc Lehmann . +Marc Lehmann , with repeated corrections by Mikael Magnusson.