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