Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^3: use sysread to read non-blocking filehandle

by ikegami (Pope)
on Nov 04, 2014 at 17:00 UTC ( #1106074=note: print w/replies, xml ) Need Help??

in reply to Re^2: use sysread to read non-blocking filehandle
in thread use sysread to read non-blocking filehandle

If there is nothing to read,it means the sysread has finished all the reading?

Or an error. You got error EAGAIN. That error signifies that sysread should block, but the file handle is non-blocking.

EAGAIN or EWOULDBLOCK: The file descriptor fd refers to a socket and has been marked nonblocking (O_NON-BLOCK), and the write would block. POSIX.1-2001 allows either error to be returned for this case, and does not require these constants to have the same value, so a portable application should check for both possibilities.

What you want:

my $buf; while (1) { my $rv = sysread($out, $buf, 64*1024, length($buf)); if (!defined($rv) && !$!{EAGAIN} && !$!{EWOULDBLOCK}) { die $!; } if (defined($rv) && !$rv) { last; } ... whatever it is you wanted to do instead of blocking ... } print $buf;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1106074]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2020-12-05 11:18 GMT
Find Nodes?
    Voting Booth?
    How often do you use taint mode?

    Results (63 votes). Check out past polls.