Coro::Handle - non-blocking io with a blocking interface. |
Coro::Handle - non-blocking io with a blocking interface.
use Coro::Handle;
This module implements io-handles in a coroutine-compatible way, that is, other coroutines can run while reads or writes block on the handle. It does NOT inherit from IO::Handle but uses tied objects.
new_from_fh
on the given
filehandle. Use it to replace a normal perl filehandle by a non-blocking
equivalent.
readline([$terminator])
autoflush([...])
timeout([...])
0
is a valid timeout, use undef
to disable the timeout.
You can use this function to implement your own optimized reader when neither readline nor sysread are viable candidates, like this:
# first get the _real_ non-blocking filehandle # and fetch a reference to the read buffer my $nb_fh = $fh->fh; my $buf = \$fh->rbuf;
for(;;) { # now use buffer contents, modifying # if necessary to reflect the removed data
last if $$buf ne ""; # we have leftover data
# read another buffer full of data $fh->readable or die "end of file"; sysread $nb_fh, $$buf, 8192; }
- Perl's IO-Handle model is THE bug.
Marc Lehmann <pcg@goof.com> http://www.goof.com/pcg/marc/
Coro::Handle - non-blocking io with a blocking interface. |