<commit_before>module Selenium
  module WebDriver
    class PortProber
      def self.above(port)
        port += 1 until free? port
        port
      end
      
      def self.random
        server = TCPServer.new(Platform.localhost, 0)
        port   = server.addr[1]
        server.close
        
        port
      end
      
      def self.free?(port)
        TCPServer.new(Platform.localhost, port).close
        true
      rescue SocketError, Errno::EADDRINUSE
        false
      end
    end # PortProber
  end # WebDriver
end # Selenium
<commit_msg>JariBakken: Make sure Ruby's PortProber.above checks all network interfaces.<commit_after>module Selenium
  module WebDriver
    class PortProber
      def self.above(port)
        port += 1 until free? port
        port
      end

      def self.random
        server = TCPServer.new(Platform.localhost, 0)
        port   = server.addr[1]
        server.close

        port
      end

      def self.free?(port)
        interfaces = Socket.getaddrinfo("localhost", port).map { |e| e[2] }
        interfaces += ["0.0.0.0", Platform.ip]
        interfaces.each { |address| TCPServer.new(address, port).close }

        true
      rescue SocketError, Errno::EADDRINUSE
        false
      end

    end # PortProber
  end # WebDriver
end # Selenium

{'fraction_non_alphanumeric': 0.08199233716475096, 'fraction_numerical': 0.00842911877394636, 'mean_word_length': 1.9217002237136465, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2004903', 'n_tokens_mistral': 402, 'n_tokens_neox': 391, 'n_words': 100}