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";
36 $SIG{ALRM} = sub { die; };
42 $listen = IO::Socket::INET->new(Listen => 2,
44 # some systems seem to need as much as 10,
45 # so be generous with the timeout
51 # Check if can fork with dynamic extensions (bug in CRT):
53 system "$^X -I../lib -MOpcode -e 'defined fork or die' > /dev/null 2>&1") {
54 print "ok $_ # skipped: broken fork\n" for 2..5;
58 $port = $listen->sockport;
62 $sock = $listen->accept() or die "accept failed: $!";
66 print $sock->getline();
76 } elsif(defined $pid) {
78 $sock = IO::Socket::INET->new(PeerPort => $port,
80 PeerAddr => 'localhost'
82 || IO::Socket::INET->new(PeerPort => $port,
84 PeerAddr => '127.0.0.1'
86 or die "$! (maybe your system does not have a localhost at all, 'localhost' or 127.0.0.1)";
92 print $sock->getline();
101 # Test various other ways to create INET sockets that should
103 $listen = IO::Socket::INET->new(Listen => '', Timeout => 15) or die "$!";
104 $port = $listen->sockport;
109 last SERVER_LOOP unless $sock = $listen->accept;
111 last SERVER_LOOP if /^quit/;
118 } elsif (defined $pid) {
119 # child, try various ways to connect
120 $sock = IO::Socket::INET->new("localhost:$port")
121 || IO::Socket::INET->new("127.0.0.1:$port");
123 print "not " unless $sock->connected;
125 $sock->print("ok 7\n");
128 $sock->print("ok 9\n");
129 $sock->print("done\n");
140 # some machines seem to suffer from a race condition here
143 $sock = IO::Socket::INET->new("127.0.0.1:$port");
145 $sock->print("ok 10\n");
146 $sock->print("done\n");
154 # some machines seem to suffer from a race condition here
157 $sock = IO::Socket->new(Domain => AF_INET,
158 PeerAddr => "localhost:$port")
159 || IO::Socket->new(Domain => AF_INET,
160 PeerAddr => "127.0.0.1:$port");
162 $sock->print("ok 11\n");
163 $sock->print("quit\n");
174 # Then test UDP sockets
175 $server = IO::Socket->new(Domain => AF_INET,
177 LocalAddr => 'localhost')
178 || IO::Socket->new(Domain => AF_INET,
180 LocalAddr => '127.0.0.1');
181 $port = $server->sockport;
183 if ($^O eq 'mpeix') {
184 print("ok 12 # skipped\n")
188 $server->recv($buf, 100);
190 } elsif (defined($pid)) {
192 $sock = IO::Socket::INET->new(Proto => 'udp',
193 PeerAddr => "localhost:$port")
194 || IO::Socket::INET->new(Proto => 'udp',
195 PeerAddr => "127.0.0.1:$port");
196 $sock->send("ok 12\n");
198 $sock->send("ok 12\n"); # send another one to be sure
205 print "not " unless $server->blocking;
208 $server->blocking(0);
209 print "not " if $server->blocking;
213 ### Set up some data to be transfered between the server and
214 ### the client. We'll use own source code ...
217 if( !open( SRC, "< $0")) {
218 print "not ok 15 - $!";
228 my $listen = IO::Socket::INET->new( Listen => 2, Proto => 'tcp', Timeout => 15) ||
231 die if( !defined( $listen));
232 my $serverport = $listen->sockport;
234 my $server_pid = fork();
237 ### TEST 17 Client/Server establishment
242 ### Get data from the server using a single stream
244 $sock = IO::Socket::INET->new("localhost:$serverport")
245 || IO::Socket::INET->new("127.0.0.1:$serverport");
248 $sock->print("send\n");
255 $sock->print("done\n");
258 print "not " if( @array != @data);
265 ### Get data from the server using a stream, which is
266 ### interrupted by eof calls.
267 ### On perl-5.7.0@7673 this failed in a SOCKS environment, because eof
268 ### did an getc followed by an ungetc in order to check for the streams
269 ### end. getc(3) got replaced by the SOCKS funktion, which ended up in
270 ### a recv(2) call on the socket, while ungetc(3) put back a character
271 ### to an IO buffer, which never again was read.
273 $sock = IO::Socket::INET->new("localhost:$serverport")
274 || IO::Socket::INET->new("127.0.0.1:$serverport");
277 $sock->print("send\n");
280 while( !eof( $sock ) ){
287 $sock->print("done\n");
290 print "not " if( @array != @data);
299 $sock = IO::Socket::INET->new("localhost:$serverport")
300 || IO::Socket::INET->new("127.0.0.1:$serverport");
303 $sock->print("done\n");
306 print "not " if( 1 != kill 0, $server_pid);
312 } elsif( defined( $server_pid)) {
316 SERVER_LOOP: while (1) {
317 last SERVER_LOOP unless $sock = $listen->accept;
319 last SERVER_LOOP if /^quit/;