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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | util/net/http_body_test.cc » ('j') | util/net/http_body_test.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 const CompositeHTTPBodyStream::PartsList& parts) 91 const CompositeHTTPBodyStream::PartsList& parts)
92 : HTTPBodyStream(), parts_(parts), current_part_(parts_.begin()) { 92 : HTTPBodyStream(), parts_(parts), current_part_(parts_.begin()) {
93 } 93 }
94 94
95 CompositeHTTPBodyStream::~CompositeHTTPBodyStream() { 95 CompositeHTTPBodyStream::~CompositeHTTPBodyStream() {
96 STLDeleteContainerPointers(parts_.begin(), parts_.end()); 96 STLDeleteContainerPointers(parts_.begin(), parts_.end());
97 } 97 }
98 98
99 ssize_t CompositeHTTPBodyStream::GetBytesBuffer(uint8_t* buffer, 99 ssize_t CompositeHTTPBodyStream::GetBytesBuffer(uint8_t* buffer,
100 size_t max_len) { 100 size_t max_len) {
101 if (current_part_ == parts_.end()) 101 max_len =
102 return 0; 102 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.
103 implicit_cast<size_t>(std::numeric_limits<ssize_t>::max()));
104 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.
105 while (bytes_copied < max_len && current_part_ != parts_.end()) {
106 ssize_t this_read = (*current_part_)->GetBytesBuffer(
107 buffer + bytes_copied, max_len - bytes_copied);
103 108
104 ssize_t rv = (*current_part_)->GetBytesBuffer(buffer, max_len); 109 if (this_read == 0) {
105 110 // If the current part has returned 0 indicating EOF, advance the current
106 if (rv == 0) { 111 // part and try again.
107 // If the current part has returned 0 indicating EOF, advance the current 112 ++current_part_;
108 // part and call recursively to try again. 113 } else if (this_read < 0) {
109 ++current_part_; 114 return this_read;
110 return GetBytesBuffer(buffer, max_len); 115 }
116 bytes_copied += this_read;
111 } 117 }
112 118
113 return rv; 119 return bytes_copied;
114 } 120 }
115 121
116 } // namespace crashpad 122 } // namespace crashpad
OLDNEW
« no previous file with comments | « no previous file | util/net/http_body_test.cc » ('j') | util/net/http_body_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698