ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/t/handle/04_listen.t
(Generate patch)

Comparing AnyEvent/t/handle/04_listen.t (file contents):
Revision 1.9 by root, Sat May 17 21:08:05 2008 UTC vs.
Revision 1.14 by root, Sat May 24 23:15:14 2008 UTC

2 2
3use strict; 3use strict;
4 4
5use AnyEvent::Impl::Perl; 5use AnyEvent::Impl::Perl;
6use AnyEvent::Handle; 6use AnyEvent::Handle;
7use AnyEvent::Socket;
7use AnyEvent::Util; 8use AnyEvent;
8 9
9my $lbytes; 10my $lbytes;
10my $rbytes; 11my $rbytes;
11 12
12print "1..2\n"; 13print "1..2\n";
14my $cv = AnyEvent->condvar; 15my $cv = AnyEvent->condvar;
15 16
16my $hdl; 17my $hdl;
17my $port; 18my $port;
18 19
19my $w = AnyEvent::Util::tcp_server undef, undef, 20my $w = tcp_server undef, undef,
20 sub { 21 sub {
21 my ($fh, $host, $port) = @_; 22 my ($fh, $host, $port) = @_;
22 23
23 $hdl = AnyEvent::Handle->new (fh => $fh, on_eof => sub { $cv->broadcast }); 24 $hdl = AnyEvent::Handle->new (fh => $fh, on_eof => sub { $cv->broadcast });
24 25
25 $hdl->push_read_chunk (6, sub { 26 $hdl->push_read (chunk => 6, sub {
26 my ($hdl, $data) = @_; 27 my ($hdl, $data) = @_;
27 28
28 if ($data eq "TEST\015\012") { 29 if ($data eq "TEST\015\012") {
29 print "ok 1 - server received client data\n"; 30 print "ok 1 - server received client data\n";
30 } else { 31 } else {
37 ($port) = Socket::unpack_sockaddr_in getsockname $_[0]; 38 ($port) = Socket::unpack_sockaddr_in getsockname $_[0];
38 39
39 0 40 0
40 }; 41 };
41 42
42
43my $clhdl; 43my $clhdl;
44my $wc = AnyEvent::Util::tcp_connect localhost => $port, sub { 44my $wc = tcp_connect localhost => $port, sub {
45 my ($fh) = @_; 45 my ($fh) = @_
46 or die "connect: $!";
46 47
47 $clhdl = AnyEvent::Handle->new (fh => $fh, on_eof => sub { $cv->broadcast }); 48 $clhdl = AnyEvent::Handle->new (fh => $fh, on_eof => sub { $cv->broadcast });
48 49
49 $clhdl->push_write ("TEST\015\012"); 50 $clhdl->push_write ("TEST\015\012");
50 $clhdl->push_read_line (sub { 51 $clhdl->push_read (line => sub {
51 my ($clhdl, $line) = @_; 52 my ($clhdl, $line) = @_;
52 53
53 if ($line eq 'BLABLABLA') { 54 if ($line eq 'BLABLABLA') {
54 print "ok 2 - client received response\n"; 55 print "ok 2 - client received response\n";
55 } else { 56 } else {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines