--- AnyEvent/lib/AnyEvent.pm 2006/12/11 01:16:09 1.20 +++ AnyEvent/lib/AnyEvent.pm 2007/11/16 09:13:11 1.36 @@ -72,7 +72,7 @@ C the Perl I (not filedescriptor) to watch for events. C must be a string that is either C or C, that creates -a watcher waiting for "r"eadable or "w"ritable events. C teh callback +a watcher waiting for "r"eadable or "w"ritable events. C the callback to invoke everytime the filehandle becomes ready. Only one io watcher per C and C combination is allowed (i.e. on @@ -163,7 +163,7 @@ You can listen for signals using a signal watcher, C is the signal I without any C prefix. Multiple signals events can be clumped -together into one callback invocation, and callbakc invocation might or +together into one callback invocation, and callback invocation might or might not be asynchronous. These watchers might use C<%SIG>, so programs overwriting those signals @@ -176,8 +176,10 @@ =head2 CHILD PROCESS WATCHERS You can also listen for the status of a child process specified by the -C argument. The watcher will only trigger once. This works by -installing a signal handler for C. +C argument (or any child if the pid argument is 0). 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). Example: wait for pid 1333 @@ -197,8 +199,10 @@ The known classes so far are: - AnyEvent::Impl::Coro based on Coro::Event, best choise. - AnyEvent::Impl::Event based on Event, also best choice :) + AnyEvent::Impl::CoroEV based on Coro::EV, best choice. + AnyEvent::Impl::EV based on EV (an interface to libev, also best choice). + AnyEvent::Impl::Coro based on Coro::Event, second best choice. + AnyEvent::Impl::Event based on Event, also second best choice :) AnyEvent::Impl::Glib based on Glib, second-best choice. AnyEvent::Impl::Tk based on Tk, very bad choice. AnyEvent::Impl::Perl pure-perl implementation, inefficient. @@ -247,9 +251,10 @@ no warnings; use strict; + use Carp; -our $VERSION = '2.5'; +our $VERSION = '2.6'; our $MODEL; our $AUTOLOAD; @@ -260,6 +265,8 @@ our @REGISTRY; my @models = ( + [Coro::EV:: => AnyEvent::Impl::CoroEV::], + [EV:: => AnyEvent::Impl::EV::], [Coro::Event:: => AnyEvent::Impl::Coro::], [Event:: => AnyEvent::Impl::Event::], [Glib:: => AnyEvent::Impl::Glib::], @@ -290,7 +297,9 @@ for (@REGISTRY, @models) { my ($package, $model) = @$_; - if (eval "require $model") { + if (eval "require $package" + and ${"$package\::VERSION"} > 0 + and eval "require $model") { $MODEL = $model; warn "AnyEvent: autoprobed and loaded model '$model', using it.\n" if $verbose > 1; last; @@ -298,7 +307,7 @@ } $MODEL - or die "No event module selected for AnyEvent and autodetect failed. Install any one of these modules: Event (or Coro+Event), Glib or Tk."; + or die "No event module selected for AnyEvent and autodetect failed. Install any one of these modules: EV (or Coro+EV), Event (or Coro+Event), Glib or Tk."; } unshift @ISA, $MODEL; @@ -370,8 +379,9 @@ our $WNOHANG; sub _child_wait { - while (0 < (my $pid = waitpid -1, $WNOHANG)) { - $_->() for values %{ (delete $PID_CB{$pid}) || {} }; + while (0 <= (my $pid = waitpid -1, $WNOHANG)) { + $_->($pid, $?) for (values %{ $PID_CB{$pid} || {} }), + (values %{ $PID_CB{0} || {} }); } undef $PID_IDLE; @@ -380,18 +390,20 @@ sub child { my (undef, %arg) = @_; - my $pid = uc $arg{pid} + defined (my $pid = $arg{pid} + 0) or Carp::croak "required option 'pid' is missing"; $PID_CB{$pid}{$arg{cb}} = $arg{cb}; unless ($WNOHANG) { - $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_child_wait); $WNOHANG = eval { require POSIX; &POSIX::WNOHANG } || 1; } - # child could be a zombie already - $PID_IDLE ||= AnyEvent->timer (after => 0, cb => \&_child_wait); + unless ($CHLD_W) { + $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_child_wait); + # child could be a zombie already + $PID_IDLE ||= AnyEvent->timer (after => 0, cb => \&_child_wait); + } bless [$pid, $arg{cb}], "AnyEvent::Base::Child" } @@ -437,7 +449,7 @@ I also cheats a bit by not providing blocking access to condition variables: code blocking while waiting for a condition will C. This still works with most modules/usages, and blocking calls must -not be in an interactive appliation, so it makes sense. +not be in an interactive application, so it makes sense. =head1 ENVIRONMENT VARIABLES