--- AnyEvent/lib/AnyEvent.pm 2008/04/25 13:48:42 1.84 +++ AnyEvent/lib/AnyEvent.pm 2008/04/25 14:01:48 1.86 @@ -143,12 +143,16 @@ You can create an I/O watcher by calling the C<< AnyEvent->io >> method with the following mandatory key-value pairs as arguments: -C the Perl I (I file descriptor) to watch for -events. C must be a string that is either C or C, which -creates a watcher waiting for "r"eadable or "w"ritable events, +C the Perl I (I file descriptor) to watch +for events. C must be a string that is either C or C, +which creates a watcher waiting for "r"eadable or "w"ritable events, respectively. C is the callback to invoke each time the file handle becomes ready. +Although the callback might get passed parameters, their value and +presence is undefined and you cannot rely on them. Portable AnyEvent +callbacks cannot use arguments passed to I/O watcher callbacks. + The I/O watcher might use the underlying file descriptor or a copy of it. You must not close a file handle as long as any watcher is active on the underlying file descriptor. @@ -157,10 +161,6 @@ always use non-blocking calls when reading/writing from/to your file handles. -Although the callback might get passed parameters, their value and -presence is undefined and you cannot rely on them. Portable AnyEvent -callbacks cannot use arguments passed to I/O watcher callbacks. - Example: # wait for readability of STDIN, then read a line and disable the watcher @@ -176,17 +176,17 @@ method with the following mandatory arguments: C specifies after how many seconds (fractional values are -supported) should the timer activate. C the callback to invoke in that -case. - -The timer callback will be invoked at most once: if you want a repeating -timer you have to create a new watcher (this is a limitation by both Tk -and Glib). +supported) the callback should be invoked. C is the callback to invoke +in that case. Although the callback might get passed parameters, their value and presence is undefined and you cannot rely on them. Portable AnyEvent callbacks cannot use arguments passed to time watcher callbacks. +The timer callback will be invoked at most once: if you want a repeating +timer you have to create a new watcher (this is a limitation by both Tk +and Glib). + Example: # fire an event after 7.7 seconds @@ -236,6 +236,10 @@ I without any C prefix, C is the Perl callback to be invoked whenever a signal occurs. +Although the callback might get passed parameters, their value and +presence is undefined and you cannot rely on them. Portable AnyEvent +callbacks cannot use arguments passed to signal watcher callbacks. + Multiple signal occurances can be clumped together into one callback invocation, and callback invocation will be synchronous. synchronous means that it might take a while until the signal gets handled by the process, @@ -259,7 +263,8 @@ watches for any child process exit). The watcher will trigger as often as status change for the child are received. This works by installing a signal handler for C. The callback will be called with the pid -and exit status (as returned by waitpid). +and exit status (as returned by waitpid), so unlike other watcher types, +you I rely on child watcher callback arguments. There is a slight catch to child watchers, however: you usually start them I the child process was created, and this means the process could @@ -961,12 +966,11 @@ natively. The pure perl implementation is hit in a few sweet spots (both the -zero timeout and the use of a single fd hit optimisations in the perl -interpreter and the backend itself, and all watchers become ready at the -same time). Nevertheless this shows that it adds very little overhead in -itself. Like any select-based backend its performance becomes really bad -with lots of file descriptors (and few of them active), of course, but -this was not subject of this benchmark. +constant timeout and the use of a single fd hit optimisations in the perl +interpreter and the backend itself). Nevertheless this shows that it +adds very little overhead in itself. Like any select-based backend its +performance becomes really bad with lots of file descriptors (and few of +them active), of course, but this was not subject of this benchmark. The C module has a relatively high setup and callback invocation cost, but overall scores on the third place. @@ -987,7 +991,7 @@ hidden memory cost inside the kernel, though, that is not reflected in the figures above). -C, regardless of underlying event loop (wether using its pure perl +C, regardless of underlying event loop (whether using its pure perl select-based backend or the Event module) shows abysmal performance and memory usage: Watchers use almost 30 times as much memory as EV watchers, and 10 times as much memory as both Event or EV via AnyEvent. Watcher