ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent/eg/ae0.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 use IO::Socket::INET;
12
13 my $CYCLES = 500;
14 my $port = 11212;
15
16 my $serv_sock = IO::Socket::INET-> new(
17 Listen => 5,
18 LocalPort => $port,
19 Proto => 'tcp',
20 ReuseAddr => 1,
21 );
22
23 my $serv_w = AnyEvent->io (fh => $serv_sock, poll => "r", cb => sub {
24 accept my $fh, $serv_sock
25 or return;
26 sysread $serv_sock, my $buf, 512;
27 syswrite $serv_sock, $buf;
28 });
29
30 my $t = time;
31 my $connections;
32
33 sub _make_connection {
34 if ($connections++ < $CYCLES) {
35 tcp_connect "127.0.0.1", $port, sub {
36 my ($fh) = @_
37 or die "tcp_connect: $!";
38 syswrite $fh, "can write $connections\n";
39 my $w; $w = AnyEvent->io (fh => $fh, poll => "r", cb => sub {
40 sysread $fh, my $buf, 512;
41 undef $fh;
42 undef $w;
43 &_make_connection;
44 });
45 };
46 } else {
47 $t = time - $t;
48 printf "%.3f sec\n", $t;
49 exit;
50 }
51 };
52
53 _make_connection;
54 AnyEvent->loop;
55