Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by ikegami (Patriarch)
on Nov 04, 2014 at 17:00 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-19 17:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found