Skip to content

Commit

Permalink
use EV, and better code
Browse files Browse the repository at this point in the history
  • Loading branch information
tokuhirom committed Sep 25, 2009
1 parent a74b9fe commit 1f71dc0
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions echo-coro.pl
Expand Up @@ -3,31 +3,26 @@
use Coro;
use Coro::Socket;
use Coro::Semaphore;
use Coro::Event;
use Coro::EV;
use Getopt::Long;

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

print "coro: http://localhost:$port/\n";
print "concurrency: $concurrent\n";
local $Coro::POOL_SIZE = $concurrent;
my $sock = Coro::Socket->new(LocalHost => '0.0.0.0', LocalPort => $port, Listen => 10, ReuseAddr => 1);
my @coros;
for my $i (1..$concurrent) {
print "awake thread $i\n";
push @coros, async {
while (1) {
my $csock = $sock->accept;
while (my $line = <$csock>) {
print $csock $line;
}
while (1) {
my $csock = $sock->accept;
async_pool {
while (my $line = <$csock>) {
print $csock $line;
}
};
}
push @coros, async { Event::loop() };
$_->join for @coros;

0 comments on commit 1f71dc0

Please sign in to comment.