lib/ztk/tcp_socket_check.rb
# Check to see if socket on the host and port specified is ready.  This
# method will timeout and return false after the amount of seconds specified
# in *config.timeout* has passed if the socket has not become ready.
#
# @return [Boolean] Returns true or false depending on Whether the socket
#   is ready or not.
Check to see if socket on the host and port specified is ready.  This
method will timeout and return false after the amount of seconds specified
in *config.timeout* has passed if the socket has not become ready.
Check to see if socket on the host and port specified is ready . This method will timeout and return false after the amount of seconds specified in * config . timeout * has passed if the socket has not become ready .
def ready?
      config.host.nil? and log_and_raise(TCPSocketCheckError, "You must supply a host!")
      config.port.nil? and log_and_raise(TCPSocketCheckError, "You must supply a port!")
      socket = TCPSocket.new(config.host, config.port)
      if config.data.nil?
        config.ui.logger.debug { "read(#{config.host}:#{config.port})" }
        ((IO.select([socket], nil, nil, config.timeout) && socket.gets) ? true : false)
      else
        config.ui.logger.debug { "write(#{config.host}:#{config.port}, #{config.data.size} bytes)" }
        ((IO.select(nil, [socket], nil, config.timeout) && socket.write(config.data)) ? true : false)
      end
    rescue Errno::ETIMEDOUT, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, Errno::EHOSTDOWN, Errno::ENETUNREACH => e
      config.ui.logger.debug { "#{config.host}:#{config.port} - #{e.message}" }
      false
    ensure
      (socket && socket.close)
    end
def ready? config . host . nil? and log_and_raise ( TCPSocketCheckError , "You must supply a host!" ) config . port . nil? and log_and_raise ( TCPSocketCheckError , "You must supply a port!" ) socket = TCPSocket . new ( config . host , config . port ) if config . data . nil? config . ui . logger . debug { "read(#{config.host}:#{config.port})" } ( ( IO . select ( [ socket ] , nil , nil , config . timeout ) && socket . gets ) ? true : false ) else config . ui . logger . debug { "write(#{config.host}:#{config.port}, #{config.data.size} bytes)" } ( ( IO . select ( nil , [ socket ] , nil , config . timeout ) && socket . write ( config . data ) ) ? true : false ) end rescue Errno :: ETIMEDOUT , Errno :: ECONNREFUSED , Errno :: ECONNRESET , Errno :: EHOSTUNREACH , Errno :: EHOSTDOWN , Errno :: ENETUNREACH => e config . ui . logger . debug { "#{config.host}:#{config.port} - #{e.message}" } false ensure ( socket && socket . close ) end
Check to see if socket on the host and port specified is ready.
Check to see if socket on the host and port specified is ready .
Returns true or false depending on Whether the socket is ready or not.
Returns true or false depending on Whether the socket is ready or not .
Boolean