class Kafka::SSLSocketWithTimeout
def read(num_bytes)
-
(String)
- the data that was read from the socket.
Raises:
-
(Errno::ETIMEDOUT)
- if the timeout is exceeded.
Parameters:
-
num_bytes
(Integer
) -- the number of bytes to read.
def read(num_bytes) buffer = '' until buffer.length >= num_bytes begin # unlike plain tcp sockets, ssl sockets don't support IO.select # properly. # Instead, timeouts happen on a per read basis, and we have to # catch exceptions from read_nonblock, and gradually build up # our read buffer. buffer << @ssl_socket.read_nonblock(num_bytes - buffer.length) rescue IO::WaitReadable if select_with_timeout(@ssl_socket, :read) retry else raise Errno::ETIMEDOUT end rescue IO::WaitWritable if select_with_timeout(@ssl_socket, :write) retry else raise Errno::ETIMEDOUT end end end buffer end