1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#!/usr/bin/perl -w
use strict;
use Test::More tests => 8;
use IO::Socket::IP;
use IO::Socket::INET;
use Errno qw( EINPROGRESS EWOULDBLOCK );
my $testserver = IO::Socket::INET->new(
Listen => 1,
LocalHost => "127.0.0.1",
Type => SOCK_STREAM,
) or die "Cannot listen on PF_INET - $@";
my $socket = IO::Socket::IP->new(
PeerHost => "127.0.0.1",
PeerService => $testserver->sockport,
Type => SOCK_STREAM,
Blocking => 0,
);
ok( defined $socket, 'IO::Socket::IP->new( Blocking => 0 ) constructs a socket' ) or
diag( " error was $@" );
while( !$socket->connect and ( $! == EINPROGRESS || $! == EWOULDBLOCK ) ) {
my $wvec = '';
vec( $wvec, fileno $socket, 1 ) = 1;
my $evec = '';
vec( $evec, fileno $socket, 1 ) = 1;
select( undef, $wvec, $evec, undef ) or die "Cannot select() - $!";
}
ok( !$!, 'Repeated ->connect eventually succeeds' );
is( $socket->sockdomain, AF_INET, '$socket->sockdomain' );
is( $socket->socktype, SOCK_STREAM, '$socket->socktype' );
is_deeply( [ unpack_sockaddr_in $socket->peername ],
[ unpack_sockaddr_in $testserver->sockname ],
'$socket->peername' );
is( $socket->peerhost, "127.0.0.1", '$socket->peerhost' );
is( $socket->peerport, $testserver->sockport, '$socket->peerport' );
ok( !$socket->blocking, '$socket->blocking' );
|