1 |
elmex |
1.1 |
#!/opt/perl/bin/perl |
2 |
root |
1.9 |
|
3 |
elmex |
1.1 |
use strict; |
4 |
root |
1.9 |
|
5 |
root |
1.2 |
use AnyEvent::Impl::Perl; |
6 |
elmex |
1.7 |
use AnyEvent::Handle; |
7 |
|
|
use AnyEvent::Util; |
8 |
elmex |
1.1 |
|
9 |
|
|
my $lbytes; |
10 |
|
|
my $rbytes; |
11 |
|
|
|
12 |
elmex |
1.7 |
print "1..2\n"; |
13 |
|
|
|
14 |
elmex |
1.1 |
my $cv = AnyEvent->condvar; |
15 |
|
|
|
16 |
elmex |
1.7 |
my $hdl; |
17 |
root |
1.9 |
my $port; |
18 |
elmex |
1.7 |
|
19 |
root |
1.9 |
my $w = AnyEvent::Util::tcp_server undef, undef, |
20 |
|
|
sub { |
21 |
|
|
my ($fh, $host, $port) = @_; |
22 |
|
|
|
23 |
|
|
$hdl = AnyEvent::Handle->new (fh => $fh, on_eof => sub { $cv->broadcast }); |
24 |
|
|
|
25 |
|
|
$hdl->push_read_chunk (6, sub { |
26 |
|
|
my ($hdl, $data) = @_; |
27 |
|
|
|
28 |
|
|
if ($data eq "TEST\015\012") { |
29 |
|
|
print "ok 1 - server received client data\n"; |
30 |
|
|
} else { |
31 |
|
|
print "not ok 1 - server received bad client data\n"; |
32 |
|
|
} |
33 |
|
|
|
34 |
|
|
$hdl->push_write ("BLABLABLA\015\012"); |
35 |
|
|
}); |
36 |
|
|
}, sub { |
37 |
|
|
($port) = Socket::unpack_sockaddr_in getsockname $_[0]; |
38 |
elmex |
1.7 |
|
39 |
root |
1.9 |
0 |
40 |
|
|
}; |
41 |
elmex |
1.7 |
|
42 |
root |
1.4 |
|
43 |
root |
1.9 |
my $clhdl; |
44 |
|
|
my $wc = AnyEvent::Util::tcp_connect localhost => $port, sub { |
45 |
root |
1.10 |
my ($fh) = @_ |
46 |
|
|
or die "connect: $!"; |
47 |
elmex |
1.6 |
|
48 |
root |
1.9 |
$clhdl = AnyEvent::Handle->new (fh => $fh, on_eof => sub { $cv->broadcast }); |
49 |
elmex |
1.7 |
|
50 |
|
|
$clhdl->push_write ("TEST\015\012"); |
51 |
|
|
$clhdl->push_read_line (sub { |
52 |
|
|
my ($clhdl, $line) = @_; |
53 |
|
|
|
54 |
|
|
if ($line eq 'BLABLABLA') { |
55 |
|
|
print "ok 2 - client received response\n"; |
56 |
|
|
} else { |
57 |
|
|
print "not ok 2 - client received bad response\n"; |
58 |
elmex |
1.1 |
} |
59 |
|
|
|
60 |
elmex |
1.7 |
$cv->broadcast; |
61 |
|
|
}); |
62 |
root |
1.9 |
}; |
63 |
elmex |
1.1 |
|
64 |
|
|
$cv->wait; |