[MERGE][bug #179638] Better handling of ShortReadvError against various http servers
John Arbash Meinel
john at arbash-meinel.com
Wed Jan 2 17:34:53 GMT 2008
John Arbash Meinel has voted tweak.
Status is now: Conditionally approved
Comment:
+ # in _checked_read() below, we may have to discard several MB in
the worst
+ # case. To avoid buffering that much, we read and discard by chunks
+ # instead. The underlying file is either a socket or a StringIO, so
reading
+ # 8k chunks should be fine.
+ _discarded_buf_size = 8192
+
^- I generally prefer putting constants like this at the top of the
class definition (before __init__()) rather than in between functions.
These loops seem odd:
- data = self._file.read(size)
- data_len = len(data)
+ data_len = 0
+ while size - data_len > self._discarded_buf_size:
+ data = self._file.read(self._discarded_buf_size)
+ data_len += len(data)
+ if size - data_len > 0:
+ data = self._file.read(size - data_len)
+ data_len += len(data)
Why not do something like:
remaining = size
while remaining > 0:
next_size = min(remaining, self._discarded_buf_size)
next_data = self._file.read(next_size)
read_size = len(next_data)
remaining -= read_size
if read_size == 0:
break
if remaining > 0:
raise ShortReadv
Or you can just raise the ShortReadv from the "if read_size == 0"
portion.
For details, see:
http://bundlebuggy.aaronbentley.com/request/%3Cm2d4ski32p.fsf%40free.fr%3E
More information about the bazaar
mailing list