4 unless(grep /blib/, @INC) {
6 unshift @INC, '../lib' if -d '../lib';
13 if (-d "lib" && -f "TEST") {
14 if (!$Config{'d_fork'} ||
15 (($Config{'extensions'} !~ /\bSocket\b/ ||
16 $Config{'extensions'} !~ /\bIO\b/) &&
17 !(($^O eq 'VMS') && $Config{d_socket}))) {
29 $listen = IO::Socket::INET->new(Listen => 2,
31 # some systems seem to need as much as 10,
32 # so be generous with the timeout
38 # Check if can fork with dynamic extensions (bug in CRT):
40 system "$^X -I../lib -MOpcode -e 'defined fork or die' > /dev/null 2>&1") {
41 print "ok $_ # skipped: broken fork\n" for 2..5;
45 $port = $listen->sockport;
49 $sock = $listen->accept() or die "accept failed: $!";
53 print $sock->getline();
63 } elsif(defined $pid) {
65 # This can fail if localhost is undefined or the
66 # special 'loopback' address 127.0.0.1 is not configured
67 # on your system. (/etc/rc.config.d/netconfig on HP-UX.)
68 # As a shortcut (not recommended) you could change 'localhost'
69 # here to be the name of this machine eg 'myhost.mycompany.com'.
71 $sock = IO::Socket::INET->new(PeerPort => $port,
73 PeerAddr => 'localhost'
75 or die "$! (maybe your system does not have the 'localhost' address defined)";
81 print $sock->getline();
90 # Test various other ways to create INET sockets that should
92 $listen = IO::Socket::INET->new(Listen => '', Timeout => 15) or die "$!";
93 $port = $listen->sockport;
98 last SERVER_LOOP unless $sock = $listen->accept;
100 last SERVER_LOOP if /^quit/;
107 } elsif (defined $pid) {
108 # child, try various ways to connect
109 $sock = IO::Socket::INET->new("localhost:$port");
111 print "not " unless $sock->connected;
113 $sock->print("ok 7\n");
116 $sock->print("ok 9\n");
117 $sock->print("done\n");
128 # some machines seem to suffer from a race condition here
131 $sock = IO::Socket::INET->new("127.0.0.1:$port");
133 $sock->print("ok 10\n");
134 $sock->print("done\n");
142 # some machines seem to suffer from a race condition here
145 $sock = IO::Socket->new(Domain => AF_INET,
146 PeerAddr => "localhost:$port");
148 $sock->print("ok 11\n");
149 $sock->print("quit\n");
158 # Then test UDP sockets
159 $server = IO::Socket->new(Domain => AF_INET,
161 LocalAddr => 'localhost');
162 $port = $server->sockport;
166 $server->recv($buf, 100);
168 } elsif (defined($pid)) {
170 $sock = IO::Socket::INET->new(Proto => 'udp',
171 PeerAddr => "localhost:$port");
172 $sock->send("ok 12\n");
174 $sock->send("ok 12\n"); # send another one to be sure
180 print "not " unless $server->blocking;
183 $server->blocking(0);
184 print "not " if $server->blocking;