[MERGE][bug #179638] Better handling of ShortReadvError against various http servers

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Jan 3 16:25:54 GMT 2008


>>>>> "john" == John Arbash Meinel <john at arbash-meinel.com> writes:

    john> John Arbash Meinel has voted tweak.
    john> Status is now: Conditionally approved
    john> Comment:
    john> +    # in _checked_read() below, we may have to discard several
    john> MB in the worst
    john> +    # case. To avoid buffering that much, we read and discard by chunks
    john> +    # instead. The underlying file is either a socket or a
    john> StringIO, so reading
    john> +    # 8k chunks should be fine.
    john> +    _discarded_buf_size = 8192
    john> +

    john> ^- I generally prefer putting constants like this at the top of
    john> the class definition (before __init__()) rather than in between
    john> functions.

Ok.

    john> These loops seem odd:
    john> -        data = self._file.read(size)
    john> -        data_len = len(data)
    john> +        data_len = 0
    john> +        while size - data_len > self._discarded_buf_size:
    john> +            data = self._file.read(self._discarded_buf_size)
    john> +            data_len += len(data)
    john> +        if size - data_len > 0:
    john> +            data = self._file.read(size - data_len)
    john> +            data_len += len(data)

    john> Why not do something like:

Doh. What was I thinking ? Thanks ;-)

     Vincent



More information about the bazaar mailing list