Class: Thrift::SSLSocket

Inherits:
Socket show all
Defined in:
lib/thrift/transport/ssl_socket.rb

Instance Attribute Summary collapse

Attributes inherited from Socket

#handle, #timeout

Instance Method Summary collapse

Methods inherited from Socket

#close, #open?, #read, #write

Methods inherited from BaseTransport

#close, #flush, #open?, #read, #read_all, #read_byte, #read_into_buffer, #write

Constructor Details

#initialize(host = 'localhost', port = 9090, timeout = nil, ssl_context = nil) ⇒ SSLSocket

Returns a new instance of SSLSocket.



22
23
24
25
# File 'lib/thrift/transport/ssl_socket.rb', line 22

def initialize(host='localhost', port=9090, timeout=nil, ssl_context=nil)
  super(host, port, timeout)
  @ssl_context = ssl_context
end

Instance Attribute Details

#ssl_contextObject

Returns the value of attribute ssl_context.



27
28
29
# File 'lib/thrift/transport/ssl_socket.rb', line 27

def ssl_context
  @ssl_context
end

Instance Method Details

#openObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/thrift/transport/ssl_socket.rb', line 29

def open
  socket = super
  @handle = OpenSSL::SSL::SSLSocket.new(socket, @ssl_context)
  begin
    @handle.connect_nonblock
    @handle.post_connection_check(@host)
    @handle
  rescue IO::WaitReadable
    IO.select([ @handle ], nil, nil, @timeout)
    retry
  rescue IO::WaitWritable
    IO.select(nil, [ @handle ], nil, @timeout)
    retry
  rescue StandardError => e
    raise TransportException.new(TransportException::NOT_OPEN, "Could not connect to #{@desc}: #{e}")
  end
end

#to_sObject



47
48
49
# File 'lib/thrift/transport/ssl_socket.rb', line 47

def to_s
  "ssl(#{super.to_s})"
end