my $select = IO::Select->new($sock) ; my $buffer = '' ; my $rc ; while (1) { $! = undef ; # no error, yet if ($select->can_read(10)) { $rc = sysread($sock, $buffer, 64*1024, length($buffer)); next if $rc ; # continue if not error and not "eof" last if defined($rc) ; # exit if "eof" } else { $rc = $! ? undef : 1 ; # $rc == undef if error, == 1 if time out last if $rc ; # exit if time out } ; redo if $! == EAGAIN ; # Not really expected, even with non-blocking redo if $! == EINTR ; # Signals ! last ; # exit on "hard" error } ; # Now: $rc == 0 => no error, == 1 => timed out, == undef => error