Fix label on C<for(;;)> statement
[p5sagit/p5-mst-13.2.git] / t / lib / io_sock.t
1 #!./perl
2
3 BEGIN {
4     unless(grep /blib/, @INC) {
5         chdir 't' if -d 't';
6         @INC = '../lib' if -d '../lib';
7     }
8 }
9
10 use Config;
11
12 BEGIN {
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}))) {
18             print "1..0\n";
19             exit 0;
20         }
21     }
22 }
23
24 $| = 1;
25 print "1..5\n";
26
27 use IO::Socket;
28
29 $listen = IO::Socket::INET->new(Listen => 2,
30                                 Proto => 'tcp',
31                                ) or die "$!";
32
33 print "ok 1\n";
34
35 $port = $listen->sockport;
36
37 if($pid = fork()) {
38
39     $sock = $listen->accept();
40     print "ok 2\n";
41
42     $sock->autoflush(1);
43     print $sock->getline();
44
45     print $sock "ok 4\n";
46
47     $sock->close;
48
49     waitpid($pid,0);
50
51     print "ok 5\n";
52
53 } elsif(defined $pid) {
54
55     $sock = IO::Socket::INET->new(PeerPort => $port,
56                                   Proto => 'tcp',
57                                   PeerAddr => 'localhost'
58                                  ) or die "$!";
59
60     $sock->autoflush(1);
61
62     print $sock "ok 3\n";
63
64     print $sock->getline();
65
66     $sock->close;
67
68     exit;
69 } else {
70  die;
71 }
72
73
74
75
76
77