From: Dobrica Pavlinusic Date: Sun, 18 Jan 2015 22:06:00 +0000 (+0100) Subject: added read timeout X-Git-Url: http://git.rot13.org/?p=vrDialog;a=commitdiff_plain;h=HEAD added read timeout --- diff --git a/dialog.pl b/dialog.pl index 381d1e4..d868ed9 100755 --- a/dialog.pl +++ b/dialog.pl @@ -47,8 +47,16 @@ die "can't connect" unless $sock; sub read_serial { my $len = shift; my $buffer; - $sock->read( $buffer, $len ); - warn "## read $len ",as_hex($buffer) if $debug; + eval { + local $SIG{ALRM} = sub { die "read timeout" }; + alarm 3; + + warn "## read_serial $len" if $debug; + $sock->read( $buffer, $len ); + warn "## read $len ",as_hex($buffer) if $debug; + }; + alarm 0; + warn "ERROR: $@" if $@; return $buffer; }