Acme-Sort-Sleep
view release on metacpan or search on metacpan
local/lib/perl5/IO/Async/OS.pm view on Meta::CPAN
Used to implement the C<watch_signal> / C<unwatch_signal> Loop pair.
=cut
sub loop_watch_signal
{
my $self = shift;
my ( $loop, $signal, $code ) = @_;
exists $SIG{$signal} or croak "Unrecognised signal name $signal";
ref $code or croak 'Expected $code as a reference';
my $signum = $self->signame2num( $signal );
my $sigwatch = $loop->{os}{sigwatch} ||= {}; # {$num} = $code
my $sigpipe;
unless( $sigpipe = $loop->{os}{sigpipe} ) {
require IO::Async::Handle;
( my $reader, $sigpipe ) = $self->pipepair or croak "Cannot pipe() - $!";
$_->blocking( 0 ) for $reader, $sigpipe;
$loop->{os}{sigpipe} = $sigpipe;
$loop->add( $loop->{os}{sigpipe_reader} = IO::Async::Handle->new(
notifier_name => "sigpipe",
read_handle => $reader,
on_read_ready => sub {
sysread $reader, my $buffer, 8192 or return;
foreach my $signum ( unpack "I*", $buffer ) {
$sigwatch->{$signum}->() if $sigwatch->{$signum};
}
},
) );
}
my $signum_str = pack "I", $signum;
$SIG{$signal} = sub { syswrite $sigpipe, $signum_str };
$sigwatch->{$signum} = $code;
}
sub loop_unwatch_signal
{
my $self = shift;
my ( $loop, $signal ) = @_;
my $signum = $self->signame2num( $signal );
my $sigwatch = $loop->{os}{sigwatch} or return;
delete $sigwatch->{$signum};
undef $SIG{$signal};
}
=head2 potentially_open_fds
@fds = IO::Async::OS->potentially_open_fds
Returns a list of filedescriptors which might need closing. By default this
will return C<0 .. _SC_OPEN_MAX>. OS-specific subclasses may have a better
guess.
=cut
sub potentially_open_fds
{
return 0 .. OPEN_MAX_FD;
}
=head1 AUTHOR
Paul Evans <leonerd@leonerd.org.uk>
=cut
0x55AA;
( run in 1.451 second using v1.01-cache-2.11-cpan-e1769b4cff6 )