minor: Added TCPSocket Class w/ pool accessor

Sockets now know what pool they were checked out from
SSLSocket updated as well
This commit is contained in:
Tyler Brock 2012-03-02 19:09:02 -05:00
parent 379c831b8b
commit 93b2f3da9b
5 changed files with 11 additions and 2 deletions

View File

@ -61,6 +61,7 @@ require 'mongo/util/pool'
require 'mongo/util/pool_manager'
require 'mongo/util/server_version'
require 'mongo/util/ssl_socket'
require 'mongo/util/tcp_socket'
require 'mongo/util/uri_parser'
require 'mongo/collection'

View File

@ -537,7 +537,7 @@ module Mongo
if @ssl
@socket_class = Mongo::SSLSocket
else
@socket_class = ::TCPSocket
@socket_class = Mongo::TCPSocket
end
# Authentication objects

View File

@ -167,6 +167,7 @@ module Mongo
begin
socket = self.connection.socket_class.new(@host, @port)
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
socket.pool = self
rescue => ex
socket.close if socket
raise ConnectionFailure, "Failed to connect to host #{@host} and port #{@port}: #{ex}"

View File

@ -7,6 +7,8 @@ module Mongo
# mirroring Ruby's TCPSocket, vis., TCPSocket#send and TCPSocket#read.
class SSLSocket
attr_accessor :pool
def initialize(host, port)
@socket = ::TCPSocket.new(host, port)
@ssl = OpenSSL::SSL::SSLSocket.new(@socket)
@ -33,6 +35,5 @@ module Mongo
def close
@ssl.close
end
end
end

View File

@ -0,0 +1,6 @@
module Mongo
class TCPSocket < ::TCPSocket
attr_accessor :pool
end
end