ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/eg/ae0.pl
(Generate patch)

Comparing AnyEvent/eg/ae0.pl (file contents):
Revision 1.1 by root, Tue Jun 23 12:21:34 2009 UTC vs.
Revision 1.2 by root, Thu Aug 6 14:00:36 2009 UTC

1# $Id: ae0.pl,v 1.1 2009/06/23 12:21:34 root Exp $ 1# $Id: ae0.pl,v 1.2 2009/08/06 14:00:36 root Exp $
2# An echo client-server benchmark. 2# An echo client-server benchmark.
3 3
4use warnings; 4use warnings;
5use strict; 5use strict;
6 6
18 LocalPort => $port, 18 LocalPort => $port,
19 Proto => 'tcp', 19 Proto => 'tcp',
20 ReuseAddr => 1, 20 ReuseAddr => 1,
21); 21);
22 22
23my $serv_w = AnyEvent->io (fh => $serv_sock, poll => "r", cb => sub { 23my $serv_w = AE::io $serv_sock, 0, sub {
24 accept my $fh, $serv_sock 24 accept my $fh, $serv_sock
25 or return; 25 or return;
26 sysread $serv_sock, my $buf, 512; 26 sysread $serv_sock, my $buf, 512;
27 syswrite $serv_sock, $buf; 27 syswrite $serv_sock, $buf;
28}); 28};
29 29
30my $t = time; 30my $t = time;
31my $connections; 31my $connections;
32 32
33sub _make_connection { 33sub _make_connection {
34 if ($connections++ < $CYCLES) { 34 if ($connections++ < $CYCLES) {
35 tcp_connect "127.0.0.1", $port, sub { 35 tcp_connect "127.0.0.1", $port, sub {
36 my ($fh) = @_ 36 my ($fh) = @_
37 or die "tcp_connect: $!"; 37 or die "tcp_connect: $!";
38 syswrite $fh, "can write $connections\n"; 38 syswrite $fh, "can write $connections\n";
39 my $w; $w = AnyEvent->io (fh => $fh, poll => "r", cb => sub { 39 my $w; $w = AE::io $fh, 0, sub {
40 sysread $fh, my $buf, 512; 40 sysread $fh, my $buf, 512;
41 undef $fh; 41 undef $fh;
42 undef $w; 42 undef $w;
43 &_make_connection; 43 &_make_connection;
44 }); 44 };
45 }; 45 };
46 } else { 46 } else {
47 $t = time - $t; 47 $t = time - $t;
48 printf "%.3f sec\n", $t; 48 printf "%.3f sec\n", $t;
49 exit; 49 exit;
50 } 50 }
51}; 51};
52 52
53_make_connection; 53_make_connection;
54AnyEvent->loop; 54AnyEvent->condvar->recv;
55 55

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines