Class: Sip2::Client
- Inherits:
-
Object
- Object
- Sip2::Client
- Defined in:
- lib/sip2/client.rb
Overview
Sip2 Client
Instance Method Summary collapse
-
#connect ⇒ Object
rubocop:disable Metrics/MethodLength.
-
#initialize(host:, port:, ignore_error_detection: false, timeout: nil, ssl_context: nil) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(host:, port:, ignore_error_detection: false, timeout: nil, ssl_context: nil) ⇒ Client
Returns a new instance of Client.
8 9 10 11 12 13 14 |
# File 'lib/sip2/client.rb', line 8 def initialize(host:, port:, ignore_error_detection: false, timeout: nil, ssl_context: nil) @host = host @port = port @ignore_error_detection = ignore_error_detection @timeout = timeout || NonBlockingSocket::DEFAULT_TIMEOUT @ssl_context = ssl_context end |
Instance Method Details
#connect ⇒ Object
rubocop:disable Metrics/MethodLength
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sip2/client.rb', line 16 def connect # rubocop:disable Metrics/MethodLength socket = NonBlockingSocket.connect host: @host, port: @port, timeout: @timeout # If we've been provided with an SSL context then use it to wrap out existing connection if @ssl_context socket = ::OpenSSL::SSL::SSLSocket.new socket, @ssl_context socket.hostname = @host # Needed for SNI socket.sync_close = true socket.connect socket.post_connection_check @host # Validate the peer certificate matches the host end if block_given? yield Connection.new(socket: socket, ignore_error_detection: @ignore_error_detection) end ensure socket&.close end |