class Mongo::SSLSocket

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., Mongo::TCPSocket#send and Mongo::TCPSocket#read.

Attributes

pool[RW]

Public Class Methods

new(host, port, op_timeout=nil, connect_timeout=nil) click to toggle source
# 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

Public Instance Methods

close() click to toggle source
# File lib/mongo/util/ssl_socket.rb, line 55
def close
  @ssl.close
end
closed?() click to toggle source
# File lib/mongo/util/ssl_socket.rb, line 59
def closed?
  @ssl.closed?
end
connect() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/mongo/util/ssl_socket.rb, line 37
def send(data)
  @ssl.syswrite(data)
end
setsockopt(key, value, n) click to toggle source
# File lib/mongo/util/ssl_socket.rb, line 51
def setsockopt(key, value, n)
  @ssl.setsockopt(key, value, n)
end