Fix-n-skip the tests under 5005threads.
[p5sagit/p5-mst-13.2.git] / t / lib / io_udp.t
CommitLineData
61f2b451 1#!./perl
2
3BEGIN {
7a4c00b4 4 unless(grep /blib/, @INC) {
5 chdir 't' if -d 't';
93430cb4 6 unshift @INC, '../lib' if -d '../lib';
7a4c00b4 7 }
8}
9
10use Config;
11
12BEGIN {
13 if(-d "lib" && -f "TEST") {
45c0de28 14 my $reason;
15
16 if ($Config{'extensions'} !~ /\bSocket\b/) {
17 $reason = 'Socket was not built';
18 }
19 elsif ($Config{'extensions'} !~ /\bIO\b/) {
20 $reason = 'IO was not built';
21 }
45c0de28 22 elsif ($^O eq 'apollo') {
23 $reason = "unknown *FIXME*";
24 }
25 undef $reason if $^O eq 'VMS' and $Config{d_socket};
26 if ($reason) {
27 print "1..0 # Skip: $reason\n";
7a4c00b4 28 exit 0;
45c0de28 29 }
61f2b451 30 }
31}
32
cf7fe8a2 33sub compare_addr {
adac82c7 34 no utf8;
cf7fe8a2 35 my $a = shift;
36 my $b = shift;
abf95952 37 if (length($a) != length $b) {
38 my $min = (length($a) < length $b) ? length($a) : length $b;
39 if ($min and substr($a, 0, $min) eq substr($b, 0, $min)) {
40 printf "# Apparently: %d bytes junk at the end of %s\n# %s\n",
41 abs(length($a) - length ($b)),
42 $_[length($a) < length ($b) ? 1 : 0],
43 "consider decreasing bufsize of recfrom.";
44 substr($a, $min) = "";
45 substr($b, $min) = "";
46 }
47 return 0;
48 }
cf7fe8a2 49 my @a = unpack_sockaddr_in($a);
50 my @b = unpack_sockaddr_in($b);
51 "$a[0]$a[1]" eq "$b[0]$b[1]";
52}
53
61f2b451 54$| = 1;
cf7fe8a2 55print "1..7\n";
61f2b451 56
57use Socket;
58use IO::Socket qw(AF_INET SOCK_DGRAM INADDR_ANY);
59
68820cec 60 # This can fail if localhost is undefined or the
61 # special 'loopback' address 127.0.0.1 is not configured
62 # on your system. (/etc/rc.config.d/netconfig on HP-UX.)
9b599b2a 63 # As a shortcut (not recommended) you could change 'localhost'
64 # here to be the name of this machine eg 'myhost.mycompany.com'.
68820cec 65
9b599b2a 66$udpa = IO::Socket::INET->new(Proto => 'udp', LocalAddr => 'localhost')
67 or die "$! (maybe your system does not have the 'localhost' address defined)";
cf7fe8a2 68
69print "ok 1\n";
70
9b599b2a 71$udpb = IO::Socket::INET->new(Proto => 'udp', LocalAddr => 'localhost')
72 or die "$! (maybe your system does not have the 'localhost' address defined)";
61f2b451 73
cf7fe8a2 74print "ok 2\n";
75
76$udpa->send("ok 4\n",0,$udpb->sockname);
61f2b451 77
abf95952 78print "not "
79 unless compare_addr($udpa->peername,$udpb->sockname, 'peername', 'sockname');
cf7fe8a2 80print "ok 3\n";
81
82my $where = $udpb->recv($buf="",5);
61f2b451 83print $buf;
cf7fe8a2 84
85my @xtra = ();
86
abf95952 87unless(compare_addr($where,$udpa->sockname, 'recv name', 'sockname')) {
cf7fe8a2 88 print "not ";
89 @xtra = (0,$udpa->sockname);
90}
91print "ok 5\n";
92
93$udpb->send("ok 6\n",@xtra);
61f2b451 94$udpa->recv($buf="",5);
95print $buf;
cf7fe8a2 96
97print "not " if $udpa->connected;
98print "ok 7\n";