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
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#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
Returns a new instance of SSLSocket.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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 @pid = Process.pid @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
#pid ⇒ Object
Returns the value of attribute pid.
12 13 14 |
# File 'lib/mongo/util/ssl_socket.rb', line 12 def pid @pid end |
#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
52 53 54 |
# File 'lib/mongo/util/ssl_socket.rb', line 52 def close @ssl.close end |
#closed? ⇒ Boolean
56 57 58 |
# File 'lib/mongo/util/ssl_socket.rb', line 56 def closed? @ssl.closed? end |
#connect ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/mongo/util/ssl_socket.rb', line 28 def connect if @connect_timeout Timeout::timeout(@connect_timeout, ConnectionTimeoutError) do @ssl.connect end else @ssl.connect end end |
#read(length, buffer) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/mongo/util/ssl_socket.rb', line 42 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
38 39 40 |
# File 'lib/mongo/util/ssl_socket.rb', line 38 def send(data) @ssl.syswrite(data) end |