perl 5.002beta2 patch: toke.c
[p5sagit/p5-mst-13.2.git] / t / lib / socket.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib' if -d '../lib';
6     require Config; import Config;
7     if ($Config{'extensions'} !~ /\bSocket\b/ && $Config{'osname'} ne 'VMS') {
8         print "1..0\n";
9         exit 0;
10     }
11 }
12         
13 use Socket;
14
15 print "1..6\n";
16
17 if (socket(T,PF_INET,SOCK_STREAM,6)) {
18   print "ok 1\n";
19
20   if (connect(T,pack_sockaddr_in(7,inet_aton("localhost")))){
21         print "ok 2\n";
22
23         print "# Connected to ",
24                 inet_ntoa((unpack_sockaddr_in(getpeername(T)))[1]),"\n";
25
26         syswrite(T,"hello",5);
27         sysread(T,$buff,10);
28         print $buff eq "hello" ? "ok 3\n" : "not ok 3\n";
29   }
30   else {
31         print "# You're allowed to fail tests 2 and 3 if.\n";
32         print "# The echo service has been disabled.\n";
33         print "# $!\n";
34         print "ok 2\n";
35         print "ok 3\n";
36   }
37 }
38 else {
39         print "# $!\n";
40         print "not ok 1\n";
41 }
42
43 if( socket(S,PF_INET,SOCK_STREAM,6) ){
44   print "ok 4\n";
45
46   if (connect(S,pack_sockaddr_in(7,INADDR_LOOPBACK))){
47         print "ok 5\n";
48
49         print "# Connected to ",
50                 inet_ntoa((unpack_sockaddr_in(getpeername(S)))[1]),"\n";
51
52         syswrite(S,"olleh",5);
53         sysread(S,$buff,10);
54         print $buff eq "olleh" ? "ok 6\n" : "not ok 6\n";
55   }
56   else {
57         print "# You're allowed to fail tests 5 and 6 if.\n";
58         print "# The echo service has been disabled.\n";
59         print "# $!\n";
60         print "ok 5\n";
61         print "ok 6\n";
62   }
63 }
64 else {
65         print "# $!\n";
66         print "not ok 4\n";
67 }