Permalink
Browse files

use sys(read|write) with coro

  • Loading branch information...
1 parent 1f71dc0 commit 66db46ef55a6d3f031ed665f653d57d0b4f0c268 @tokuhirom committed Sep 25, 2009
Showing with 9 additions and 2 deletions.
  1. +9 −2 echo-coro.pl
View
@@ -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);
}
};
}

0 comments on commit 66db46e

Please sign in to comment.