… | |
… | |
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 |
|
|
1338 | |
|
|
1339 | $signal = Async::Interrupt::sig2num ($signal); |
|
|
1340 | $SIG_CB{$signal}{$arg{cb}} = $arg{cb}; |
1340 | |
1341 | |
1341 | $SIG_ASY{$signal} ||= do { |
1342 | $SIG_ASY{$signal} ||= do { |
1342 | my $asy = new Async::Interrupt |
1343 | my $asy = new Async::Interrupt |
1343 | cb => sub { undef $SIG_EV{$signal} }, |
1344 | cb => sub { undef $SIG_EV{$signal} }, |
1344 | signal => $signal, |
1345 | signal => $signal, |
… | |
… | |
1350 | }; |
1351 | }; |
1351 | |
1352 | |
1352 | } else { |
1353 | } else { |
1353 | # pure perl |
1354 | # pure perl |
1354 | |
1355 | |
|
|
1356 | # AE::Util has been loaded in signal |
|
|
1357 | $signal = AnyEvent::Util::sig2name ($signal); |
|
|
1358 | $SIG_CB{$signal}{$arg{cb}} = $arg{cb}; |
|
|
1359 | |
1355 | $SIG{$signal} ||= sub { |
1360 | $SIG{$signal} ||= sub { |
1356 | local $!; |
1361 | local $!; |
1357 | syswrite $SIGPIPE_W, "\x00", 1 unless %SIG_EV; |
1362 | syswrite $SIGPIPE_W, "\x00", 1 unless %SIG_EV; |
1358 | undef $SIG_EV{$signal}; |
1363 | undef $SIG_EV{$signal}; |
1359 | }; |
1364 | }; |
… | |
… | |
1366 | bless [$signal, $arg{cb}], "AnyEvent::Base::signal" |
1371 | bless [$signal, $arg{cb}], "AnyEvent::Base::signal" |
1367 | } |
1372 | } |
1368 | |
1373 | |
1369 | sub signal { |
1374 | sub signal { |
1370 | # probe for availability of Async::Interrupt |
1375 | # probe for availability of Async::Interrupt |
1371 | if (!$ENV{PERL_ANYEVENT_AVOID_ASYNC_INTERRUPT} && eval "use Async::Interrupt 0.6 (); 1") { |
1376 | 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; |
1377 | warn "AnyEvent: using Async::Interrupt for race-free signal handling.\n" if $VERBOSE >= 8; |
1373 | |
1378 | |
1374 | $HAVE_ASYNC_INTERRUPT = 1; |
1379 | $HAVE_ASYNC_INTERRUPT = 1; |
1375 | $SIGPIPE_R = new Async::Interrupt::EventPipe; |
1380 | $SIGPIPE_R = new Async::Interrupt::EventPipe; |
1376 | $SIG_IO = AnyEvent->io (fh => $SIGPIPE_R->fileno, poll => "r", cb => \&_signal_exec); |
1381 | $SIG_IO = AnyEvent->io (fh => $SIGPIPE_R->fileno, poll => "r", cb => \&_signal_exec); |