OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "net/base/io_buffer.h" | 5 #include "net/base/io_buffer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 | 8 |
9 namespace net { | 9 namespace net { |
10 | 10 |
11 IOBuffer::IOBuffer(int buffer_size) { | 11 IOBuffer::IOBuffer(int buffer_size) { |
12 DCHECK(buffer_size > 0); | 12 DCHECK(buffer_size > 0); |
13 data_ = new char[buffer_size]; | 13 data_ = new char[buffer_size]; |
14 } | 14 } |
15 | 15 |
16 void DrainableIOBuffer::SetOffset(int bytes) { | 16 void DrainableIOBuffer::SetOffset(int bytes) { |
17 DCHECK(bytes >= 0 && bytes <= size_); | 17 DCHECK(bytes >= 0 && bytes <= size_); |
18 used_ = bytes; | 18 used_ = bytes; |
19 data_ = base_->data() + used_; | 19 data_ = base_->data() + used_; |
20 } | 20 } |
21 | 21 |
22 void GrowableIOBuffer::set_capacity(int capacity) { | 22 bool GrowableIOBuffer::SetCapacity(int capacity) { |
23 DCHECK_GE(capacity, 0); | 23 DCHECK_GE(capacity, 0); |
wtc
2009/11/09 22:37:23
Let's change this DCHECK to a CHECK.
| |
24 real_data_.reset(static_cast<char*>(realloc(real_data_.release(), capacity))); | 24 char* cur_buf = real_data_.release(); |
25 real_data_.reset(static_cast<char*>(realloc(cur_buf, capacity))); | |
26 if (real_data_.get() == NULL && capacity != 0) { | |
27 real_data_.reset(cur_buf); | |
28 return false; | |
29 } | |
25 capacity_ = capacity; | 30 capacity_ = capacity; |
26 CHECK(real_data_.get() != NULL || capacity == 0); | 31 CHECK(real_data_.get() != NULL || capacity == 0); |
wtc
2009/10/27 22:42:10
You can remove this CHECK now because its expressi
| |
27 if (offset_ > capacity) | 32 if (offset_ > capacity) |
28 set_offset(capacity); | 33 set_offset(capacity); |
29 else | 34 else |
30 set_offset(offset_); // The pointer may have changed. | 35 set_offset(offset_); // The pointer may have changed. |
36 return true; | |
31 } | 37 } |
32 | 38 |
33 void GrowableIOBuffer::set_offset(int offset) { | 39 void GrowableIOBuffer::set_offset(int offset) { |
34 DCHECK(offset >= 0 && offset <= capacity_); | 40 DCHECK(offset >= 0 && offset <= capacity_); |
35 offset_ = offset; | 41 offset_ = offset; |
36 data_ = real_data_.get() + offset; | 42 data_ = real_data_.get() + offset; |
37 } | 43 } |
38 | 44 |
39 } // namespace net | 45 } // namespace net |
OLD | NEW |