Sha256: d40d58310428c18a36a6d695436f5510bcffa6386ad32494129ed3ef9cbfaf2b
Contents?: true
Size: 1.23 KB
Versions: 47
Compression:
Stored size: 1.23 KB
Contents
require 'socket' require 'openssl' require 'timeout' module Mongo # 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. class SSLSocket attr_accessor :pool def initialize(host, port, op_timeout=nil, connect_timeout=nil) @op_timeout = op_timeout @connect_timeout = connect_timeout @socket = ::TCPSocket.new(host, port) @ssl = OpenSSL::SSL::SSLSocket.new(@socket) @ssl.sync_close = true connect end def connect if @connect_timeout Timeout::timeout(@connect_timeout, ConnectionTimeoutError) do @ssl.connect end else @ssl.connect end end def send(data) @ssl.syswrite(data) end 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 def setsockopt(key, value, n) @ssl.setsockopt(key, value, n) end def close @ssl.close end def closed? @ssl.closed? end end end
Version data entries
47 entries across 47 versions & 2 rubygems