OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef NET_BASE_IO_BUFFER_H_ | 5 #ifndef NET_BASE_IO_BUFFER_H_ |
6 #define NET_BASE_IO_BUFFER_H_ | 6 #define NET_BASE_IO_BUFFER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 explicit StringIOBuffer(const std::string& s); | 116 explicit StringIOBuffer(const std::string& s); |
117 | 117 |
118 int size() const { return static_cast<int>(string_data_.size()); } | 118 int size() const { return static_cast<int>(string_data_.size()); } |
119 | 119 |
120 private: | 120 private: |
121 virtual ~StringIOBuffer(); | 121 virtual ~StringIOBuffer(); |
122 | 122 |
123 std::string string_data_; | 123 std::string string_data_; |
124 }; | 124 }; |
125 | 125 |
126 // This version allows a string to be used as the storage for a write-style | |
127 // operation, avoiding an extra data copy. The string passed to the constructor | |
128 // is std::string::swap'd with an interal string. | |
129 class NET_EXPORT ZeroCopyStringIOBuffer : public IOBuffer { | |
gavinp
2014/08/14 22:02:45
Firstly, this is really cool. Well thought out and
jkarlin
2014/08/15 00:13:34
Great suggestion. Done.
| |
130 public: | |
131 // The input |s| is swapped with string_. | |
132 ZeroCopyStringIOBuffer(std::string* s); | |
133 | |
134 std::string* string() { return &string_; } | |
135 | |
136 private: | |
137 virtual ~ZeroCopyStringIOBuffer(); | |
138 | |
139 std::string string_; | |
140 }; | |
141 | |
126 // This version wraps an existing IOBuffer and provides convenient functions | 142 // This version wraps an existing IOBuffer and provides convenient functions |
127 // to progressively read all the data. | 143 // to progressively read all the data. |
128 // | 144 // |
129 // DrainableIOBuffer is useful when you have an IOBuffer that contains data | 145 // DrainableIOBuffer is useful when you have an IOBuffer that contains data |
130 // to be written progressively, and Write() function takes an IOBuffer rather | 146 // to be written progressively, and Write() function takes an IOBuffer rather |
131 // than char*. DrainableIOBuffer can be used as follows: | 147 // than char*. DrainableIOBuffer can be used as follows: |
132 // | 148 // |
133 // // payload is the IOBuffer containing the data to be written. | 149 // // payload is the IOBuffer containing the data to be written. |
134 // buf = new DrainableIOBuffer(payload, payload_size); | 150 // buf = new DrainableIOBuffer(payload, payload_size); |
135 // | 151 // |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 public: | 251 public: |
236 explicit WrappedIOBuffer(const char* data); | 252 explicit WrappedIOBuffer(const char* data); |
237 | 253 |
238 protected: | 254 protected: |
239 virtual ~WrappedIOBuffer(); | 255 virtual ~WrappedIOBuffer(); |
240 }; | 256 }; |
241 | 257 |
242 } // namespace net | 258 } // namespace net |
243 | 259 |
244 #endif // NET_BASE_IO_BUFFER_H_ | 260 #endif // NET_BASE_IO_BUFFER_H_ |
OLD | NEW |