Class: Selenium::WebDriver::PortProber

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium/webdriver/common/port_prober.rb

Class Method Summary collapse

Class Method Details

.above(port) ⇒ Object


4
5
6
7
# File 'lib/selenium/webdriver/common/port_prober.rb', line 4

def self.above(port)
  port += 1 until free? port
  port
end

.free?(port) ⇒ Boolean


22
23
24
25
26
27
# File 'lib/selenium/webdriver/common/port_prober.rb', line 22

def self.free?(port)
  Platform.interfaces.each { |host| TCPServer.new(host, port).close }
  true
rescue SocketError, Errno::EADDRINUSE
  false
end

.randomObject


9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/selenium/webdriver/common/port_prober.rb', line 9

def self.random
  # TODO: Avoid this
  #
  # (a) should pick a port that's guaranteed to be free on all interfaces
  # (b) should pick a random port outside the ephemeral port range
  #
  server = TCPServer.new(Platform.localhost, 0)
  port   = server.addr[1]
  server.close

  port
end