class Nonnative::Port

Attributes

process[R]
timeout[R]

Public Class Methods

new(process) click to toggle source
# File lib/nonnative/port.rb, line 5
def initialize(process)
  @process = process
  @timeout = Nonnative::Timeout.new(process.timeout)
end

Public Instance Methods

closed?() click to toggle source
# File lib/nonnative/port.rb, line 20
def closed?
  timeout.perform do
    open_socket
    raise Nonnative::Error
  rescue Nonnative::Error
    sleep_interval
    retry
  rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET
    true
  end
end
open?() click to toggle source
# File lib/nonnative/port.rb, line 10
def open?
  timeout.perform do
    open_socket
    true
  rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
    sleep_interval
    retry
  end
end

Private Instance Methods

open_socket() click to toggle source
# File lib/nonnative/port.rb, line 36
def open_socket
  TCPSocket.new('0.0.0.0', process.port).close
end
sleep_interval() click to toggle source
# File lib/nonnative/port.rb, line 40
def sleep_interval
  sleep 0.01
end