ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/04_listen.t
Revision: 1.15
Committed: Sun May 25 02:26:49 2008 UTC (16 years, 1 month ago) by root
Content type: application/x-troff
Branch: MAIN
CVS Tags: rel-4_151, rel-4_152, rel-4_04, rel-4_23, rel-4_21, rel-4_412, rel-4_81, rel-4_83, rel-4_82, rel-4_86, rel-4_352, rel-4_351, rel-4_14, rel-4_15, rel-4_13, rel-0_85, rel-4_331, rel-4_231, rel-4_233, rel-4_232, rel-4_8, rel-4_234, rel-4_4, rel-4_05, rel-4_12, rel-4_11, rel-4_22, rel-4_161, rel-4_160, rel-4_411, rel-4_45, rel-4_41, rel-4_42, rel-4_1, rel-4_2, rel-4_3, rel-4_31, rel-4_32, rel-4_33, rel-4_34, rel-4_35, rel-4_03
Changes since 1.14: +1 -1 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;
44 my $wc = tcp_connect localhost => $port, sub {
45 my ($fh) = @_
46 or die "connect: $!";
47
48 $clhdl = AnyEvent::Handle->new (fh => $fh, on_eof => sub { $cv->broadcast });
49
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 }
59
60 $cv->broadcast;
61 });
62 };
63
64 $cv->wait;