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.31 by root, Fri Nov 2 19:20:36 2007 UTC vs.
Revision 1.33 by root, Fri Nov 9 19:34:32 2007 UTC

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 (or any child if the pid argument is 0). The watcher will 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 180trigger as often as status change for the child are received. This works
181by installing a signal handler for C<SIGCHLD>. 181by installing a signal handler for C<SIGCHLD>. The callback will be called with
182the pid and exit status (as returned by waitpid).
182 183
183Example: wait for pid 1333 184Example: wait for pid 1333
184 185
185 my $w = AnyEvent->child (pid => 1333, cb => sub { warn "exit status $?" }); 186 my $w = AnyEvent->child (pid => 1333, cb => sub { warn "exit status $?" });
186 187
196C<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
197AnyEvent has been extended at runtime (e.g. in I<rxvt-unicode>). 198AnyEvent has been extended at runtime (e.g. in I<rxvt-unicode>).
198 199
199The known classes so far are: 200The known classes so far are:
200 201
202 AnyEvent::Impl::CoroEV based on Coro::EV, best choice.
201 EV::AnyEvent based on EV (an interface to libev, best choice) 203 AnyEvent::Impl::EV based on EV (an interface to libev, also best choice).
202 AnyEvent::Impl::Coro based on Coro::Event, second best choice. 204 AnyEvent::Impl::Coro based on Coro::Event, second best choice.
203 AnyEvent::Impl::Event based on Event, also second best choice :) 205 AnyEvent::Impl::Event based on Event, also second best choice :)
204 AnyEvent::Impl::Glib based on Glib, second-best choice. 206 AnyEvent::Impl::Glib based on Glib, second-best choice.
205 AnyEvent::Impl::Tk based on Tk, very bad choice. 207 AnyEvent::Impl::Tk based on Tk, very bad choice.
206 AnyEvent::Impl::Perl pure-perl implementation, inefficient. 208 AnyEvent::Impl::Perl pure-perl implementation, inefficient.
261our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1; 263our $verbose = $ENV{PERL_ANYEVENT_VERBOSE}*1;
262 264
263our @REGISTRY; 265our @REGISTRY;
264 266
265my @models = ( 267my @models = (
268 [Coro::EV:: => AnyEvent::Impl::CoroEV::],
269 [EV:: => AnyEvent::Impl::EV::],
266 [Coro::Event:: => AnyEvent::Impl::Coro::], 270 [Coro::Event:: => AnyEvent::Impl::Coro::],
267 [EV:: => EV::AnyEvent::],
268 [Event:: => AnyEvent::Impl::Event::], 271 [Event:: => AnyEvent::Impl::Event::],
269 [Glib:: => AnyEvent::Impl::Glib::], 272 [Glib:: => AnyEvent::Impl::Glib::],
270 [Tk:: => AnyEvent::Impl::Tk::], 273 [Tk:: => AnyEvent::Impl::Tk::],
271 [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::], 274 [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::],
272); 275);
374our $CHLD_W; 377our $CHLD_W;
375our $PID_IDLE; 378our $PID_IDLE;
376our $WNOHANG; 379our $WNOHANG;
377 380
378sub _child_wait { 381sub _child_wait {
379 while (0 < (my $pid = waitpid -1, $WNOHANG)) { 382 while (0 <= (my $pid = waitpid -1, $WNOHANG)) {
380 $_->() for (values %{ $PID_CB{$pid} || {} }), 383 $_->($pid, $?) for (values %{ $PID_CB{$pid} || {} }),
381 (values %{ $PID_CB{0} || {} }); 384 (values %{ $PID_CB{0} || {} });
382 } 385 }
383 386
384 undef $PID_IDLE; 387 undef $PID_IDLE;
385} 388}
386 389

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines