OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 DCHECK_LE(bytes, size_); | 76 DCHECK_LE(bytes, size_); |
77 used_ = bytes; | 77 used_ = bytes; |
78 data_ = base_->data() + used_; | 78 data_ = base_->data() + used_; |
79 } | 79 } |
80 | 80 |
81 DrainableIOBuffer::~DrainableIOBuffer() { | 81 DrainableIOBuffer::~DrainableIOBuffer() { |
82 // The buffer is owned by the |base_| instance. | 82 // The buffer is owned by the |base_| instance. |
83 data_ = NULL; | 83 data_ = NULL; |
84 } | 84 } |
85 | 85 |
| 86 SeekableIOBuffer::SeekableIOBuffer(int size) |
| 87 : IOBuffer(size), |
| 88 begin_(data_), |
| 89 capacity_(size), |
| 90 size_(0), |
| 91 used_(0) { |
| 92 } |
| 93 |
| 94 void SeekableIOBuffer::DidConsume(int bytes) { |
| 95 SetOffset(used_ + bytes); |
| 96 } |
| 97 |
| 98 int SeekableIOBuffer::BytesRemaining() const { |
| 99 return size_ - used_; |
| 100 } |
| 101 |
| 102 int SeekableIOBuffer::BytesConsumed() const { |
| 103 return used_; |
| 104 } |
| 105 |
| 106 void SeekableIOBuffer::SetOffset(int bytes) { |
| 107 DCHECK_GE(bytes, 0); |
| 108 DCHECK_LE(bytes, size_); |
| 109 used_ = bytes; |
| 110 data_ = begin_ + used_; |
| 111 } |
| 112 |
| 113 void SeekableIOBuffer::DidAppend(int bytes) { |
| 114 DCHECK_GE(size_ + bytes, 0); |
| 115 DCHECK_LE(size_ + bytes, capacity_); |
| 116 size_ += bytes; |
| 117 } |
| 118 |
| 119 void SeekableIOBuffer::Clear() { |
| 120 size_ = 0; |
| 121 SetOffset(0); |
| 122 } |
| 123 |
| 124 SeekableIOBuffer::~SeekableIOBuffer() { |
| 125 // data_ will be deleted in IOBuffer::~IOBuffer(). |
| 126 data_ = begin_; |
| 127 } |
| 128 |
86 GrowableIOBuffer::GrowableIOBuffer() | 129 GrowableIOBuffer::GrowableIOBuffer() |
87 : IOBuffer(), | 130 : IOBuffer(), |
88 capacity_(0), | 131 capacity_(0), |
89 offset_(0) { | 132 offset_(0) { |
90 } | 133 } |
91 | 134 |
92 void GrowableIOBuffer::SetCapacity(int capacity) { | 135 void GrowableIOBuffer::SetCapacity(int capacity) { |
93 DCHECK_GE(capacity, 0); | 136 DCHECK_GE(capacity, 0); |
94 // realloc will crash if it fails. | 137 // realloc will crash if it fails. |
95 real_data_.reset(static_cast<char*>(realloc(real_data_.release(), capacity))); | 138 real_data_.reset(static_cast<char*>(realloc(real_data_.release(), capacity))); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 172 |
130 WrappedIOBuffer::WrappedIOBuffer(const char* data) | 173 WrappedIOBuffer::WrappedIOBuffer(const char* data) |
131 : IOBuffer(const_cast<char*>(data)) { | 174 : IOBuffer(const_cast<char*>(data)) { |
132 } | 175 } |
133 | 176 |
134 WrappedIOBuffer::~WrappedIOBuffer() { | 177 WrappedIOBuffer::~WrappedIOBuffer() { |
135 data_ = NULL; | 178 data_ = NULL; |
136 } | 179 } |
137 | 180 |
138 } // namespace net | 181 } // namespace net |
OLD | NEW |