Sha256: f8f65695fbd99c96403721d729416e4a720202cb12ae1c966f70cbd362a70329

Contents?: true

Size: 813 Bytes

Versions: 51

Compression:

Stored size: 813 Bytes

Contents

# frozen_string_literal: true

module Nonnative
  class Port
    def initialize(process)
      @process = process
      @timeout = Nonnative::Timeout.new(process.timeout)
    end

    def open?
      timeout.perform do
        open_socket
        true
      rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
        sleep_interval
        retry
      end
    end

    def closed?
      timeout.perform do
        open_socket
        raise Nonnative::Error
      rescue Nonnative::Error
        sleep_interval
        retry
      rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ECONNRESET
        true
      end
    end

    private

    attr_reader :process, :timeout

    def open_socket
      TCPSocket.new('0.0.0.0', process.port).close
    end

    def sleep_interval
      sleep 0.01
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
nonnative-1.58.0 lib/nonnative/port.rb
nonnative-1.57.1 lib/nonnative/port.rb
nonnative-1.57.0 lib/nonnative/port.rb
nonnative-1.56.1 lib/nonnative/port.rb
nonnative-1.56.0 lib/nonnative/port.rb
nonnative-1.55.0 lib/nonnative/port.rb
nonnative-1.54.0 lib/nonnative/port.rb
nonnative-1.53.0 lib/nonnative/port.rb
nonnative-1.51.1 lib/nonnative/port.rb
nonnative-1.48.0 lib/nonnative/port.rb
nonnative-1.47.0 lib/nonnative/port.rb
nonnative-1.46.0 lib/nonnative/port.rb
nonnative-1.45.0 lib/nonnative/port.rb
nonnative-1.44.0 lib/nonnative/port.rb
nonnative-1.43.0 lib/nonnative/port.rb
nonnative-1.42.0 lib/nonnative/port.rb
nonnative-1.41.0 lib/nonnative/port.rb
nonnative-1.40.0 lib/nonnative/port.rb
nonnative-1.39.0 lib/nonnative/port.rb
nonnative-1.38.0 lib/nonnative/port.rb