Class: Mongo::SSLSocket
Overview
A basic wrapper over Ruby’s SSLSocket that initiates a TCP connection over SSL and then provides an basic interface mirroring Ruby’s TCPSocket, vis., TCPSocket#send and TCPSocket#read.
Instance Attribute Summary collapse
-
#pool ⇒ Object
Returns the value of attribute pool.
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
- #connect ⇒ Object
-
#initialize(host, port, op_timeout = nil, connect_timeout = nil) ⇒ SSLSocket
constructor
A new instance of SSLSocket.
- #read(length, buffer) ⇒ Object
- #send(data) ⇒ Object
Constructor Details
#initialize(host, port, op_timeout = nil, connect_timeout = nil) ⇒ SSLSocket
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mongo/util/ssl_socket.rb', line 14 def initialize(host, port, op_timeout=nil, connect_timeout=nil) @op_timeout = op_timeout @connect_timeout = connect_timeout @socket = ::TCPSocket.new(host, port) @socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) @ssl = OpenSSL::SSL::SSLSocket.new(@socket) @ssl.sync_close = true connect end |
Instance Attribute Details
#pool ⇒ Object
Returns the value of attribute pool.
12 13 14 |
# File 'lib/mongo/util/ssl_socket.rb', line 12 def pool @pool end |
Instance Method Details
#close ⇒ Object
51 52 53 |
# File 'lib/mongo/util/ssl_socket.rb', line 51 def close @ssl.close end |
#closed? ⇒ Boolean
55 56 57 |
# File 'lib/mongo/util/ssl_socket.rb', line 55 def closed? @ssl.closed? end |
#connect ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/mongo/util/ssl_socket.rb', line 27 def connect if @connect_timeout Timeout::timeout(@connect_timeout, ConnectionTimeoutError) do @ssl.connect end else @ssl.connect end end |
#read(length, buffer) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/mongo/util/ssl_socket.rb', line 41 def read(length, buffer) if @op_timeout Timeout::timeout(@op_timeout, OperationTimeout) do @ssl.sysread(length, buffer) end else @ssl.sysread(length, buffer) end end |
#send(data) ⇒ Object
37 38 39 |
# File 'lib/mongo/util/ssl_socket.rb', line 37 def send(data) @ssl.syswrite(data) end |