This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
reorder 'struct block' fields.
[perl5.git] / cpan / IO-Socket-IP / t / 06local-cross-v6.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8 use IO::Socket::IP;
9
10 eval { IO::Socket::IP->new( LocalHost => "::1" ) } or
11    plan skip_all => "Unable to bind to ::1";
12
13 foreach my $socktype (qw( SOCK_STREAM SOCK_DGRAM )) {
14    my $testserver = IO::Socket::IP->new(
15       ( $socktype eq "SOCK_STREAM" ? ( Listen => 1 ) : () ),
16       LocalHost => "::1",
17       LocalPort => "0",
18       Type      => Socket->$socktype,
19    ) or die "Cannot listen on PF_INET6 - $@";
20
21    my $socket = IO::Socket::IP->new(
22       PeerHost    => "::1",
23       PeerService => $testserver->sockport,
24       Type        => Socket->$socktype,
25    ) or die "Cannot connect on PF_INET6 - $@";
26
27    my $testclient = ( $socktype eq "SOCK_STREAM" ) ? 
28       $testserver->accept : 
29       do { $testserver->connect( $socket->sockname ); $testserver };
30
31    is( $testclient->sockport, $socket->peerport, "\$testclient->sockport for $socktype" );
32    is( $testclient->peerport, $socket->sockport, "\$testclient->peerport for $socktype" );
33
34    is( $testclient->sockhost, $socket->peerhost, "\$testclient->sockhost for $socktype" );
35    is( $testclient->peerhost, $socket->sockhost, "\$testclient->peerhost for $socktype" );
36
37    $socket->write( "Request\n" );
38    is( $testclient->getline, "Request\n", "\$socket to \$testclient for $socktype" );
39
40    SKIP: {
41       skip "local DGRAM response fails on windows", 1 if $socktype eq 'SOCK_DGRAM' and $^O =~ /MSWin32|cygwin|msys/;
42
43       $testclient->write( "Response\n" );
44       is( $socket->getline, "Response\n", "\$testclient to \$socket for $socktype" );
45    }
46 }
47
48 done_testing;