def read(num_bytes)
      buffer = String.new

      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
def read(num_bytes)
      buffer = String.new

      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
Opens a socket.

 @param host [String]
 @param port [Integer]
 @param connect_timeout [Integer] the connection timeout, in seconds.
 @param timeout [Integer] the read and write timeout, in seconds.
 @param ssl_context [OpenSSL::SSL::SSLContext] which SSLContext the ssl connection should use
 @raise [Errno::ETIMEDOUT] if the timeout is exceeded.
 Reads bytes from the socket, possible with a timeout.

 @param num_bytes [Integer] the number of bytes to read.
 @raise [Errno::ETIMEDOUT] if the timeout is exceeded.
 @return [String] the data that was read from the socket.