RUBY-236 Create timeout block only when timeout is set
This commit is contained in:
parent
025e56732e
commit
f3174550b7
|
@ -837,18 +837,12 @@ module Mongo
|
||||||
# Requires length and an available socket.
|
# Requires length and an available socket.
|
||||||
def receive_message_on_socket(length, socket)
|
def receive_message_on_socket(length, socket)
|
||||||
begin
|
begin
|
||||||
message = new_binary_string
|
if @op_timeout
|
||||||
Mongo::TimeoutHandler.timeout(@op_timeout, OperationTimeout) do
|
Mongo::TimeoutHandler.timeout(@op_timeout, OperationTimeout) do
|
||||||
socket.read(length, message)
|
message = receive_data(length, socket)
|
||||||
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
|
end
|
||||||
|
else
|
||||||
|
message = receive_data(length, socket)
|
||||||
end
|
end
|
||||||
rescue => ex
|
rescue => ex
|
||||||
close
|
close
|
||||||
|
@ -862,6 +856,21 @@ module Mongo
|
||||||
message
|
message
|
||||||
end
|
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)
|
if defined?(Encoding)
|
||||||
BINARY_ENCODING = Encoding.find("binary")
|
BINARY_ENCODING = Encoding.find("binary")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue