Module: Cute::Network

Defined in:
lib/cute/net.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.port_open?(ip, port) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
12
13
# File 'lib/cute/net.rb', line 5

def Network::port_open?(ip, port)
  begin
    s = TCPSocket.new(ip, port)
    s.close
    return true
  rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ETIMEDOUT
    return false
  end
end

.wait_open_port(host, port, timeout = 120) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cute/net.rb', line 15

def Network::wait_open_port(host, port, timeout = 120)
  def now()
    return Time.now.to_f
  end
  bound = now() + timeout
  while now() < bound do
    t = now()
    return true if port_open?(host, port)
    dt = now() - t
    sleep(0.5 - dt) if dt < 0.5
  end
  return false
end

Instance Method Details

#nowObject



16
17
18
# File 'lib/cute/net.rb', line 16

def now()
  return Time.now.to_f
end