Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2620)

Unified Diff: util/net/http_body.cc

Issue 707223002: In CompositeHTTPBodyStream, coalesce small GetBytesBuffer()s to better fill the buffer. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | util/net/http_body_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/net/http_body.cc
diff --git a/util/net/http_body.cc b/util/net/http_body.cc
index cd31ab4fa568f45dc6e1c41db087393367ebd3d5..0e5daa34259a57816c91e5d60b9a4eeb4b7d3d9f 100644
--- a/util/net/http_body.cc
+++ b/util/net/http_body.cc
@@ -97,20 +97,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);
+ size_t buffer_len) {
+ ssize_t max_len = std::min(
+ buffer_len, implicit_cast<size_t>(std::numeric_limits<ssize_t>::max()));
+ ssize_t bytes_copied = 0;
+ 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
« no previous file with comments | « no previous file | util/net/http_body_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698