OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <functional> | 5 #include <functional> |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
9 #include "remoting/base/compound_buffer.h" | 9 #include "remoting/base/compound_buffer.h" |
10 | 10 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 locked_ = true; | 137 locked_ = true; |
138 } | 138 } |
139 | 139 |
140 net::IOBufferWithSize* CompoundBuffer::ToIOBufferWithSize() const { | 140 net::IOBufferWithSize* CompoundBuffer::ToIOBufferWithSize() const { |
141 net::IOBufferWithSize* result = new net::IOBufferWithSize(total_bytes_); | 141 net::IOBufferWithSize* result = new net::IOBufferWithSize(total_bytes_); |
142 CopyTo(result->data(), total_bytes_); | 142 CopyTo(result->data(), total_bytes_); |
143 return result; | 143 return result; |
144 } | 144 } |
145 | 145 |
146 void CompoundBuffer::CopyTo(char* data, int size) const { | 146 void CompoundBuffer::CopyTo(char* data, int size) const { |
147 char* pos = data; | 147 int pos = 0; |
148 for (DataChunkList::const_iterator it = chunks_.begin(); | 148 for (DataChunkList::const_iterator it = chunks_.begin(); |
149 it != chunks_.end(); ++it) { | 149 it != chunks_.end() && pos < size; ++it) { |
150 CHECK_LE(pos + it->size, data + size); | 150 int bytes_to_copy = std::min(size - pos, it->size); |
151 memcpy(pos, it->start, it->size); | 151 memcpy(data + pos, it->start, bytes_to_copy); |
152 pos += it->size; | 152 pos += bytes_to_copy; |
153 } | 153 } |
154 } | 154 } |
155 | 155 |
156 void CompoundBuffer::CopyFrom(const CompoundBuffer& source, | 156 void CompoundBuffer::CopyFrom(const CompoundBuffer& source, |
157 int start, int end) { | 157 int start, int end) { |
158 // Check that 0 <= |start| <= |end| <= |total_bytes_|. | 158 // Check that 0 <= |start| <= |end| <= |total_bytes_|. |
159 DCHECK_LE(0, start); | 159 DCHECK_LE(0, start); |
160 DCHECK_LE(start, end); | 160 DCHECK_LE(start, end); |
161 DCHECK_LE(end, source.total_bytes()); | 161 DCHECK_LE(end, source.total_bytes()); |
162 | 162 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 } | 268 } |
269 | 269 |
270 return count == 0; | 270 return count == 0; |
271 } | 271 } |
272 | 272 |
273 int64 CompoundBufferInputStream::ByteCount() const { | 273 int64 CompoundBufferInputStream::ByteCount() const { |
274 return position_; | 274 return position_; |
275 } | 275 } |
276 | 276 |
277 } // namespace remoting | 277 } // namespace remoting |
OLD | NEW |