Class: Selenium::WebDriver::PortProber

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

Constant Summary collapse

IGNORED_ERRORS =
[Errno::EADDRNOTAVAIL, Errno::EAFNOSUPPORT].tap { |arr|
  arr << Errno::EBADF if Platform.cygwin?
  arr << Errno::EACCES if Platform.windows?
}.freeze

Class Method Summary collapse

Class Method Details

.above(port) ⇒ Object



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

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

.free?(port) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/selenium/webdriver/common/port_prober.rb', line 33

def self.free?(port)
  Platform.interfaces.each do |host|
    TCPServer.new(host, port).close
  rescue *IGNORED_ERRORS => e
    WebDriver.logger.debug("port prober could not bind to #{host}:#{port} (#{e.message})", id: :driver_service)
    # ignored - some machines appear unable to bind to some of their interfaces
  end

  true
rescue SocketError, Errno::EADDRINUSE
  false
end