ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/eg/ae2.pl
Revision: 1.1
Committed: Tue Jun 23 12:21:34 2009 UTC (15 years ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-4_45, rel-4_82, rel-4_42, rel-4_412, rel-4_83, rel-4_86, rel-4_81, rel-4_881, rel-4_88, rel-0_85, rel-4_91, rel-4_8, rel-4_9
Log Message:
*** empty log message ***

File Contents

# Content
1 # $Id: tcp-poe-raw.pl,v 1.1 2009/01/17 11:29:06 dk Exp $
2 # An echo client-server benchmark.
3
4 use warnings;
5 use strict;
6
7 use Time::HiRes qw(time);
8 use AnyEvent;
9 use AnyEvent::Impl::Perl;
10 use AnyEvent::Socket;
11
12 my $CYCLES = 500;
13 my $port = 11212;
14
15 tcp_server undef, $port, sub {
16 my ($fh) = @_
17 or die "tcp_server: $!";
18
19 my $hdl = new AnyEvent::Handle fh => $fh;
20
21 $hdl->push_read (line => sub {
22 $hdl->push_write ("$_[1]\n");
23 undef $hdl;
24 });
25 };
26
27 my $t = time;
28
29 for my $connections (1..$CYCLES) {
30 my $cv = AnyEvent->condvar;
31
32 tcp_connect "127.0.0.1", $port, sub {
33 my ($fh) = @_
34 or die "tcp_connect: $!";
35
36 my $hdl = new AnyEvent::Handle fh => $fh;
37
38 $hdl->push_write ("can write $connections\n");
39 $hdl->push_read (line => sub {
40 undef $hdl;
41 $cv->send;
42 });
43 };
44
45 $cv->recv;
46 };
47
48 $t = time - $t;
49 printf "%.3f sec\n", $t;
50 exit;