Class: Protobuf::Rpc::Connectors::Ping
- Inherits:
-
Object
- Object
- Protobuf::Rpc::Connectors::Ping
- Defined in:
- lib/protobuf/rpc/connectors/ping.rb
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(host, port) ⇒ Ping
constructor
A new instance of Ping.
- #online? ⇒ Boolean
- #timeout ⇒ Object
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
#host ⇒ Object (readonly)
Returns the value of attribute host.
7 8 9 |
# File 'lib/protobuf/rpc/connectors/ping.rb', line 7 def host @host end |
#port ⇒ Object (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
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 |
#timeout ⇒ Object
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 |