Skip to content

Commit

Permalink
minor: Added TCPSocket Class w/ pool accessor
Browse files Browse the repository at this point in the history
Sockets now know what pool they were checked out from
SSLSocket updated as well
  • Loading branch information
TylerBrock committed Mar 3, 2012
1 parent 379c831 commit 93b2f3d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/mongo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ module Constants
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'
Expand Down
2 changes: 1 addition & 1 deletion lib/mongo/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def setup(opts)
if @ssl
@socket_class = Mongo::SSLSocket
else
@socket_class = ::TCPSocket
@socket_class = Mongo::TCPSocket
end

# Authentication objects
Expand Down
1 change: 1 addition & 0 deletions lib/mongo/util/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def checkout_new_socket
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}"
Expand Down
3 changes: 2 additions & 1 deletion lib/mongo/util/ssl_socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -33,6 +35,5 @@ def read(length, buffer)
def close
@ssl.close
end

end
end
6 changes: 6 additions & 0 deletions lib/mongo/util/tcp_socket.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module Mongo
class TCPSocket < ::TCPSocket
attr_accessor :pool

end
end

0 comments on commit 93b2f3d

Please sign in to comment.