4 unless(grep /blib/, @INC) {
13 if (-d "lib" && -f "TEST") {
15 if (! $Config{'d_fork'}) {
18 elsif ($Config{'extensions'} !~ /\bSocket\b/) {
19 $reason = 'Socket extension unavailable';
21 elsif ($Config{'extensions'} !~ /\bIO\b/) {
22 $reason = 'IO extension unavailable';
24 undef $reason if $^O eq 'VMS' and $Config{d_socket};
26 print "1..0 # Skip: $reason\n";
37 $listen = IO::Socket::INET->new(Listen => 2,
39 # some systems seem to need as much as 10,
40 # so be generous with the timeout
46 # Check if can fork with dynamic extensions (bug in CRT):
48 system "$^X -I../lib -MOpcode -e 'defined fork or die' > /dev/null 2>&1") {
49 print "ok $_ # skipped: broken fork\n" for 2..5;
53 $port = $listen->sockport;
57 $sock = $listen->accept() or die "accept failed: $!";
61 print $sock->getline();
71 } elsif(defined $pid) {
73 # This can fail if localhost is undefined or the
74 # special 'loopback' address 127.0.0.1 is not configured
75 # on your system. (/etc/rc.config.d/netconfig on HP-UX.)
76 # As a shortcut (not recommended) you could change 'localhost'
77 # here to be the name of this machine eg 'myhost.mycompany.com'.
79 $sock = IO::Socket::INET->new(PeerPort => $port,
81 PeerAddr => 'localhost'
83 or die "$! (maybe your system does not have the 'localhost' address defined)";
89 print $sock->getline();
98 # Test various other ways to create INET sockets that should
100 $listen = IO::Socket::INET->new(Listen => '', Timeout => 15) or die "$!";
101 $port = $listen->sockport;
106 last SERVER_LOOP unless $sock = $listen->accept;
108 last SERVER_LOOP if /^quit/;
115 } elsif (defined $pid) {
116 # child, try various ways to connect
117 $sock = IO::Socket::INET->new("localhost:$port");
119 print "not " unless $sock->connected;
121 $sock->print("ok 7\n");
124 $sock->print("ok 9\n");
125 $sock->print("done\n");
136 # some machines seem to suffer from a race condition here
139 $sock = IO::Socket::INET->new("127.0.0.1:$port");
141 $sock->print("ok 10\n");
142 $sock->print("done\n");
150 # some machines seem to suffer from a race condition here
153 $sock = IO::Socket->new(Domain => AF_INET,
154 PeerAddr => "localhost:$port");
156 $sock->print("ok 11\n");
157 $sock->print("quit\n");
166 # Then test UDP sockets
167 $server = IO::Socket->new(Domain => AF_INET,
169 LocalAddr => 'localhost');
170 $port = $server->sockport;
172 if ($^O eq 'mpeix') {
173 print("ok 12 # skipped\n")
177 $server->recv($buf, 100);
179 } elsif (defined($pid)) {
181 $sock = IO::Socket::INET->new(Proto => 'udp',
182 PeerAddr => "localhost:$port");
183 $sock->send("ok 12\n");
185 $sock->send("ok 12\n"); # send another one to be sure
192 print "not " unless $server->blocking;
195 $server->blocking(0);
196 print "not " if $server->blocking;