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.28 by root, Sat Oct 27 15:10:09 2007 UTC vs.
Revision 1.31 by root, Fri Nov 2 19:20:36 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
180trigger as often as status change for the child are received. This works
180installing a signal handler for C<SIGCHLD>. 181by installing a signal handler for C<SIGCHLD>.
181 182
182Example: wait for pid 1333 183Example: wait for pid 1333
183 184
184 my $w = AnyEvent->child (pid => 1333, cb => sub { warn "exit status $?" }); 185 my $w = AnyEvent->child (pid => 1333, cb => sub { warn "exit status $?" });
185 186
195C<AnyEvent::Impl:xxx> modules, but can be any other class in the case 196C<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>). 197AnyEvent has been extended at runtime (e.g. in I<rxvt-unicode>).
197 198
198The known classes so far are: 199The known classes so far are:
199 200
201 EV::AnyEvent based on EV (an interface to libev, best choice)
200 AnyEvent::Impl::Coro based on Coro::Event, best choice. 202 AnyEvent::Impl::Coro based on Coro::Event, second best choice.
201 EV::AnyEvent based on EV (an interface to libevent)
202 AnyEvent::Impl::Event based on Event, also best choice :) 203 AnyEvent::Impl::Event based on Event, also second best choice :)
203 AnyEvent::Impl::Glib based on Glib, second-best choice. 204 AnyEvent::Impl::Glib based on Glib, second-best choice.
204 AnyEvent::Impl::Tk based on Tk, very bad choice. 205 AnyEvent::Impl::Tk based on Tk, very bad choice.
205 AnyEvent::Impl::Perl pure-perl implementation, inefficient. 206 AnyEvent::Impl::Perl pure-perl implementation, inefficient.
206 207
207=item AnyEvent::detect 208=item AnyEvent::detect
374our $PID_IDLE; 375our $PID_IDLE;
375our $WNOHANG; 376our $WNOHANG;
376 377
377sub _child_wait { 378sub _child_wait {
378 while (0 < (my $pid = waitpid -1, $WNOHANG)) { 379 while (0 < (my $pid = waitpid -1, $WNOHANG)) {
379 $_->() for values %{ (delete $PID_CB{$pid}) || {} }; 380 $_->() for (values %{ $PID_CB{$pid} || {} }),
381 (values %{ $PID_CB{0} || {} });
380 } 382 }
381 383
382 undef $PID_IDLE; 384 undef $PID_IDLE;
383} 385}
384 386
385sub child { 387sub child {
386 my (undef, %arg) = @_; 388 my (undef, %arg) = @_;
387 389
388 my $pid = uc $arg{pid} 390 defined (my $pid = $arg{pid} + 0)
389 or Carp::croak "required option 'pid' is missing"; 391 or Carp::croak "required option 'pid' is missing";
390 392
391 $PID_CB{$pid}{$arg{cb}} = $arg{cb}; 393 $PID_CB{$pid}{$arg{cb}} = $arg{cb};
392 394
393 unless ($WNOHANG) { 395 unless ($WNOHANG) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines