port_open?

in lib/between_meals/util.rb [73:93]


    def port_open?(port)
      ips = Socket.ip_address_list
      ips.map!(&:ip_address)
      ips.each do |ip|
        begin
          Timeout.timeout(1) do
            begin
              s = TCPSocket.new(ip, port)
              s.close
              return true
            rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
              next
            end
          end
        rescue Timeout::Error
          next
        end
      end
      return false
    end