Class: Mongo::Socket::SSL
- Inherits:
-
Mongo::Socket
- Object
- Mongo::Socket
- Mongo::Socket::SSL
- Includes:
- OpenSSL
- Defined in:
- lib/mongo/socket/ssl.rb
Overview
Wrapper for SSL sockets.
Constant Summary
Constants inherited from Mongo::Socket
SSL_ERROR, TIMEOUT_ERROR, TIMEOUT_PACK
Instance Attribute Summary collapse
-
#context ⇒ SSLContext
readonly
Context The ssl context.
-
#host ⇒ String
readonly
Host The host to connect to.
-
#host_name ⇒ String
readonly
Host_name The original host name.
-
#options ⇒ Hash
readonly
The ssl options.
-
#port ⇒ Integer
readonly
Port The port to connect to.
-
#timeout ⇒ Float
readonly
Timeout The connection timeout.
Attributes inherited from Mongo::Socket
Instance Method Summary collapse
-
#connect! ⇒ SSL
Establishes a socket connection.
-
#connectable? ⇒ true, false
This socket can only be used if the ssl socket (@socket) has been created.
-
#initialize(host, port, host_name, timeout, family, options = {}) ⇒ SSL
constructor
Initializes a new SSL socket.
-
#readbyte ⇒ Object
Read a single byte from the socket.
Methods inherited from Mongo::Socket
#alive?, #close, #eof?, #gets, #read, #write
Constructor Details
#initialize(host, port, host_name, timeout, family, options = {}) ⇒ SSL
Initializes a new SSL socket.
79 80 81 82 83 84 85 86 |
# File 'lib/mongo/socket/ssl.rb', line 79 def initialize(host, port, host_name, timeout, family, = {}) @host, @port, @host_name, @timeout, @options = host, port, host_name, timeout, @context = create_context() @family = family @tcp_socket = ::Socket.new(family, SOCK_STREAM, 0) @tcp_socket.setsockopt(IPPROTO_TCP, TCP_NODELAY, 1) (@tcp_socket) end |
Instance Attribute Details
#context ⇒ SSLContext (readonly)
Returns context The ssl context.
27 28 29 |
# File 'lib/mongo/socket/ssl.rb', line 27 def context @context end |
#host ⇒ String (readonly)
Returns host The host to connect to.
30 31 32 |
# File 'lib/mongo/socket/ssl.rb', line 30 def host @host end |
#host_name ⇒ String (readonly)
Returns host_name The original host name.
33 34 35 |
# File 'lib/mongo/socket/ssl.rb', line 33 def host_name @host_name end |
#options ⇒ Hash (readonly)
Returns The ssl options.
36 37 38 |
# File 'lib/mongo/socket/ssl.rb', line 36 def @options end |
#port ⇒ Integer (readonly)
Returns port The port to connect to.
39 40 41 |
# File 'lib/mongo/socket/ssl.rb', line 39 def port @port end |
#timeout ⇒ Float (readonly)
Returns timeout The connection timeout.
42 43 44 |
# File 'lib/mongo/socket/ssl.rb', line 42 def timeout @timeout end |
Instance Method Details
#connect! ⇒ SSL
This method mutates the object by setting the socket internally.
Establishes a socket connection.
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/mongo/socket/ssl.rb', line 55 def connect! Timeout.timeout(timeout, Error::SocketTimeoutError) do handle_errors { @tcp_socket.connect(::Socket.pack_sockaddr_in(port, host)) } @socket = OpenSSL::SSL::SSLSocket.new(@tcp_socket, context) @socket.hostname = @host_name unless BSON::Environment.jruby? @socket.sync_close = true handle_errors { @socket.connect } verify_certificate!(@socket) self end end |
#connectable? ⇒ true, false
This socket can only be used if the ssl socket (@socket) has been created.
111 112 113 |
# File 'lib/mongo/socket/ssl.rb', line 111 def connectable? !!@socket end |
#readbyte ⇒ Object
Read a single byte from the socket.
96 97 98 99 100 101 |
# File 'lib/mongo/socket/ssl.rb', line 96 def readbyte handle_errors do byte = socket.read(1).bytes.to_a[0] byte.nil? ? raise(EOFError) : byte end end |