Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 64113365f4
Fetching contributors…

Cannot retrieve contributors at this time

file 44 lines (40 sloc) 0.877 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 35 36 37 38 39 40 41 42 43 44
use strict;
use warnings;
use Parallel::Prefork;
use Getopt::Long;
use IO::Socket::INET;
use Parallel::Prefork;

my $concurrent = 10;
my $port = 9040;
GetOptions(
    'concurrent=s' => \$concurrent,
    'port=i' => \$port,
);

print "$0: http://localhost:$port/\n";
print "concurrency: $concurrent\n";

my $sock = IO::Socket::INET->new(
    LocalHost => '0.0.0.0',
    LocalPort => $port,
    Listen => 10,
    ReuseAddr => 1
) or die $!;

my $pm = Parallel::Prefork->new(
    {
        max_workers => $concurrent,
        trap_signals => {
            TERM => 'TERM',
            HUP => 'TERM',
        },
    }
);
while ( $pm->signal_received ne 'TERM' ) {
    $pm->start and next;
    while (1) {
        my $csock = $sock->accept;
        while (my $line = <$csock>) {
            print $csock $line;
        }
    }
    $pm->finish;
}
$pm->wait_all_children;
Something went wrong with that request. Please try again.