Class: Protobuf::Rpc::Connectors::Ping

Inherits:
Object
  • Object
show all
Defined in:
lib/protobuf/rpc/connectors/ping.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ Ping

Returns a new instance of Ping.



9
10
11
12
# File 'lib/protobuf/rpc/connectors/ping.rb', line 9

def initialize(host, port)
  @host = host
  @port = port
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



7
8
9
# File 'lib/protobuf/rpc/connectors/ping.rb', line 7

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



7
8
9
# File 'lib/protobuf/rpc/connectors/ping.rb', line 7

def port
  @port
end

Instance Method Details

#online?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/protobuf/rpc/connectors/ping.rb', line 14

def online?
  socket = tcp_socket
  socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_LINGER, [1, 0].pack('ii'))

  true
rescue
  false
ensure
  begin
    socket && socket.close
  rescue IOError
    nil
  end
end

#timeoutObject



29
30
31
32
33
34
35
36
37
# File 'lib/protobuf/rpc/connectors/ping.rb', line 29

def timeout
  @timeout ||= begin
    if ::ENV.key?("PB_RPC_PING_PORT_TIMEOUT")
      ::ENV["PB_RPC_PING_PORT_TIMEOUT"].to_f / 1000
    else
      0.2 # 200 ms
    end
  end
end