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

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

by roboticus (Chancellor)
on Nov 04, 2014 at 15:23 UTC ( #1106057=note: print w/replies, xml ) Need Help??

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


This is a bit oversimplified, as there's insufficient error checking and such. But I'd suggest doing something like "terminate the loop if I haven't received anything for X seconds" (where you'd have to choose X to balance between performance, and the possibility of a false failure). You could start with something like this:

my $timeout = time+$X; # timeout if we don't see anything in $X secon +ds my $ttl_bytes_rcvd=0; # haven't received anything yet while (time < $timeout) { ... read the data ... if ($bytes_read>0) { $timeout = time+$X; # Reset timeout if we actually saw some data $ttl_bytes_rcvd += $bytes_read; } # don't just hammer the CPU, give other processes a chance to do so +mething, # as well as allowing a bit of time for more data to arrive sleep 0.5; } if ($ttl_bytes_rcvd) { # process successful response ... } else { die "Error! No data received!\n"; }


When your only tool is a hammer, all problems look like your thumb.

Log In?

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

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

    Results (63 votes). Check out past polls.