Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b68c2cf17e
Fetching contributors…

Cannot retrieve contributors at this time

file 34 lines (31 sloc) 0.708 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
use strict;
use warnings;
use AnyEvent::Impl::EV;
use AE;
use Getopt::Long;
use AnyEvent::Socket;
use AnyEvent::Handle;

my $concurrent = 2; # = number of CPU core or a few over
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;
Something went wrong with that request. Please try again.