… | |
… | |
161 | |
161 | |
162 | =head2 SIGNAL WATCHERS |
162 | =head2 SIGNAL WATCHERS |
163 | |
163 | |
164 | You can listen for signals using a signal watcher, C<signal> is the signal |
164 | You can listen for signals using a signal watcher, C<signal> is the signal |
165 | I<name> without any C<SIG> prefix. Multiple signals events can be clumped |
165 | I<name> without any C<SIG> prefix. Multiple signals events can be clumped |
166 | together into one callback invocation, and callbakc invocation might or |
166 | together into one callback invocation, and callback invocation might or |
167 | might not be asynchronous. |
167 | might not be asynchronous. |
168 | |
168 | |
169 | These watchers might use C<%SIG>, so programs overwriting those signals |
169 | These watchers might use C<%SIG>, so programs overwriting those signals |
170 | directly will likely not work correctly. |
170 | directly will likely not work correctly. |
171 | |
171 | |
… | |
… | |
247 | |
247 | |
248 | no warnings; |
248 | no warnings; |
249 | use strict; |
249 | use strict; |
250 | use Carp; |
250 | use Carp; |
251 | |
251 | |
252 | our $VERSION = '2.5'; |
252 | our $VERSION = '2.52'; |
253 | our $MODEL; |
253 | our $MODEL; |
254 | |
254 | |
255 | our $AUTOLOAD; |
255 | our $AUTOLOAD; |
256 | our @ISA; |
256 | our @ISA; |
257 | |
257 | |
… | |
… | |
288 | unless ($MODEL) { |
288 | unless ($MODEL) { |
289 | # try to load a model |
289 | # try to load a model |
290 | |
290 | |
291 | for (@REGISTRY, @models) { |
291 | for (@REGISTRY, @models) { |
292 | my ($package, $model) = @$_; |
292 | my ($package, $model) = @$_; |
|
|
293 | if (eval "require $package" |
|
|
294 | and ${"$package\::VERSION"} > 0 |
293 | if (eval "require $model") { |
295 | and eval "require $model") { |
294 | $MODEL = $model; |
296 | $MODEL = $model; |
295 | warn "AnyEvent: autoprobed and loaded model '$model', using it.\n" if $verbose > 1; |
297 | warn "AnyEvent: autoprobed and loaded model '$model', using it.\n" if $verbose > 1; |
296 | last; |
298 | last; |
297 | } |
299 | } |
298 | } |
300 | } |
… | |
… | |
384 | or Carp::croak "required option 'pid' is missing"; |
386 | or Carp::croak "required option 'pid' is missing"; |
385 | |
387 | |
386 | $PID_CB{$pid}{$arg{cb}} = $arg{cb}; |
388 | $PID_CB{$pid}{$arg{cb}} = $arg{cb}; |
387 | |
389 | |
388 | unless ($WNOHANG) { |
390 | unless ($WNOHANG) { |
389 | $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_child_wait); |
|
|
390 | $WNOHANG = eval { require POSIX; &POSIX::WNOHANG } || 1; |
391 | $WNOHANG = eval { require POSIX; &POSIX::WNOHANG } || 1; |
391 | } |
392 | } |
392 | |
393 | |
|
|
394 | unless ($CHLD_W) { |
|
|
395 | $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_child_wait); |
393 | # child could be a zombie already |
396 | # child could be a zombie already |
394 | $PID_IDLE ||= AnyEvent->timer (after => 0, cb => \&_child_wait); |
397 | $PID_IDLE ||= AnyEvent->timer (after => 0, cb => \&_child_wait); |
|
|
398 | } |
395 | |
399 | |
396 | bless [$pid, $arg{cb}], "AnyEvent::Base::Child" |
400 | bless [$pid, $arg{cb}], "AnyEvent::Base::Child" |
397 | } |
401 | } |
398 | |
402 | |
399 | sub AnyEvent::Base::Child::DESTROY { |
403 | sub AnyEvent::Base::Child::DESTROY { |