Line | |
---|
1 | #!./perl
|
---|
2 |
|
---|
3 | BEGIN {
|
---|
4 | unless(grep /blib/, @INC) {
|
---|
5 | chdir 't' if -d 't';
|
---|
6 | @INC = '../lib';
|
---|
7 | }
|
---|
8 | }
|
---|
9 |
|
---|
10 | use Config;
|
---|
11 |
|
---|
12 | BEGIN {
|
---|
13 | if(-d "lib" && -f "TEST") {
|
---|
14 | my $reason;
|
---|
15 | if (! $Config{'d_fork'}) {
|
---|
16 | $reason = 'no fork';
|
---|
17 | }
|
---|
18 | elsif ($Config{'extensions'} !~ /\bSocket\b/) {
|
---|
19 | $reason = 'Socket extension unavailable';
|
---|
20 | }
|
---|
21 | elsif ($Config{'extensions'} !~ /\bIO\b/) {
|
---|
22 | $reason = 'IO extension unavailable';
|
---|
23 | }
|
---|
24 | elsif ($^O eq 'os2') {
|
---|
25 | require IO::Socket;
|
---|
26 |
|
---|
27 | eval {IO::Socket::pack_sockaddr_un('/foo/bar') || 1}
|
---|
28 | or $@ !~ /not implemented/ or
|
---|
29 | $reason = 'compiled without TCP/IP stack v4';
|
---|
30 | } elsif ($^O =~ m/^(?:qnx|nto|vos)$/ ) {
|
---|
31 | $reason = 'Not implemented';
|
---|
32 | }
|
---|
33 | if ($reason) {
|
---|
34 | print "1..0 # Skip: $reason\n";
|
---|
35 | exit 0;
|
---|
36 | }
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | $PATH = "sock-$$";
|
---|
41 |
|
---|
42 | # Test if we can create the file within the tmp directory
|
---|
43 | if (-e $PATH or not open(TEST, ">$PATH") and $^O ne 'os2') {
|
---|
44 | print "1..0 # Skip: cannot open '$PATH' for write\n";
|
---|
45 | exit 0;
|
---|
46 | }
|
---|
47 | close(TEST);
|
---|
48 | unlink($PATH) or $^O eq 'os2' or die "Can't unlink $PATH: $!";
|
---|
49 |
|
---|
50 | # Start testing
|
---|
51 | $| = 1;
|
---|
52 | print "1..5\n";
|
---|
53 |
|
---|
54 | use IO::Socket;
|
---|
55 |
|
---|
56 | $listen = IO::Socket::UNIX->new(Local=>$PATH, Listen=>0) || die "$!";
|
---|
57 | print "ok 1\n";
|
---|
58 |
|
---|
59 | if($pid = fork()) {
|
---|
60 |
|
---|
61 | $sock = $listen->accept();
|
---|
62 |
|
---|
63 | if (defined $sock) {
|
---|
64 | print "ok 2\n";
|
---|
65 |
|
---|
66 | print $sock->getline();
|
---|
67 |
|
---|
68 | print $sock "ok 4\n";
|
---|
69 |
|
---|
70 | $sock->close;
|
---|
71 |
|
---|
72 | waitpid($pid,0);
|
---|
73 | unlink($PATH) || $^O eq 'os2' || warn "Can't unlink $PATH: $!";
|
---|
74 |
|
---|
75 | print "ok 5\n";
|
---|
76 | } else {
|
---|
77 | print "# accept() failed: $!\n";
|
---|
78 | for (2..5) {
|
---|
79 | print "not ok $_ # accept failed\n";
|
---|
80 | }
|
---|
81 | }
|
---|
82 | } elsif(defined $pid) {
|
---|
83 |
|
---|
84 | $sock = IO::Socket::UNIX->new(Peer => $PATH) or die "$!";
|
---|
85 |
|
---|
86 | print $sock "ok 3\n";
|
---|
87 |
|
---|
88 | print $sock->getline();
|
---|
89 |
|
---|
90 | $sock->close;
|
---|
91 |
|
---|
92 | exit;
|
---|
93 | } else {
|
---|
94 | die;
|
---|
95 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.