module Glint::Util

Public Class Methods

check_port(port) click to toggle source
# File lib/glint/util.rb, line 12
def self.check_port(port)
  begin
    socket = TCPSocket.open('127.0.0.1', port)
    socket.close
    return true
  rescue Errno::ECONNREFUSED
    return false
  end
end
empty_port() click to toggle source
# File lib/glint/util.rb, line 5
def self.empty_port
  s = TCPServer.open(0)
  port = s.addr[1]
  s.close
  port
end
wait_port(port) click to toggle source
# File lib/glint/util.rb, line 22
def self.wait_port(port)
  100.times do |n|
    return true if check_port(port)
    sleep 0.1
  end

  raise RuntimeError.new("Could not open the port: #{port}")
end