1 | =head1 NAME |
1 | =head1 NAME |
2 | |
2 | |
3 | AnyEvent - events independent of event loop implementation |
3 | AnyEvent - the DBI of event loop programming |
4 | |
4 | |
5 | EV, Event, Glib, Tk, Perl, Event::Lib, Irssi, IO::Async, Qt and POE are |
5 | EV, Event, Glib, Tk, Perl, Event::Lib, Irssi, rxvt-unicode, IO::Async, Qt |
6 | various supported event loops/environments. |
6 | and POE are various supported event loops/environments. |
7 | |
7 | |
8 | =head1 SYNOPSIS |
8 | =head1 SYNOPSIS |
9 | |
9 | |
10 | use AnyEvent; |
10 | use AnyEvent; |
11 | |
11 | |
… | |
… | |
1086 | |
1086 | |
1087 | BEGIN { AnyEvent::common_sense } |
1087 | BEGIN { AnyEvent::common_sense } |
1088 | |
1088 | |
1089 | use Carp (); |
1089 | use Carp (); |
1090 | |
1090 | |
1091 | our $VERSION = 4.86; |
1091 | our $VERSION = 4.881; |
1092 | our $MODEL; |
1092 | our $MODEL; |
1093 | |
1093 | |
1094 | our $AUTOLOAD; |
1094 | our $AUTOLOAD; |
1095 | our @ISA; |
1095 | our @ISA; |
1096 | |
1096 | |
… | |
… | |
1306 | $_->() for values %{ $SIG_CB{$_} || {} }; |
1306 | $_->() for values %{ $SIG_CB{$_} || {} }; |
1307 | } |
1307 | } |
1308 | } |
1308 | } |
1309 | } |
1309 | } |
1310 | |
1310 | |
1311 | # install a dumym wakeupw atcher to reduce signal catching latency |
1311 | # install a dummy wakeup watcher to reduce signal catching latency |
1312 | sub _sig_add() { |
1312 | sub _sig_add() { |
1313 | unless ($SIG_COUNT++) { |
1313 | unless ($SIG_COUNT++) { |
1314 | # try to align timer on a full-second boundary, if possible |
1314 | # try to align timer on a full-second boundary, if possible |
1315 | my $NOW = AnyEvent->now; |
1315 | my $NOW = AnyEvent->now; |
1316 | |
1316 | |
… | |
… | |
1331 | my (undef, %arg) = @_; |
1331 | my (undef, %arg) = @_; |
1332 | |
1332 | |
1333 | my $signal = uc $arg{signal} |
1333 | my $signal = uc $arg{signal} |
1334 | or Carp::croak "required option 'signal' is missing"; |
1334 | or Carp::croak "required option 'signal' is missing"; |
1335 | |
1335 | |
1336 | $SIG_CB{$signal}{$arg{cb}} = $arg{cb}; |
|
|
1337 | |
|
|
1338 | if ($HAVE_ASYNC_INTERRUPT) { |
1336 | if ($HAVE_ASYNC_INTERRUPT) { |
1339 | # async::interrupt |
1337 | # async::interrupt |
1340 | |
1338 | |
1341 | $SIG_ASY{$signal} ||= do { |
1339 | $signal = Async::Interrupt::sig2num ($signal); |
1342 | my $asy = new Async::Interrupt |
1340 | $SIG_CB{$signal}{$arg{cb}} = $arg{cb}; |
|
|
1341 | |
|
|
1342 | $SIG_ASY{$signal} ||= new Async::Interrupt |
1343 | cb => sub { undef $SIG_EV{$signal} }, |
1343 | cb => sub { undef $SIG_EV{$signal} }, |
1344 | signal => $signal, |
1344 | signal => $signal, |
1345 | pipe => [$SIGPIPE_R->filenos], |
1345 | pipe => [$SIGPIPE_R->filenos], |
1346 | ; |
|
|
1347 | $asy->pipe_autodrain (0); |
1346 | pipe_autodrain => 0, |
1348 | |
|
|
1349 | $asy |
|
|
1350 | }; |
1347 | ; |
1351 | |
1348 | |
1352 | } else { |
1349 | } else { |
1353 | # pure perl |
1350 | # pure perl |
|
|
1351 | |
|
|
1352 | # AE::Util has been loaded in signal |
|
|
1353 | $signal = AnyEvent::Util::sig2name ($signal); |
|
|
1354 | $SIG_CB{$signal}{$arg{cb}} = $arg{cb}; |
1354 | |
1355 | |
1355 | $SIG{$signal} ||= sub { |
1356 | $SIG{$signal} ||= sub { |
1356 | local $!; |
1357 | local $!; |
1357 | syswrite $SIGPIPE_W, "\x00", 1 unless %SIG_EV; |
1358 | syswrite $SIGPIPE_W, "\x00", 1 unless %SIG_EV; |
1358 | undef $SIG_EV{$signal}; |
1359 | undef $SIG_EV{$signal}; |
… | |
… | |
1366 | bless [$signal, $arg{cb}], "AnyEvent::Base::signal" |
1367 | bless [$signal, $arg{cb}], "AnyEvent::Base::signal" |
1367 | } |
1368 | } |
1368 | |
1369 | |
1369 | sub signal { |
1370 | sub signal { |
1370 | # probe for availability of Async::Interrupt |
1371 | # probe for availability of Async::Interrupt |
1371 | if (!$ENV{PERL_ANYEVENT_AVOID_ASYNC_INTERRUPT} && eval "use Async::Interrupt 0.6 (); 1") { |
1372 | if (!$ENV{PERL_ANYEVENT_AVOID_ASYNC_INTERRUPT} && eval "use Async::Interrupt 1.0 (); 1") { |
1372 | warn "AnyEvent: using Async::Interrupt for race-free signal handling.\n" if $VERBOSE >= 8; |
1373 | warn "AnyEvent: using Async::Interrupt for race-free signal handling.\n" if $VERBOSE >= 8; |
1373 | |
1374 | |
1374 | $HAVE_ASYNC_INTERRUPT = 1; |
1375 | $HAVE_ASYNC_INTERRUPT = 1; |
1375 | $SIGPIPE_R = new Async::Interrupt::EventPipe; |
1376 | $SIGPIPE_R = new Async::Interrupt::EventPipe; |
1376 | $SIG_IO = AnyEvent->io (fh => $SIGPIPE_R->fileno, poll => "r", cb => \&_signal_exec); |
1377 | $SIG_IO = AnyEvent->io (fh => $SIGPIPE_R->fileno, poll => "r", cb => \&_signal_exec); |