--- cvsroot/EV/EV.pm 2007/11/27 10:59:10 1.56 +++ cvsroot/EV/EV.pm 2007/12/17 07:24:12 1.71 @@ -60,7 +60,8 @@ below is comprehensive, one might also consult the documentation of libev itself (L) for more subtle details on watcher semantics or some discussion on the available backends, or how to -force a specific backend with C. +force a specific backend with C, or just about in any case +because it has much more detailed information. =cut @@ -69,7 +70,7 @@ use strict; BEGIN { - our $VERSION = '1.4'; + our $VERSION = '1.86'; use XSLoader; XSLoader::load "EV", $VERSION; } @@ -94,7 +95,7 @@ =item $EV::DIED Must contain a reference to a function that is called when a callback -throws an exception (with $@ containing thr error). The default prints an +throws an exception (with $@ containing the error). The default prints an informative message and continues. If this callback throws an exception it will be silently ignored. @@ -133,6 +134,11 @@ When called with an argument of EV::UNLOOP_ALL, all calls to EV::loop will return as fast as possible. +=item $count = EV::loop_count + +Return the number of times the event loop has polled for new +events. Sometiems useful as a generation counter. + =item EV::once $fh_or_undef, $events, $timeout, $cb->($revents) This function rolls together an I/O and a timer watcher for a single @@ -156,8 +162,20 @@ of them triggers, then they will be stopped and freed, and the callback invoked. +=item EV::feed_fd_event ($fd, $revents) + +Feed an event on a file descriptor into EV. EV will react to this call as +if the readyness notifications specified by C<$revents> (a combination of +C and C) happened on the file descriptor C<$fd>. + +=item EV::feed_signal_event ($signal) + +Feed a signal event into EV. EV will react to this call as if the signal +specified by C<$signal> had occured. + =back + =head2 WATCHER OBJECTS A watcher is an object that gets created to record your interest in some @@ -177,7 +195,7 @@ Each watcher type has its associated bit in revents, so you can use the same callback for multiple watchers. The event mask is named after the type, i..e. EV::child sets EV::CHILD, EV::prepare sets EV::PREPARE, -EV::periodic sets EV::PERIODIC and so on, with the exception of IO events +EV::periodic sets EV::PERIODIC and so on, with the exception of I/O events (which can set both EV::READ and EV::WRITE bits), and EV::timer (which uses EV::TIMEOUT). @@ -209,7 +227,7 @@ Stop a watcher if it is active. Also clear any pending events (events that have been received but that didn't yet result in a callback invocation), -regardless of wether the watcher was active or not. +regardless of whether the watcher was active or not. =item $bool = $w->is_active @@ -249,10 +267,21 @@ Note that the priority semantics have not yet been fleshed out and are subject to almost certain change. -=item $w->trigger ($revents) +=item $w->invoke ($revents) Call the callback *now* with the given event mask. +=item $w->feed_event ($revents) + +Feed some events on this watcher into EV. EV will react to this call as if +the watcher had received the given C<$revents> mask. + +=item $revents = $w->clear_pending + +If the watcher is pending, this function returns clears its pending status +and returns its C<$revents> bitset (as if its callback was invoked). If the +watcher isn't pending it does nothing and returns C<0>. + =item $previous_state = $w->keepalive ($bool) Normally, C will return when there are no active watchers @@ -274,7 +303,7 @@ The initial value for keepalive is true (enabled), and you cna change it any time. -Example: Register an IO watcher for some UDP socket but do not keep the +Example: Register an I/O watcher for some UDP socket but do not keep the event loop from running just because of that watcher. my $udp_socket = ... @@ -288,7 +317,7 @@ Each of the following subsections describes a single watcher type. -=head3 IO WATCHERS - is this file descriptor readable or writable? +=head3 I/O WATCHERS - is this file descriptor readable or writable? =over 4 @@ -467,6 +496,10 @@ Simply stops and starts the watcher again. +=item $time = $w->at + +Return the time that the watcher is expected to trigger next. + =back @@ -578,6 +611,41 @@ The C variant doesn't start (activate) the newly created watcher. +=item ... = $w->stat + +This call is very similar to the perl C built-in: It stats (using +C) the path specified in the watcher and sets perls stat cache (as +well as EV's idea of the current stat values) to the values found. + +In scalar context, a boolean is return indicating success or failure of +the stat. In list context, the same 13-value list as with stat is returned +(except that the blksize and blocks fields are not reliable). + +In the case of an error, errno is set to C (regardless of the +actual error value) and the C value is forced to zero (if the stat +was successful then nlink is guaranteed to be non-zero). + +See also the next two entries for more info. + +=item ... = $w->attr + +Just like C<< $w->stat >>, but without the initial stat'ing: this returns +the values most recently detected by EV. See the next entry for more info. + +=item ... = $w->prev + +Just like C<< $w->stat >>, but without the initial stat'ing: this returns +the previous set of values, before the change. + +That is, when the watcher callback is invoked, C<< $w->prev >> will be set +to the values found I a change was detected, while C<< $w->attr >> +returns the values found leading to the change detection. The difference (if any) +between C and C is what triggered the callback. + +If you did something to the filesystem object and do not want to trigger +yet another change, you can call C to update EV's idea of what the +current attributes are. + =item $w->set ($path, $interval) Reconfigures the watcher, see the constructor above for details. Can be @@ -607,12 +675,24 @@ =item $w = EV::idle_ns $callback -Call the callback when there are no pending io, timer/periodic, signal or -child events, i.e. when the process is idle. +Call the callback when there are no other pending watchers of the same or +higher priority (excluding check, prepare and other idle watchers of the +same or lower priority, of course). They are called idle watchers because +when the watcher is the highest priority pending event in the process, the +process is considered to be idle at that priority. + +If you want a watcher that is only ever called when I other events are +outstanding you have to set the priority to C. The process will not block as long as any idle watchers are active, and they will be called repeatedly until stopped. +For example, if you have idle watchers at priority C<0> and C<1>, and +an I/O watcher at priority C<0>, then the idle watcher at priority C<1> +and the I/O watcher will always run when ready. Only when the idle watcher +at priority C<1> is stopped and the I/O watcher at priority C<0> is not +pending with the C<0>-priority idle watcher be invoked. + The C variant doesn't start (activate) the newly created watcher. =back @@ -662,7 +742,7 @@ # make the dispatcher handle any outstanding stuff ... not shown - # create an IO watcher for each and every socket + # create an I/O watcher for each and every socket @snmp_watcher = ( (map { EV::io $_, EV::READ, sub { } } keys %{ $dispatcher->{_descriptors} }), @@ -715,6 +795,25 @@ =back +=head1 PERL SIGNALS + +While Perl signal handling (C<%SIG>) is not affected by EV, the behaviour +with EV is as the same as any other C library: Perl-signals will only be +handled when Perl runs, which means your signal handler might be invoked +only the next time an event callback is invoked. + +The solution is to use EV signal watchers (see C), which will +ensure proper operations with regards to other event watchers. + +If you cannot do this for whatever reason, you can also force a watcher +to be called on every event loop iteration by installing a C +watcher: + + my $async_check = EV::check sub { }; + +This ensures that perl shortly gets into control for a short time, and +also ensures slower overall operation. + =head1 THREADS Threads are not supported by this module in any way. Perl pseudo-threads @@ -745,13 +844,14 @@ }; default_loop - or die 'EV: cannot initialise libev backend. bad $ENV{LIBEV_METHODS}?'; + or die 'EV: cannot initialise libev backend. bad $ENV{LIBEV_FLAGS}?'; 1; =head1 SEE ALSO -L. +L (asynchronous dns), L (makes Glib/Gtk2 use EV as +event loop), L (efficient coroutines with EV). =head1 AUTHOR