applied patch, and undid change#1302 which it made unnecessary
[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     # This can fail if localhost is undefined or the
56     # special 'loopback' address 127.0.0.1 is not configured
57     # on your system. (/etc/rc.config.d/netconfig on HP-UX.)
58     # As a shortcut (not recommended) you could change 'localhost'
59     # here to be the name of this machine eg 'myhost.mycompany.com'.
60
61     $sock = IO::Socket::INET->new(PeerPort => $port,
62                                   Proto => 'tcp',
63                                   PeerAddr => 'localhost'
64                                  )
65             or die "$! (maybe your system does not have the 'localhost' address defined)";
66
67     $sock->autoflush(1);
68
69     print $sock "ok 3\n";
70
71     print $sock->getline();
72
73     $sock->close;
74
75     exit;
76 } else {
77  die;
78 }
79
80
81
82
83
84