ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/lib/AnyEvent.pm
(Generate patch)

Comparing AnyEvent/lib/AnyEvent.pm (file contents):
Revision 1.26 by root, Sun Jul 8 08:52:10 2007 UTC vs.
Revision 1.34 by root, Fri Nov 9 19:37:05 2007 UTC

174 my $w = AnyEvent->signal (signal => "INT", cb => sub { exit 1 }); 174 my $w = AnyEvent->signal (signal => "INT", cb => sub { exit 1 });
175 175
176=head2 CHILD PROCESS WATCHERS 176=head2 CHILD PROCESS WATCHERS
177 177
178You can also listen for the status of a child process specified by the 178You can also listen for the status of a child process specified by the
179C<pid> argument. The watcher will only trigger once. This works by 179C<pid> argument (or any child if the pid argument is 0). The watcher will
180installing a signal handler for C<SIGCHLD>. 180trigger as often as status change for the child are received. This works
181by installing a signal handler for C<SIGCHLD>. The callback will be called with
182the pid and exit status (as returned by waitpid).
181 183
182Example: wait for pid 1333 184Example: wait for pid 1333
183 185
184 my $w = AnyEvent->child (pid => 1333, cb => sub { warn "exit status $?" }); 186 my $w = AnyEvent->child (pid => 1333, cb => sub { warn "exit status $?" });
185 187
195C<AnyEvent::Impl:xxx> modules, but can be any other class in the case 197C<AnyEvent::Impl:xxx> modules, but can be any other class in the case
196AnyEvent has been extended at runtime (e.g. in I<rxvt-unicode>). 198AnyEvent has been extended at runtime (e.g. in I<rxvt-unicode>).
197 199
198The known classes so far are: 200The known classes so far are:
199 201
202 AnyEvent::Impl::CoroEV based on Coro::EV, best choice.
203 AnyEvent::Impl::EV based on EV (an interface to libev, also best choice).
200 AnyEvent::Impl::Coro based on Coro::Event, best choise. 204 AnyEvent::Impl::Coro based on Coro::Event, second best choice.
201 AnyEvent::Impl::Event based on Event, also best choice :) 205 AnyEvent::Impl::Event based on Event, also second best choice :)
202 AnyEvent::Impl::Glib based on Glib, second-best choice. 206 AnyEvent::Impl::Glib based on Glib, second-best choice.
203 AnyEvent::Impl::Tk based on Tk, very bad choice. 207 AnyEvent::Impl::Tk based on Tk, very bad choice.
204 AnyEvent::Impl::Perl pure-perl implementation, inefficient. 208 AnyEvent::Impl::Perl pure-perl implementation, inefficient.
205 209
206=item AnyEvent::detect 210=item AnyEvent::detect
248no warnings; 252no warnings;
249use strict; 253use strict;
250 254
251use Carp; 255use Carp;
252 256
253our $VERSION = '2.53'; 257our $VERSION = '2.6';
254our $MODEL; 258our $MODEL;
255 259
256our $AUTOLOAD; 260our $AUTOLOAD;
257our @ISA; 261our @ISA;
258 262
259our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1; 263our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1;
260 264
261our @REGISTRY; 265our @REGISTRY;
262 266
263my @models = ( 267my @models = (
268 [Coro::EV:: => AnyEvent::Impl::CoroEV::],
269 [EV:: => AnyEvent::Impl::EV::],
264 [Coro::Event:: => AnyEvent::Impl::Coro::], 270 [Coro::Event:: => AnyEvent::Impl::Coro::],
265 [Event:: => AnyEvent::Impl::Event::], 271 [Event:: => AnyEvent::Impl::Event::],
266 [Glib:: => AnyEvent::Impl::Glib::], 272 [Glib:: => AnyEvent::Impl::Glib::],
267 [Tk:: => AnyEvent::Impl::Tk::], 273 [Tk:: => AnyEvent::Impl::Tk::],
268 [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::], 274 [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::],
371our $CHLD_W; 377our $CHLD_W;
372our $PID_IDLE; 378our $PID_IDLE;
373our $WNOHANG; 379our $WNOHANG;
374 380
375sub _child_wait { 381sub _child_wait {
376 while (0 < (my $pid = waitpid -1, $WNOHANG)) { 382 while (0 <= (my $pid = waitpid -1, $WNOHANG)) {
377 $_->() for values %{ (delete $PID_CB{$pid}) || {} }; 383 $_->($pid, $?) for (values %{ $PID_CB{$pid} || {} }),
384 (values %{ $PID_CB{0} || {} });
378 } 385 }
379 386
380 undef $PID_IDLE; 387 undef $PID_IDLE;
381} 388}
382 389
383sub child { 390sub child {
384 my (undef, %arg) = @_; 391 my (undef, %arg) = @_;
385 392
386 my $pid = uc $arg{pid} 393 defined (my $pid = $arg{pid} + 0)
387 or Carp::croak "required option 'pid' is missing"; 394 or Carp::croak "required option 'pid' is missing";
388 395
389 $PID_CB{$pid}{$arg{cb}} = $arg{cb}; 396 $PID_CB{$pid}{$arg{cb}} = $arg{cb};
390 397
391 unless ($WNOHANG) { 398 unless ($WNOHANG) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines