Sha256: 0fe09cda0c11391a2608680d0efef4332e85756271f1b8028504db5a05b6c043

Contents?: true

Size: 831 Bytes

Versions: 6

Compression:

Stored size: 831 Bytes

Contents

require 'openssl'

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

    def initialize(host, port)
      @socket = ::TCPSocket.new(host, port)
      @ssl = OpenSSL::SSL::SSLSocket.new(@socket)
      @ssl.sync_close = true
      @ssl.connect
    end

    def setsockopt(key, value, n)
      @socket.setsockopt(key, value, n)
    end

    # Write to the SSL socket.
    #
    # @param buffer a buffer to send.
    # @param flags socket flags. Because Ruby's SSL
    def send(buffer, flags=0)
      @ssl.syswrite(buffer)
    end

    def read(length, buffer)
      @ssl.sysread(length, buffer)
    end

    def close
      @ssl.close
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mongo-1.6.0 lib/mongo/util/ssl_socket.rb
mongo-1.5.2 lib/mongo/util/ssl_socket.rb
mongo-1.5.1 lib/mongo/util/ssl_socket.rb
mongo-1.5.0 lib/mongo/util/ssl_socket.rb
mongo-1.5.0.rc0 lib/mongo/util/ssl_socket.rb
mongo-1.4.0 lib/mongo/util/ssl_socket.rb