--- AnyEvent/lib/AnyEvent.pm 2007/11/09 19:34:32 1.33 +++ AnyEvent/lib/AnyEvent.pm 2008/04/07 19:00:55 1.40 @@ -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 @@ -111,7 +111,7 @@ }); # to cancel the timer: - undef $w + undef $w; =head2 CONDITION WATCHERS @@ -201,7 +201,7 @@ 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::CoroEvent 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. @@ -254,7 +254,7 @@ use Carp; -our $VERSION = '2.55'; +our $VERSION = '2.9'; our $MODEL; our $AUTOLOAD; @@ -267,7 +267,7 @@ my @models = ( [Coro::EV:: => AnyEvent::Impl::CoroEV::], [EV:: => AnyEvent::Impl::EV::], - [Coro::Event:: => AnyEvent::Impl::Coro::], + [Coro::Event:: => AnyEvent::Impl::CoroEvent::], [Event:: => AnyEvent::Impl::Event::], [Glib:: => AnyEvent::Impl::Glib::], [Tk:: => AnyEvent::Impl::Tk::], @@ -307,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; @@ -375,11 +375,12 @@ our %PID_CB; our $CHLD_W; +our $CHLD_DELAY_W; our $PID_IDLE; our $WNOHANG; sub _child_wait { - while (0 <= (my $pid = waitpid -1, $WNOHANG)) { + while (0 < (my $pid = waitpid -1, $WNOHANG)) { $_->($pid, $?) for (values %{ $PID_CB{$pid} || {} }), (values %{ $PID_CB{0} || {} }); } @@ -387,6 +388,14 @@ undef $PID_IDLE; } +sub _sigchld { + # make sure we deliver these changes "synchronous" with the event loop. + $CHLD_DELAY_W ||= AnyEvent->timer (after => 0, cb => sub { + undef $CHLD_DELAY_W; + &_child_wait; + }); +} + sub child { my (undef, %arg) = @_; @@ -400,9 +409,9 @@ } 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); + $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_sigchld); + # child could be a zombie already, so make at least one round + &_sigchld; } bless [$pid, $arg{cb}], "AnyEvent::Base::Child"