Skip to content

Commit

Permalink
Update lib/mongo/socket.rb
Browse files Browse the repository at this point in the history
Co-authored-by: Jamis Buck <jamisbuck@gmail.com>
  • Loading branch information
comandeo-mongo and jamis authored Mar 5, 2024
1 parent e87d5ae commit 2c2ec6c
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions lib/mongo/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,26 +273,19 @@ def connectable?
def read_with_timeout(length, timeout)
deadline = Utils.monotonic_time + timeout
map_exceptions do
socket_timeout = deadline - Utils.monotonic_time
if socket_timeout <= 0
raise Mongo::Error::TimeoutError
end
data = read_from_socket(length, socket_timeout: socket_timeout, csot: true)
unless (data.length > 0 || length == 0)
raise IOError, "Expected to read > 0 bytes but read 0 bytes"
end
while data.length < length
socket_timeout = deadline - Utils.monotonic_time
if socket_timeout <= 0
raise Mongo::Error::TimeoutError
end
chunk = read_from_socket(length - data.length, socket_timeout: socket_timeout, csot: true)
unless (chunk.length > 0 || length == 0)
raise IOError, "Expected to read > 0 bytes but read 0 bytes"
"".tap do |data|
while data.length < length
socket_timeout = deadline - Utils.monotonic_time
if socket_timeout <= 0
raise Mongo::Error::TimeoutError
end
chunk = read_from_socket(length - data.length, socket_timeout: socket_timeout, csot: true)
unless chunk.length > 0
raise IOError, "Expected to read > 0 bytes but read 0 bytes"
end
data << chunk
end
data << chunk
end
data
end
end

Expand Down

0 comments on commit 2c2ec6c

Please sign in to comment.