Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use sys(read|write) with coro

  • Loading branch information...
commit 66db46ef55a6d3f031ed665f653d57d0b4f0c268 1 parent 1f71dc0
@tokuhirom authored
Showing with 9 additions and 2 deletions.
  1. +9 −2 echo-coro.pl
View
11 echo-coro.pl
@@ -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);
}
};
}
Please sign in to comment.
Something went wrong with that request. Please try again.