Permalink
Browse files

do fork

  • Loading branch information...
1 parent b95e735 commit 56628aa7fa281cd6ba9852e90b6d82aad8d083a7 @hirose31 hirose31 committed Sep 24, 2009
Showing with 34 additions and 0 deletions.
  1. +34 −0 echo-ae+mp.pl
View
@@ -0,0 +1,34 @@
+use strict;
+use warnings;
+use AE;
+use Getopt::Long;
+use AnyEvent::Socket;
+use AnyEvent::Handle;
+
+my $concurrent = 2;
+my $port = 9010;
+GetOptions(
+ 'port=i' => \$port,
+ 'concurrent=s' => \$concurrent,
+);
+
+print "$0: http://localhost:$port/\n";
+print "concurrency: $concurrent\n";
+
+tcp_server undef, $port, sub {
+ my ($fh, $host, $port) = @_;
+ my $sock = AnyEvent::Handle->new(fh => $fh);
+ $sock->on_read(
+ sub {
+ $sock->push_write($_[0]->{rbuf});
+ $_[0]->{rbuf} = '';
+ }
+ );
+}, sub {
+ my ($fh, $host, $port) = @_;
+ for (2 .. $concurrent) {
+ fork || return;
+ }
+};
+AE::cv->recv;
+

0 comments on commit 56628aa

Please sign in to comment.