… | |
… | |
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 | |
… | |
… | |
195 | C<AnyEvent::Impl:xxx> modules, but can be any other class in the case |
195 | C<AnyEvent::Impl:xxx> modules, but can be any other class in the case |
196 | AnyEvent has been extended at runtime (e.g. in I<rxvt-unicode>). |
196 | AnyEvent has been extended at runtime (e.g. in I<rxvt-unicode>). |
197 | |
197 | |
198 | The known classes so far are: |
198 | The known classes so far are: |
199 | |
199 | |
200 | AnyEvent::Impl::Coro based on Coro::Event, best choise. |
200 | AnyEvent::Impl::Coro based on Coro::Event, best choice. |
|
|
201 | EV::AnyEvent based on EV (an interface to libevent) |
201 | AnyEvent::Impl::Event based on Event, also best choice :) |
202 | AnyEvent::Impl::Event based on Event, also best choice :) |
202 | AnyEvent::Impl::Glib based on Glib, second-best choice. |
203 | AnyEvent::Impl::Glib based on Glib, second-best choice. |
203 | AnyEvent::Impl::Tk based on Tk, very bad choice. |
204 | AnyEvent::Impl::Tk based on Tk, very bad choice. |
204 | AnyEvent::Impl::Perl pure-perl implementation, inefficient. |
205 | AnyEvent::Impl::Perl pure-perl implementation, inefficient. |
205 | |
206 | |
… | |
… | |
245 | |
246 | |
246 | package AnyEvent; |
247 | package AnyEvent; |
247 | |
248 | |
248 | no warnings; |
249 | no warnings; |
249 | use strict; |
250 | use strict; |
|
|
251 | |
250 | use Carp; |
252 | use Carp; |
251 | |
253 | |
252 | our $VERSION = '2.5'; |
254 | our $VERSION = '2.55'; |
253 | our $MODEL; |
255 | our $MODEL; |
254 | |
256 | |
255 | our $AUTOLOAD; |
257 | our $AUTOLOAD; |
256 | our @ISA; |
258 | our @ISA; |
257 | |
259 | |
… | |
… | |
259 | |
261 | |
260 | our @REGISTRY; |
262 | our @REGISTRY; |
261 | |
263 | |
262 | my @models = ( |
264 | my @models = ( |
263 | [Coro::Event:: => AnyEvent::Impl::Coro::], |
265 | [Coro::Event:: => AnyEvent::Impl::Coro::], |
|
|
266 | [EV:: => EV::AnyEvent::], |
264 | [Event:: => AnyEvent::Impl::Event::], |
267 | [Event:: => AnyEvent::Impl::Event::], |
265 | [Glib:: => AnyEvent::Impl::Glib::], |
268 | [Glib:: => AnyEvent::Impl::Glib::], |
266 | [Tk:: => AnyEvent::Impl::Tk::], |
269 | [Tk:: => AnyEvent::Impl::Tk::], |
267 | [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::], |
270 | [AnyEvent::Impl::Perl:: => AnyEvent::Impl::Perl::], |
268 | ); |
271 | ); |
… | |
… | |
288 | unless ($MODEL) { |
291 | unless ($MODEL) { |
289 | # try to load a model |
292 | # try to load a model |
290 | |
293 | |
291 | for (@REGISTRY, @models) { |
294 | for (@REGISTRY, @models) { |
292 | my ($package, $model) = @$_; |
295 | my ($package, $model) = @$_; |
|
|
296 | if (eval "require $package" |
|
|
297 | and ${"$package\::VERSION"} > 0 |
293 | if (eval "require $model") { |
298 | and eval "require $model") { |
294 | $MODEL = $model; |
299 | $MODEL = $model; |
295 | warn "AnyEvent: autoprobed and loaded model '$model', using it.\n" if $verbose > 1; |
300 | warn "AnyEvent: autoprobed and loaded model '$model', using it.\n" if $verbose > 1; |
296 | last; |
301 | last; |
297 | } |
302 | } |
298 | } |
303 | } |
… | |
… | |
384 | or Carp::croak "required option 'pid' is missing"; |
389 | or Carp::croak "required option 'pid' is missing"; |
385 | |
390 | |
386 | $PID_CB{$pid}{$arg{cb}} = $arg{cb}; |
391 | $PID_CB{$pid}{$arg{cb}} = $arg{cb}; |
387 | |
392 | |
388 | unless ($WNOHANG) { |
393 | unless ($WNOHANG) { |
389 | $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_child_wait); |
|
|
390 | $WNOHANG = eval { require POSIX; &POSIX::WNOHANG } || 1; |
394 | $WNOHANG = eval { require POSIX; &POSIX::WNOHANG } || 1; |
391 | } |
395 | } |
392 | |
396 | |
|
|
397 | unless ($CHLD_W) { |
|
|
398 | $CHLD_W = AnyEvent->signal (signal => 'CHLD', cb => \&_child_wait); |
393 | # child could be a zombie already |
399 | # child could be a zombie already |
394 | $PID_IDLE ||= AnyEvent->timer (after => 0, cb => \&_child_wait); |
400 | $PID_IDLE ||= AnyEvent->timer (after => 0, cb => \&_child_wait); |
|
|
401 | } |
395 | |
402 | |
396 | bless [$pid, $arg{cb}], "AnyEvent::Base::Child" |
403 | bless [$pid, $arg{cb}], "AnyEvent::Base::Child" |
397 | } |
404 | } |
398 | |
405 | |
399 | sub AnyEvent::Base::Child::DESTROY { |
406 | sub AnyEvent::Base::Child::DESTROY { |
… | |
… | |
435 | I<rxvt-unicode> distribution. |
442 | I<rxvt-unicode> distribution. |
436 | |
443 | |
437 | I<rxvt-unicode> also cheats a bit by not providing blocking access to |
444 | I<rxvt-unicode> also cheats a bit by not providing blocking access to |
438 | condition variables: code blocking while waiting for a condition will |
445 | condition variables: code blocking while waiting for a condition will |
439 | C<die>. This still works with most modules/usages, and blocking calls must |
446 | C<die>. This still works with most modules/usages, and blocking calls must |
440 | not be in an interactive appliation, so it makes sense. |
447 | not be in an interactive application, so it makes sense. |
441 | |
448 | |
442 | =head1 ENVIRONMENT VARIABLES |
449 | =head1 ENVIRONMENT VARIABLES |
443 | |
450 | |
444 | The following environment variables are used by this module: |
451 | The following environment variables are used by this module: |
445 | |
452 | |