in reply to blocking socket and alarm

The function passed to alarm_call is not called on timeout as you expect. The function passed to alarm_call is the one alarm_call will interupt after the specified timeout. Reread the docs.

sub socket_read { my $len; { ($len, my $errmsg) = alarm_call(60, '->sysread', $socket, $lin +e, 1024); if (defined($len)) { if ($len eq 'TIMEOUT') { print STDERR "Received alarm\n"; redo; } if ($len eq 'ERROR') { die($errmsg); } } } ... }

Of course, you could also use alarm directly.

sub socket_read { my $len; { eval { local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n require +d alarm 60; $len = $socket->sysread($line, 1024); }; alarm 0; if (my $e = $@) { if ($e eq "alarm\n") { print STDERR "Received alarm\n"; redo; } die($e); } } ... }

Untested.

Update: Added second snippet. Handle exceptions.