view release on metacpan or search on metacpan
local/lib/perl5/IO/Async.pm view on Meta::CPAN
=head2 Loops
The L<IO::Async::Loop> object class represents an abstract collection of
L<IO::Async::Notifier> objects, and manages the actual filehandle IO
watchers, timers, signal handlers, and other functionality. It performs all
of the abstract collection management tasks, and leaves the actual OS
interactions to a particular subclass for the purpose.
L<IO::Async::Loop::Poll> uses an L<IO::Poll> object for this test.
L<IO::Async::Loop::Select> uses the C<select(2)> syscall.
Other subclasses of loop may appear on CPAN under their own dists; see the
L</SEE ALSO> section below for more detail.
As well as these general-purpose classes, the L<IO::Async::Loop> constructor
also supports looking for OS-specific subclasses, in case a more efficient
implementation exists for the specific OS it runs on.
=head2 Child Processes
local/lib/perl5/IO/Async/Loop.pm view on Meta::CPAN
=head2 later
$loop->later( $code )
Schedules a code reference to be invoked as soon as the current round of IO
operations is complete.
The code reference is never invoked immediately, though the loop will not
perform any blocking operations between when it is installed and when it is
invoked. It may call C<select>, C<poll> or equivalent with a zero-second
timeout, and process any currently-pending IO conditions before the code is
invoked, but it will not block for a non-zero amount of time.
This method is implemented using the C<watch_idle> method, with the C<when>
parameter set to C<later>. It will return an ID value that can be passed to
C<unwatch_idle> if required.
=cut
sub later
local/lib/perl5/IO/Async/Loop/Poll.pm view on Meta::CPAN
# finds nothing, keep -1
# Preserve $! whatever happens
local $!;
my $secondattempt = $poll->poll( 0 );
$pollret = $secondattempt if $secondattempt > 0;
}
}
else {
# Workaround - we'll use select to fake a millisecond-accurate sleep
$pollret = select( undef, undef, undef, $timeout );
}
return undef unless defined $pollret;
return $self->post_poll;
}
else {
my @pollmasks = %{ $self->{pollmask} };
# Perl 5.8.x's IO::Poll::_poll gets confused with no masks
my $pollret;
local/lib/perl5/IO/Async/Loop/Poll.pm view on Meta::CPAN
$pollret == 0 and $self->{sigproxy} ) {
local $!;
@pollmasks = %{ $self->{pollmask} };
my $secondattempt = IO::Poll::_poll( $msec, @pollmasks );
$pollret = $secondattempt if $secondattempt > 0;
}
}
else {
# Workaround - we'll use select to fake a millisecond-accurate sleep
$pollret = select( undef, undef, undef, $timeout );
}
return undef unless defined $pollret;
$self->{pollevents} = { @pollmasks };
return $self->post_poll;
}
}
sub watch_io
local/lib/perl5/IO/Async/Loop/Select.pm view on Meta::CPAN
our $VERSION = '0.70';
use constant API_VERSION => '0.49';
use base qw( IO::Async::Loop );
use IO::Async::OS;
use Carp;
# select() on most platforms claims that ISREG files are always read- and
# write-ready, but not on MSWin32. We need to fake this
use constant FAKE_ISREG_READY => IO::Async::OS->HAVE_FAKE_ISREG_READY;
# select() on most platforms indicates write-ready when connect() fails, but
# not on MSWin32. Have to pull from evec in that case
use constant SELECT_CONNECT_EVEC => IO::Async::OS->HAVE_SELECT_CONNECT_EVEC;
use constant _CAN_WATCHDOG => 1;
use constant WATCHDOG_ENABLE => IO::Async::Loop->WATCHDOG_ENABLE;
=head1 NAME
C<IO::Async::Loop::Select> - use L<IO::Async> with C<select(2)>
=head1 SYNOPSIS
Normally an instance of this class would not be directly constructed by a
program. It may however, be useful for runinng L<IO::Async> with an existing
program already using a C<select> call.
use IO::Async::Loop::Select;
my $loop = IO::Async::Loop::Select->new;
$loop->add( ... );
while(1) {
my ( $rvec, $wvec, $evec ) = ('') x 3;
my $timeout;
$loop->pre_select( \$rvec, \$wvec, \$evec, \$timeout );
...
my $ret = select( $rvec, $wvec, $evec, $timeout );
...
$loop->post_select( $rvec, $evec, $wvec );
}
=head1 DESCRIPTION
This subclass of L<IO::Async::Loop> uses the C<select(2)> syscall to perform
read-ready and write-ready tests.
To integrate with an existing C<select>-based event loop, a pair of methods
C<pre_select> and C<post_select> can be called immediately before and
after a C<select> call. The relevant bits in the read-ready, write-ready and
exceptional-state bitvectors are set by the C<pre_select> method, and tested
by the C<post_select> method to pick which event callbacks to invoke.
=cut
=head1 CONSTRUCTOR
=cut
=head2 new
$loop = IO::Async::Loop::Select->new
local/lib/perl5/IO/Async/Loop/Select.pm view on Meta::CPAN
$self->{avec} = ''; # Bitvector of handles always to claim are ready
return $self;
}
=head1 METHODS
=cut
=head2 pre_select
$loop->pre_select( \$readvec, \$writevec, \$exceptvec, \$timeout )
This method prepares the bitvectors for a C<select> call, setting the bits
that the Loop is interested in. It will also adjust the C<$timeout> value if
appropriate, reducing it if the next event timeout the Loop requires is sooner
than the current value.
=over 8
=item \$readvec
=item \$writevec
local/lib/perl5/IO/Async/Loop/Select.pm view on Meta::CPAN
Scalar references to the reading, writing and exception bitvectors
=item \$timeout
Scalar reference to the timeout value
=back
=cut
sub pre_select
{
my $self = shift;
my ( $readref, $writeref, $exceptref, $timeref ) = @_;
# BITWISE operations
$$readref |= $self->{rvec};
$$writeref |= $self->{wvec};
$$exceptref |= $self->{evec};
$self->_adjust_timeout( $timeref );
local/lib/perl5/IO/Async/Loop/Select.pm view on Meta::CPAN
# Round up to nearest millisecond
if( $$timeref ) {
my $mils = $$timeref * 1000;
my $fraction = $mils - int $mils;
$$timeref += ( 1 - $fraction ) / 1000 if $fraction;
}
return;
}
=head2 post_select
$loop->post_select( $readvec, $writevec, $exceptvec )
This method checks the returned bitvectors from a C<select> call, and calls
any of the callbacks that are appropriate.
=over 8
=item $readvec
=item $writevec
=item $exceptvec
Scalars containing the read-ready, write-ready and exception bitvectors
=back
=cut
sub post_select
{
my $self = shift;
my ( $readvec, $writevec, $exceptvec ) = @_;
my $iowatches = $self->{iowatches};
my $count = 0;
alarm( IO::Async::Loop->WATCHDOG_INTERVAL ) if WATCHDOG_ENABLE;
local/lib/perl5/IO/Async/Loop/Select.pm view on Meta::CPAN
$self->_manage_queues;
alarm( 0 ) if WATCHDOG_ENABLE;
}
=head2 loop_once
$count = $loop->loop_once( $timeout )
This method calls the C<pre_select> method to prepare the bitvectors for a
C<select> syscall, performs it, then calls C<post_select> to process the
result. It returns the total number of callbacks invoked by the
C<post_select> method, or C<undef> if the underlying C<select(2)> syscall
returned an error.
=cut
sub loop_once
{
my $self = shift;
my ( $timeout ) = @_;
my ( $rvec, $wvec, $evec ) = ('') x 3;
$self->pre_select( \$rvec, \$wvec, \$evec, \$timeout );
my $ret = select( $rvec, $wvec, $evec, $timeout );
if( $ret < 0 ) {
# r/w/e vec can't be trusted
$rvec = $wvec = $evec = '';
}
{
local $!;
$self->post_select( $rvec, $wvec, $evec );
}
return $ret;
}
sub watch_io
{
my $self = shift;
my %params = @_;
local/lib/perl5/IO/Async/Loop/Select.pm view on Meta::CPAN
# trailing null bytes
$_ =~s/\0+\z// for $self->{rvec}, $self->{wvec}, $self->{evec}, $self->{avec};
}
=head1 SEE ALSO
=over 4
=item *
L<IO::Select> - OO interface to select system call
=back
=head1 AUTHOR
Paul Evans <leonerd@leonerd.org.uk>
=cut
0x55AA;
local/lib/perl5/IO/Async/OS.pm view on Meta::CPAN
# Win32 [and maybe other places] don't have an _SC_OPEN_MAX. About the best we
# can do really is just make up some largeish number and hope for the best.
use constant OPEN_MAX_FD => eval { sysconf(_SC_OPEN_MAX) } || 1024;
# Some constants that define features of the OS
use constant HAVE_SOCKADDR_IN6 => defined eval { pack_sockaddr_in6 0, inet_pton( AF_INET6, "2001::1" ) };
use constant HAVE_SOCKADDR_UN => defined eval { pack_sockaddr_un "/foo" };
# Do we have to fake S_ISREG() files read/write-ready in select()?
use constant HAVE_FAKE_ISREG_READY => 0;
# Do we have to select() for for evec to get connect() failures
use constant HAVE_SELECT_CONNECT_EVEC => 0;
# Ditto; do we have to poll() for POLLPRI to get connect() failures
use constant HAVE_POLL_CONNECT_POLLPRI => 0;
# Does connect() yield EWOULDBLOCK for nonblocking in progress?
use constant HAVE_CONNECT_EWOULDBLOCK => 0;
# Can we rename() files that are open?
use constant HAVE_RENAME_OPEN_FILES => 1;
local/lib/perl5/IO/Async/OS/MSWin32.pm view on Meta::CPAN
our @ISA = qw( IO::Async::OS::_Base );
use Carp;
use Socket qw( AF_INET SOCK_STREAM SOCK_DGRAM INADDR_LOOPBACK pack_sockaddr_in );
use IO::Socket (); # empty import
use constant HAVE_FAKE_ISREG_READY => 1;
# Also select() only reports connect() failures by evec, not wvec
use constant HAVE_SELECT_CONNECT_EVEC => 1;
use constant HAVE_POLL_CONNECT_POLLPRI => 1;
use constant HAVE_CONNECT_EWOULDBLOCK => 1;
use constant HAVE_RENAME_OPEN_FILES => 0;
# poll(2) on Windows is emulated by wrapping select(2) anyway, so we might as
# well try the Select loop first
use constant LOOP_BUILTIN_CLASSES => qw( Select Poll );
# CORE::fork() does not provide full POSIX semantics
use constant HAVE_POSIX_FORK => 0;
# Windows does not have signals, and SIGCHLD is not available
use constant HAVE_SIGNALS => 0;
=head1 NAME
local/lib/perl5/IO/Async/OS/MSWin32.pm view on Meta::CPAN
C<IO::Async::OS::MSWin32> - operating system abstractions on C<MSWin32> for C<IO::Async>
=head1 DESCRIPTION
This module contains OS support code for C<MSWin32>.
See instead L<IO::Async::OS>.
=cut
# Win32's pipes don't actually work with select(). We'll have to create
# sockets instead
sub pipepair
{
shift->socketpair( 'inet', 'stream' );
}
# Win32 doesn't have a socketpair(). We'll fake one up
sub socketpair
{
my $self = shift;
local/lib/perl5/IO/Async/OS/cygwin.pm view on Meta::CPAN
use warnings;
our $VERSION = '0.70';
our @ISA = qw( IO::Async::OS::_Base );
# Cygwin almost needs no hinting above the POSIX-like base, except that its
# emulation of poll() isn't quite perfect. It needs POLLPRI
use constant HAVE_POLL_CONNECT_POLLPRI => 1;
# Also select() only reports connect() failures by evec, not wvec
use constant HAVE_SELECT_CONNECT_EVEC => 1;
=head1 NAME
C<IO::Async::OS::cygwin> - operating system abstractions on C<cygwin> for C<IO::Async>
=head1 DESCRIPTION
This module contains OS support code for C<cygwin>.
local/lib/perl5/Module/Build.pm view on Meta::CPAN
=back
Four other parameters let you control various aspects of how
installation paths are determined:
=over 4
=item installdirs
The default destinations for these installable things come from
entries in your system's C<Config.pm>. You can select from three
different sets of default locations by setting the C<installdirs>
parameter as follows:
'installdirs' set to:
core site vendor
uses the following defaults from Config.pm:
lib => installprivlib installsitelib installvendorlib
arch => installarchlib installsitearch installvendorarch
local/lib/perl5/Module/Build.pm view on Meta::CPAN
=item *
There are several architectural decisions in C<MakeMaker> that make it
very difficult to customize its behavior. For instance, when using
C<MakeMaker> you do C<use ExtUtils::MakeMaker>, but the object created in
C<WriteMakefile()> is actually blessed into a package name that's
created on the fly, so you can't simply subclass
C<ExtUtils::MakeMaker>. There is a workaround C<MY> package that lets
you override certain C<MakeMaker> methods, but only certain explicitly
preselected (by C<MakeMaker>) methods can be overridden. Also, the method
of customization is very crude: you have to modify a string containing
the Makefile text for the particular target. Since these strings
aren't documented, and I<can't> be documented (they take on different
values depending on the platform, version of perl, version of
C<MakeMaker>, etc.), you have no guarantee that your modifications will
work on someone else's machine or after an upgrade of C<MakeMaker> or
perl.
=item *
local/lib/perl5/Module/Build/Base.pm view on Meta::CPAN
}
sub args {
my $self = shift;
return wantarray ? %{ $self->{args} } : $self->{args} unless @_;
my $key = shift;
$self->{args}{$key} = shift if @_;
return $self->{args}{$key};
}
# allows select parameters (with underscores) to be spoken with dashes
# when used as command-line options
sub _translate_option {
my $self = shift;
my $opt = shift;
(my $tr_opt = $opt) =~ tr/-/_/;
return $tr_opt if grep $tr_opt =~ /^(?:no_?)?$_$/, qw(
create_license
create_makefile_pl
local/lib/perl5/Module/Build/Base.pm view on Meta::CPAN
install_path
meta_add
meta_merge
test_files
use_rcfile
use_tap_harness
tap_harness_args
cpan_client
pureperl_only
allow_pureperl
); # normalize only selected option names
return $opt;
}
my %singular_argument = map { ($_ => 1) } qw/install_base prefix destdir installdirs verbose quiet uninst debug sign/;
sub _read_arg {
my ($self, $args, $key, $val) = @_;
$key = $self->_translate_option($key);
local/lib/perl5/Module/Build/Base.pm view on Meta::CPAN
} else {
push( @{$alt{$package}}, {
file => $mapped_filename,
version => $version,
} );
}
}
}
# Then we iterate over all the packages found above, identifying conflicts
# and selecting the "best" candidate for recording the file & version
# for each package.
foreach my $package ( sort keys( %alt ) ) {
my $result = $self->_resolve_module_versions( $alt{$package} );
if ( exists( $prime{$package} ) ) { # primary package selected
if ( $result->{err} ) {
# Use the selected primary package, but there are conflicting
# errors among multiple alternative packages that need to be
# reported
$self->log_warn(
"Found conflicting versions for package '$package'\n" .
" $prime{$package}{file} ($prime{$package}{version})\n" .
$result->{err}
);
} elsif ( defined( $result->{version} ) ) {
# There is a primary package selected, and exactly one
# alternative package
if ( exists( $prime{$package}{version} ) &&
defined( $prime{$package}{version} ) ) {
# Unless the version of the primary package agrees with the
# version of the alternative package, report a conflict
if ( $self->compare_versions( $prime{$package}{version}, '!=',
$result->{version} ) ) {
$self->log_warn(
"Found conflicting versions for package '$package'\n" .
" $prime{$package}{file} ($prime{$package}{version})\n" .
" $result->{file} ($result->{version})\n"
);
}
} else {
# The prime package selected has no version so, we choose to
# use any alternative package that does have a version
$prime{$package}{file} = $result->{file};
$prime{$package}{version} = $result->{version};
}
} else {
# no alt package found with a version, but we have a prime
# package so we use it whether it has a version or not
}
} else { # No primary package was selected, use the best alternative
if ( $result->{err} ) {
$self->log_warn(
"Found conflicting versions for package '$package'\n" .
$result->{err}
);
}
# Despite possible conflicting versions, we choose to record
# something rather than nothing