Class: Gitlab::TcpChecker
- Inherits:
-
Object
- Object
- Gitlab::TcpChecker
- Defined in:
- lib/gitlab/tcp_checker.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#local_host ⇒ Object
readonly
Returns the value of attribute local_host.
-
#local_port ⇒ Object
readonly
Returns the value of attribute local_port.
-
#remote_host ⇒ Object
readonly
Returns the value of attribute remote_host.
-
#remote_port ⇒ Object
readonly
Returns the value of attribute remote_port.
Instance Method Summary collapse
- #check(timeout: 10) ⇒ Object
-
#initialize(remote_host, remote_port, local_host = nil, local_port = nil) ⇒ TcpChecker
constructor
A new instance of TcpChecker.
- #local ⇒ Object
- #remote ⇒ Object
Constructor Details
#initialize(remote_host, remote_port, local_host = nil, local_port = nil) ⇒ TcpChecker
Returns a new instance of TcpChecker.
7 8 9 10 11 12 |
# File 'lib/gitlab/tcp_checker.rb', line 7 def initialize(remote_host, remote_port, local_host = nil, local_port = nil) @remote_host = remote_host @remote_port = remote_port @local_host = local_host @local_port = local_port end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
5 6 7 |
# File 'lib/gitlab/tcp_checker.rb', line 5 def error @error end |
#local_host ⇒ Object (readonly)
Returns the value of attribute local_host.
5 6 7 |
# File 'lib/gitlab/tcp_checker.rb', line 5 def local_host @local_host end |
#local_port ⇒ Object (readonly)
Returns the value of attribute local_port.
5 6 7 |
# File 'lib/gitlab/tcp_checker.rb', line 5 def local_port @local_port end |
#remote_host ⇒ Object (readonly)
Returns the value of attribute remote_host.
5 6 7 |
# File 'lib/gitlab/tcp_checker.rb', line 5 def remote_host @remote_host end |
#remote_port ⇒ Object (readonly)
Returns the value of attribute remote_port.
5 6 7 |
# File 'lib/gitlab/tcp_checker.rb', line 5 def remote_port @remote_port end |
Instance Method Details
#check(timeout: 10) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/gitlab/tcp_checker.rb', line 22 def check(timeout: 10) Socket.tcp( remote_host, remote_port, local_host, local_port, connect_timeout: timeout ) do |sock| @local_port, @local_host = Socket.unpack_sockaddr_in(sock.local_address) @remote_port, @remote_host = Socket.unpack_sockaddr_in(sock.remote_address) end true rescue StandardError => err @error = err false end |
#local ⇒ Object
14 15 16 |
# File 'lib/gitlab/tcp_checker.rb', line 14 def local join_host_port(local_host, local_port) end |
#remote ⇒ Object
18 19 20 |
# File 'lib/gitlab/tcp_checker.rb', line 18 def remote join_host_port(remote_host, remote_port) end |