Skip to content

Commit

Permalink
use sys(read|write) with coro
Browse files Browse the repository at this point in the history
  • Loading branch information
tokuhirom committed Sep 25, 2009
1 parent 1f71dc0 commit 66db46e
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions echo-coro.pl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@
while (1) {
my $csock = $sock->accept;
async_pool {
while (my $line = <$csock>) {
print $csock $line;
my $nb_fh = $csock->fh;
my $buf = \$csock->rbuf;
while (1) {
$csock->readable or last;
unless (sysread($nb_fh, $$buf, 8192)) {
last;
}
$csock->writable or last;
syswrite($csock, $$buf);
}
};
}
Expand Down

0 comments on commit 66db46e

Please sign in to comment.