Chromium Code Reviews| Index: util/net/http_body.cc |
| diff --git a/util/net/http_body.cc b/util/net/http_body.cc |
| index cd31ab4fa568f45dc6e1c41db087393367ebd3d5..efef5d89fa5d649767ad137a686eba19b4a08207 100644 |
| --- a/util/net/http_body.cc |
| +++ b/util/net/http_body.cc |
| @@ -98,19 +98,25 @@ CompositeHTTPBodyStream::~CompositeHTTPBodyStream() { |
| ssize_t CompositeHTTPBodyStream::GetBytesBuffer(uint8_t* buffer, |
| size_t max_len) { |
| - if (current_part_ == parts_.end()) |
| - return 0; |
| - |
| - ssize_t rv = (*current_part_)->GetBytesBuffer(buffer, max_len); |
| - |
| - if (rv == 0) { |
| - // If the current part has returned 0 indicating EOF, advance the current |
| - // part and call recursively to try again. |
| - ++current_part_; |
| - return GetBytesBuffer(buffer, max_len); |
| + max_len = |
| + std::min(max_len, |
|
Mark Mentovai
2014/11/07 17:00:11
Maybe more readable if std::min( went on the first
Robert Sesek
2014/11/07 17:05:33
Done.
|
| + implicit_cast<size_t>(std::numeric_limits<ssize_t>::max())); |
| + size_t bytes_copied = 0; |
|
Mark Mentovai
2014/11/07 17:00:11
I think this should be ssize_t because that’s what
Robert Sesek
2014/11/07 17:05:33
Done.
|
| + while (bytes_copied < max_len && current_part_ != parts_.end()) { |
| + ssize_t this_read = (*current_part_)->GetBytesBuffer( |
| + buffer + bytes_copied, max_len - bytes_copied); |
| + |
| + if (this_read == 0) { |
| + // If the current part has returned 0 indicating EOF, advance the current |
| + // part and try again. |
| + ++current_part_; |
| + } else if (this_read < 0) { |
| + return this_read; |
| + } |
| + bytes_copied += this_read; |
| } |
| - return rv; |
| + return bytes_copied; |
| } |
| } // namespace crashpad |