ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/04_listen.t
Revision: 1.11
Committed: Wed May 21 14:37:55 2008 UTC (16 years, 1 month ago) by root
Content type: application/x-troff
Branch: MAIN
Changes since 1.10: +1 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
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 root 1.11 use AnyEvent;
9 elmex 1.1
10     my $lbytes;
11     my $rbytes;
12    
13 elmex 1.7 print "1..2\n";
14    
15 elmex 1.1 my $cv = AnyEvent->condvar;
16    
17 elmex 1.7 my $hdl;
18 root 1.9 my $port;
19 elmex 1.7
20 root 1.9 my $w = AnyEvent::Util::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) = Socket::unpack_sockaddr_in getsockname $_[0];
39 elmex 1.7
40 root 1.9 0
41     };
42 elmex 1.7
43 root 1.4
44 root 1.9 my $clhdl;
45     my $wc = AnyEvent::Util::tcp_connect localhost => $port, sub {
46 root 1.10 my ($fh) = @_
47     or die "connect: $!";
48 elmex 1.6
49 root 1.9 $clhdl = AnyEvent::Handle->new (fh => $fh, on_eof => sub { $cv->broadcast });
50 elmex 1.7
51     $clhdl->push_write ("TEST\015\012");
52     $clhdl->push_read_line (sub {
53     my ($clhdl, $line) = @_;
54    
55     if ($line eq 'BLABLABLA') {
56     print "ok 2 - client received response\n";
57     } else {
58     print "not ok 2 - client received bad response\n";
59 elmex 1.1 }
60    
61 elmex 1.7 $cv->broadcast;
62     });
63 root 1.9 };
64 elmex 1.1
65     $cv->wait;