class Redis::Client
def set_socket_timeout(sock, timeout)
def set_socket_timeout(sock, timeout) secs = Integer(timeout) usecs = Integer((timeout - secs) * 1_000_000) optval = [secs, usecs].pack("l_2") begin sock.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval sock.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval rescue Exception => ex # Solaris, for one, does not like/support socket timeouts. log("Unable to use raw socket timeouts: #{ex.class.name}: #{ex.message}") end end