RUBY-236 Create timeout block only when timeout is set

This commit is contained in:
Kyle Banker 2011-03-29 11:06:46 -04:00
parent 025e56732e
commit f3174550b7

View File

@ -837,20 +837,14 @@ module Mongo
# Requires length and an available socket.
def receive_message_on_socket(length, socket)
begin
message = new_binary_string
Mongo::TimeoutHandler.timeout(@op_timeout, OperationTimeout) do
socket.read(length, message)
raise ConnectionFailure, "connection closed" unless message && message.length > 0
if message.length < length
chunk = new_binary_string
while message.length < length
socket.read(length - message.length, chunk)
raise ConnectionFailure, "connection closed" unless chunk.length > 0
message << chunk
end
if @op_timeout
Mongo::TimeoutHandler.timeout(@op_timeout, OperationTimeout) do
message = receive_data(length, socket)
end
else
message = receive_data(length, socket)
end
rescue => ex
rescue => ex
close
if ex.class == OperationTimeout
@ -862,6 +856,21 @@ module Mongo
message
end
def receive_data(length, socket)
message = new_binary_string
socket.read(length, message)
raise ConnectionFailure, "connection closed" unless message && message.length > 0
if message.length < length
chunk = new_binary_string
while message.length < length
socket.read(length - message.length, chunk)
raise ConnectionFailure, "connection closed" unless chunk.length > 0
message << chunk
end
end
message
end
if defined?(Encoding)
BINARY_ENCODING = Encoding.find("binary")