undo change#1379 (order of tests *is* significant)
[p5sagit/p5-mst-13.2.git] / t / lib / io_sock.t
CommitLineData
61f2b451 1#!./perl
2
3BEGIN {
7a4c00b4 4 unless(grep /blib/, @INC) {
5 chdir 't' if -d 't';
6 @INC = '../lib' if -d '../lib';
7 }
8}
9
10use Config;
11
12BEGIN {
774d564b 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}))) {
7a4c00b4 18 print "1..0\n";
19 exit 0;
20 }
61f2b451 21 }
22}
23
24$| = 1;
25print "1..5\n";
26
27use IO::Socket;
28
7a4c00b4 29$listen = IO::Socket::INET->new(Listen => 2,
30 Proto => 'tcp',
31 ) or die "$!";
61f2b451 32
7a4c00b4 33print "ok 1\n";
61f2b451 34
7a4c00b4 35$port = $listen->sockport;
61f2b451 36
7a4c00b4 37if($pid = fork()) {
61f2b451 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";
61f2b451 52
7a4c00b4 53} elsif(defined $pid) {
61f2b451 54
68820cec 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.)
9b599b2a 58 # As a shortcut (not recommended) you could change 'localhost'
59 # here to be the name of this machine eg 'myhost.mycompany.com'.
68820cec 60
61f2b451 61 $sock = IO::Socket::INET->new(PeerPort => $port,
62 Proto => 'tcp',
63 PeerAddr => 'localhost'
9b599b2a 64 )
65 or die "$! (maybe your system does not have the 'localhost' address defined)";
61f2b451 66
67 $sock->autoflush(1);
7a4c00b4 68
61f2b451 69 print $sock "ok 3\n";
7a4c00b4 70
61f2b451 71 print $sock->getline();
7a4c00b4 72
61f2b451 73 $sock->close;
7a4c00b4 74
61f2b451 75 exit;
76} else {
77 die;
78}
79
80
81
82
83
84