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 $sock = IO::Socket::INET->new(PeerPort => $port,
75 PeerAddr => 'localhost'
77 || IO::Socket::INET->new(PeerPort => $port,
79 PeerAddr => '127.0.0.1'
81 or die "$! (maybe your system does not have a localhost at all, 'localhost' or 127.0.0.1)";
87 print $sock->getline();
96 # Test various other ways to create INET sockets that should
98 $listen = IO::Socket::INET->new(Listen => '', Timeout => 15) or die "$!";
99 $port = $listen->sockport;
104 last SERVER_LOOP unless $sock = $listen->accept;
106 last SERVER_LOOP if /^quit/;
113 } elsif (defined $pid) {
114 # child, try various ways to connect
115 $sock = IO::Socket::INET->new("localhost:$port")
116 || IO::Socket::INET->new("127.0.0.1:$port");
118 print "not " unless $sock->connected;
120 $sock->print("ok 7\n");
123 $sock->print("ok 9\n");
124 $sock->print("done\n");
135 # some machines seem to suffer from a race condition here
138 $sock = IO::Socket::INET->new("127.0.0.1:$port");
140 $sock->print("ok 10\n");
141 $sock->print("done\n");
149 # some machines seem to suffer from a race condition here
152 $sock = IO::Socket->new(Domain => AF_INET,
153 PeerAddr => "localhost:$port")
154 || IO::Socket->new(Domain => AF_INET,
155 PeerAddr => "127.0.0.1:$port");
157 $sock->print("ok 11\n");
158 $sock->print("quit\n");
169 # Then test UDP sockets
170 $server = IO::Socket->new(Domain => AF_INET,
172 LocalAddr => 'localhost')
173 || IO::Socket->new(Domain => AF_INET,
175 LocalAddr => '127.0.0.1');
176 $port = $server->sockport;
178 if ($^O eq 'mpeix') {
179 print("ok 12 # skipped\n")
183 $server->recv($buf, 100);
185 } elsif (defined($pid)) {
187 $sock = IO::Socket::INET->new(Proto => 'udp',
188 PeerAddr => "localhost:$port")
189 || IO::Socket::INET->new(Proto => 'udp',
190 PeerAddr => "127.0.0.1:$port");
191 $sock->send("ok 12\n");
193 $sock->send("ok 12\n"); # send another one to be sure
200 print "not " unless $server->blocking;
203 $server->blocking(0);
204 print "not " if $server->blocking;
208 ### Set up some data to be transfered between the server and
209 ### the client. We'll use own source code ...
212 if( !open( SRC, "< $0")) {
213 print "not ok 15 - $!";
223 my $listen = IO::Socket::INET->new( Listen => 2, Proto => 'tcp', Timeout => 15) ||
226 die if( !defined( $listen));
227 my $serverport = $listen->sockport;
229 my $server_pid = fork();
232 ### TEST 17 Client/Server establishment
237 ### Get data from the server using a single stream
239 $sock = IO::Socket::INET->new("localhost:$serverport")
240 || IO::Socket::INET->new("127.0.0.1:$serverport");
243 $sock->print("send\n");
250 $sock->print("done\n");
253 print "not " if( @array != @data);
260 ### Get data from the server using a stream, which is
261 ### interrupted by eof calls.
262 ### On perl-5.7.0@7673 this failed in a SOCKS environment, because eof
263 ### did an getc followed by an ungetc in order to check for the streams
264 ### end. getc(3) got replaced by the SOCKS funktion, which ended up in
265 ### a recv(2) call on the socket, while ungetc(3) put back a character
266 ### to an IO buffer, which never again was read.
268 $sock = IO::Socket::INET->new("localhost:$serverport")
269 || IO::Socket::INET->new("127.0.0.1:$serverport");
272 $sock->print("send\n");
275 while( !eof( $sock ) ){
282 $sock->print("done\n");
285 print "not " if( @array != @data);
294 $sock = IO::Socket::INET->new("localhost:$serverport")
295 || IO::Socket::INET->new("127.0.0.1:$serverport");
298 $sock->print("done\n");
301 print "not " if( 1 != kill 0, $server_pid);
307 } elsif( defined( $server_pid)) {
311 SERVER_LOOP: while (1) {
312 last SERVER_LOOP unless $sock = $listen->accept;
314 last SERVER_LOOP if /^quit/;