Acme-Sort-Sleep
view release on metacpan or search on metacpan
local/lib/perl5/IO/Async/Handle.pm view on Meta::CPAN
$handle = $handle->bind( $ai )->get
When invoked with a single argument, this method is a convenient shortcut to
creating a socket handle and C<bind()>ing it to the address as given by an
addrinfo structure, and setting it as the read and write handle for the
object.
C<$ai> may be either a C<HASH> or C<ARRAY> reference of the same form as given
to L<IO::Async::OS>'s C<extract_addrinfo> method.
The returned future returns the handle object itself for convenience.
=cut
sub bind
{
my $self = shift;
if( @_ == 1 ) {
my ( $ai ) = @_;
$self->socket( $ai );
my $addr = ( IO::Async::OS->extract_addrinfo( $ai ) )[3];
$self->read_handle->bind( $addr ) or
return Future->fail( "Cannot bind - $!", bind => $self->read_handle, $addr, $! );
return Future->done( $self );
}
$self->loop->resolver->getaddrinfo( passive => 1, @_ )->then( sub {
my @addrs = @_;
try_repeat {
my $ai = shift;
$self->bind( $ai );
} foreach => \@addrs,
until => sub { shift->is_done };
});
}
=head2 connect
$handle = $handle->connect( %args )->get
A convenient wrapper for calling the C<connect> method on the underlying
L<IO::Async::Loop> object.
=cut
sub connect
{
my $self = shift;
my %args = @_;
my $loop = $self->loop or croak "Cannot ->connect a Handle that is not in a Loop";
$self->debug_printf( "CONNECT " . join( ", ",
# These args should be stringy
( map { defined $args{$_} ? "$_=$args{$_}" : () } qw( host service family socktype protocol local_host local_service ) )
) );
return $self->loop->connect( %args, handle => $self );
}
=head1 SEE ALSO
=over 4
=item *
L<IO::Handle> - Supply object methods for I/O handles
=back
=head1 AUTHOR
Paul Evans <leonerd@leonerd.org.uk>
=cut
0x55AA;
( run in 2.023 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )