File: host6.t

package info (click to toggle)
libio-socket-inet6-perl 2.72-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 184 kB
  • ctags: 25
  • sloc: perl: 994; makefile: 5
file content (77 lines) | stat: -rw-r--r-- 1,499 bytes parent folder | download | duplicates (4)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/perl

use strict;
use warnings;

use Config;

BEGIN {
    if (-d "lib" && -f "TEST") {
	my $reason;
	if (! $Config{'d_fork'}) {
	    $reason = 'no fork';
	}
	elsif ($Config{'extensions'} !~ /\bSocket\b/) {
	    $reason = 'Socket extension unavailable';
	}
	elsif ($Config{'extensions'} !~ /\bIO\b/) {
	    $reason = 'IO extension unavailable';
	}
	if ($reason) {
	    print "1..0 # Skip: $reason\n";
	    exit 0;
        }
    }
    if ($^O eq 'MSWin32') {
        print "1..0 # Skip: accept() fails for IPv6 under MSWin32\n";
        exit 0;
    }
}

use Test::More;

use IO::Socket::INET6;

my $listen = IO::Socket::INET6->new(Listen => 2,
				Proto => 'tcp',
				# some systems seem to need as much as 10,
				# so be generous with the timeout
				Timeout => 15,
			       ) or die "$@";

# TEST
my $sockhost = $listen->sockhost();


my $port = $listen->sockport;

if(my $pid = fork()) {
    my $sock = $listen->accept();
    my $line = <$sock>;
    $listen->close;
    exit;
} elsif (defined $pid) {

    plan tests => 4;
    # child, try various ways to connect
    my $sock = IO::Socket::INET6->new("[::1]:$port");

    # TEST
    ok ($sockhost, "Checking for sockhost() success");

    # TEST
    ok ($sock->peerhost(), "Checking for peerhost() success");

    # TEST
    is ($sock->sockflow(), 0, "Checking for sockflow() success");

    # TEST
    is ($sock->peerflow(), 0, "Checking for peerflow() success");

    print {$sock} "H\n";
    undef($sock);
} else {
    die $!;
}