| OLD | NEW |
| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 CompositeHTTPBodyStream::CompositeHTTPBodyStream( | 90 CompositeHTTPBodyStream::CompositeHTTPBodyStream( |
| 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 buffer_len) { |
| 101 if (current_part_ == parts_.end()) | 101 ssize_t max_len = std::min( |
| 102 return 0; | 102 buffer_len, implicit_cast<size_t>(std::numeric_limits<ssize_t>::max())); |
| 103 ssize_t bytes_copied = 0; |
| 104 while (bytes_copied < max_len && current_part_ != parts_.end()) { |
| 105 ssize_t this_read = (*current_part_)->GetBytesBuffer( |
| 106 buffer + bytes_copied, max_len - bytes_copied); |
| 103 | 107 |
| 104 ssize_t rv = (*current_part_)->GetBytesBuffer(buffer, max_len); | 108 if (this_read == 0) { |
| 105 | 109 // If the current part has returned 0 indicating EOF, advance the current |
| 106 if (rv == 0) { | 110 // part and try again. |
| 107 // If the current part has returned 0 indicating EOF, advance the current | 111 ++current_part_; |
| 108 // part and call recursively to try again. | 112 } else if (this_read < 0) { |
| 109 ++current_part_; | 113 return this_read; |
| 110 return GetBytesBuffer(buffer, max_len); | 114 } |
| 115 bytes_copied += this_read; |
| 111 } | 116 } |
| 112 | 117 |
| 113 return rv; | 118 return bytes_copied; |
| 114 } | 119 } |
| 115 | 120 |
| 116 } // namespace crashpad | 121 } // namespace crashpad |
| OLD | NEW |