--- AnyEvent/lib/AnyEvent.pm 2007/11/16 09:13:11 1.36 +++ AnyEvent/lib/AnyEvent.pm 2008/04/07 19:00:55 1.40 @@ -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.6'; +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::], @@ -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"