Hail all Monks!
I want to try reading from a handle (a pipe in my case) and timing out if nothing happens after X seconds. I'm using a $SIG{ALRM} right now, but that involves a callback when all I really want to do is stop trying to read and continue execution right after the read. I found myself considering a GOTO inside the $SIG{ALRM} callback, and that's when I decided a perlmonks post was in order.
To clarify, here's the code of my $SIG{ALRM} rendition:
# $read is an open pipe from earlier local $SIG{ALRM} = sub { goto('WIBBLE'); }; alarm(60); $result = <$read>; :WIBBLE if ( !defined($result) ) { print "Oh well, I didn't need that anyway...\n"; }
And to restate my question: What's the best way to handle a timeout like this?
In reply to Best way to timeout on a read by pileofrogs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |