ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/04_listen.t
Revision: 1.16
Committed: Fri Jul 24 22:47:04 2009 UTC (14 years, 11 months ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-4_91, rel-5_112, rel-5_251, rel-5_261, rel-5_271, rel-5_28, rel-5_29, rel-5_21, rel-5_22, rel-5_23, rel-5_24, rel-5_26, rel-5_27, rel-5_1, rel-5_0, rel-5_2, rel-5_201, rel-5_202, rel-5_111, rel-4_881, rel-4_9, rel-5_01, rel-4_88, rel-5_11, rel-5_12
Changes since 1.15: +14 -17 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::Socket;
8 use AnyEvent;
9
10 my $lbytes;
11 my $rbytes;
12
13 print "1..2\n";
14
15 my $cv = AnyEvent->condvar;
16
17 my $hdl;
18 my $port;
19
20 my $w = tcp_server undef, undef,
21 sub {
22 my ($fh, $host, $port) = @_;
23
24 $hdl = AnyEvent::Handle->new (fh => $fh, on_eof => sub { $cv->broadcast });
25
26 $hdl->push_read (chunk => 6, sub {
27 my ($hdl, $data) = @_;
28
29 if ($data eq "TEST\015\012") {
30 print "ok 1 - server received client data\n";
31 } else {
32 print "not ok 1 - server received bad client data\n";
33 }
34
35 $hdl->push_write ("BLABLABLA\015\012");
36 });
37 }, sub {
38 $port = $_[2];
39
40 0
41 };
42
43 my $clhdl; $clhdl = AnyEvent::Handle->new (
44 connect => [localhost => $port],
45 on_eof => sub { $cv->broadcast },
46 );
47
48 $clhdl->push_write ("TEST\015\012");
49 $clhdl->push_read (line => sub {
50 my ($clhdl, $line) = @_;
51
52 if ($line eq 'BLABLABLA') {
53 print "ok 2 - client received response\n";
54 } else {
55 print "not ok 2 - client received bad response\n";
56 }
57
58 $cv->broadcast;
59 });
60
61 $cv->wait;