Permalink
Browse files

use EV, and better code

  • Loading branch information...
1 parent a74b9fe commit 1f71dc02e4aa0e8f84f035eb06cbae8746845af3 @tokuhirom committed Sep 25, 2009
Showing with 8 additions and 13 deletions.
  1. +8 −13 echo-coro.pl
View
@@ -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.