if (select($rout=$rin, undef, undef, $timeout)) { unless ($length = sysread($socket, $buf="", 1024)) { #connection error } # handle data in $buf } else { # timeout error }