Top Level Namespace

Instance Method Summary collapse

Instance Method Details

#autodetect_free_portObject

Raises:

  • (RuntimeError)


35
36
37
38
39
40
41
42
# File 'bin/cuke4php', line 35

def autodetect_free_port
  port = 16816
  while port_in_use?(port) && port < 65536 do
    port+=1
  end
  raise RuntimeError, "No free port detected" if port == 65536
  return port
end

#port_in_use?(_port) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'bin/cuke4php', line 15

def port_in_use?(_port)
  begin
    Timeout::timeout(1) do
      
      begin
        s = TCPSocket.new('localhost', _port)
        s.close
        return true
      rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
        return false
      end
      
    end
    
  rescue Timeout::Error
  end

  return false
end