ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/04_listen.t
Revision: 1.9
Committed: Sat May 17 21:08:05 2008 UTC (16 years, 1 month ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-3_5
Changes since 1.8: +29 -30 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #!/opt/perl/bin/perl
2
3 use strict;
4
5 use AnyEvent::Impl::Perl;
6 use AnyEvent::Handle;
7 use AnyEvent::Util;
8
9 my $lbytes;
10 my $rbytes;
11
12 print "1..2\n";
13
14 my $cv = AnyEvent->condvar;
15
16 my $hdl;
17 my $port;
18
19 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
39 0
40 };
41
42
43 my $clhdl;
44 my $wc = AnyEvent::Util::tcp_connect localhost => $port, sub {
45 my ($fh) = @_;
46
47 $clhdl = AnyEvent::Handle->new (fh => $fh, on_eof => sub { $cv->broadcast });
48
49 $clhdl->push_write ("TEST\015\012");
50 $clhdl->push_read_line (sub {
51 my ($clhdl, $line) = @_;
52
53 if ($line eq 'BLABLABLA') {
54 print "ok 2 - client received response\n";
55 } else {
56 print "not ok 2 - client received bad response\n";
57 }
58
59 $cv->broadcast;
60 });
61 };
62
63 $cv->wait;