minor: refactor TCP_NODELAY

This commit is contained in:
Tyler Brock 2012-04-08 10:48:25 -04:00
parent 95a831c0b3
commit 00cea59c10
5 changed files with 7 additions and 10 deletions

View File

@ -622,9 +622,7 @@ module Mongo
socket = nil
config = nil
socket = @socket_class.new(host, port, @op_timeout, @connect_timeout)
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
socket = @socket_class.new(host, port, @op_timeout, @connect_timeout)
config = self['admin'].command({:ismaster => 1}, :socket => socket)
rescue OperationFailure, SocketError, SystemCallError, IOError
close

View File

@ -40,11 +40,7 @@ module Mongo
@connection.op_timeout, @connection.connect_timeout
)
if socket.nil?
return nil
else
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
end
return nil if socket.nil?
rescue OperationTimeout, ConnectionFailure, OperationFailure, SocketError, SystemCallError, IOError => ex
@connection.log(:debug, "Failed connection to #{host_string} with #{ex.class}, #{ex.message}.")
socket.close if socket

View File

@ -157,7 +157,6 @@ module Mongo
def checkout_new_socket
begin
socket = @connection.socket_class.new(@host, @port, @connection.op_timeout)
socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
socket.pool = self
rescue => ex
socket.close if socket

View File

@ -15,7 +15,9 @@ module Mongo
@op_timeout = op_timeout
@connect_timeout = connect_timeout
@socket = ::TCPSocket.new(host, port)
@socket = ::TCPSocket.new(host, port)
@socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
@ssl = OpenSSL::SSL::SSLSocket.new(@socket)
@ssl.sync_close = true

View File

@ -16,8 +16,10 @@ module Mongo
# TODO: Prefer ipv6 if server is ipv6 enabled
@host = Socket.getaddrinfo(host, nil, Socket::AF_INET).first[3]
@port = port
@socket_address = Socket.pack_sockaddr_in(@port, @host)
@socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
@socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
connect
end