lib/net/tcp_client/tcp_client.rb
def read(length, buffer = nil, timeout = read_timeout)
      if respond_to?(:logger)
        payload = {bytes: length, timeout: timeout}
        logger.benchmark_debug('#read', payload: payload) do
          data           = socket_read(length, buffer, timeout)
          # With trace level also log the received data
          payload[:data] = data if logger.trace?
          data
        end
      else
        socket_read(length, buffer, timeout)
      end
    rescue Exception => exc
      close if close_on_error
      raise exc
    end
def read(length, buffer = nil, timeout = read_timeout)
      if respond_to?(:logger)
        payload = {bytes: length, timeout: timeout}
        logger.benchmark_debug('#read', payload: payload) do
          data           = socket_read(length, buffer, timeout)
          # With trace level also log the received data
          payload[:data] = data if logger.trace?
          data
        end
      else
        socket_read(length, buffer, timeout)
      end
    rescue Exception => exc
      close if close_on_error
      raise exc
    end
Returns a response from the server

 Raises Net::TCPClient::ConnectionTimeout when the time taken to create a connection
        exceeds the :connect_timeout
        Connection is closed
 Raises Net::TCPClient::ConnectionFailure whenever Socket raises an error such as
        Error::EACCESS etc, see Socket#connect for more information
        Connection is closed
 Raises Net::TCPClient::ReadTimeout if the timeout has been exceeded waiting for the
        requested number of bytes from the server
        Partial data will not be returned
        Connection is _not_ closed and #read can be called again later
        to read the response from the connection

 Parameters
   length [Fixnum]
     The number of bytes to return
     #read will not return until 'length' bytes have been received from
     the server

   buffer [String]
    Optional buffer into which to write the data that is read.

   timeout [Float]
     Optional: Override the default read timeout for this read
     Number of seconds before raising Net::TCPClient::ReadTimeout when no data has
     been returned
     A value of -1 will wait forever for a response on the socket
     Default: :read_timeout supplied to #initialize

  Note: After a Net::TCPClient::ReadTimeout #read can be called again on
        the same socket to read the response later.
        If the application no longer wants the connection after a
        Net::TCPClient::ReadTimeout, then the #close method _must_ be called
        before calling _connect_ or _retry_on_connection_failure_ to create
        a new connection