io read: making sure that the read buffer is flushed when one can't read from the io, as we'll need this information later

This commit is contained in:
HoneyryderChuck 2020-04-18 17:42:22 +01:00
parent 203cdb1b8e
commit e7181132ab
2 changed files with 7 additions and 2 deletions

View File

@ -74,9 +74,10 @@ module HTTPX
# :nocov:
if RUBY_VERSION < "2.3"
def read(*)
def read(_, buffer)
super
rescue ::IO::WaitWritable
buffer.clear
0
end

View File

@ -88,6 +88,7 @@ module HTTPX
@io.read_nonblock(size, buffer)
buffer.bytesize
rescue ::IO::WaitReadable
buffer.clear
0
rescue EOFError
nil
@ -106,7 +107,10 @@ module HTTPX
else
def read(size, buffer)
ret = @io.read_nonblock(size, buffer, exception: false)
return 0 if ret == :wait_readable
if ret == :wait_readable
buffer.clear
return 0
end
return if ret.nil?
buffer.bytesize