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 #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 "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
10 | 10 |
11 namespace net { | 11 namespace net { |
12 | 12 |
13 // This is a simple wrapper around a buffer that provides ref counting for | 13 // This is a simple wrapper around a buffer that provides ref counting for |
14 // easier asynchronous IO handling. | 14 // easier asynchronous IO handling. |
15 class IOBuffer : public base::RefCountedThreadSafe<IOBuffer> { | 15 class IOBuffer : public base::RefCountedThreadSafe<IOBuffer> { |
16 public: | 16 public: |
17 IOBuffer() : data_(NULL) {} | 17 IOBuffer() : data_(NULL) {} |
18 explicit IOBuffer(int buffer_size) { | 18 explicit IOBuffer(int buffer_size) { |
19 DCHECK(buffer_size); | 19 DCHECK(buffer_size); |
20 data_ = new char[buffer_size]; | 20 data_ = new char[buffer_size]; |
21 } | 21 } |
22 explicit IOBuffer(char* buffer) : data_(buffer) {} | 22 explicit IOBuffer(char* data) : data_(data) {} |
23 virtual ~IOBuffer() { | 23 virtual ~IOBuffer() { |
24 delete[] data_; | 24 delete[] data_; |
25 } | 25 } |
26 | 26 |
27 char* data() { return data_; } | 27 char* data() { return data_; } |
28 | 28 |
29 protected: | 29 protected: |
30 char* data_; | 30 char* data_; |
31 }; | 31 }; |
32 | 32 |
33 // This class allows the creation of a temporary IOBuffer that doesn't really | |
34 // owns the underlying buffer. Please use this class only as a last resort. | |
darin (slow to review)
2009/02/10 04:40:27
nit: s/owns/own/
maybe you could also more clearl
| |
35 class WrappedIOBuffer : public net::IOBuffer { | |
36 public: | |
37 explicit WrappedIOBuffer(const char* data) | |
38 : net::IOBuffer(const_cast<char*>(data)) {} | |
39 ~WrappedIOBuffer() { | |
40 data_ = NULL; | |
41 } | |
42 }; | |
43 | |
33 } // namespace net | 44 } // namespace net |
34 | 45 |
35 #endif // NET_BASE_IO_BUFFER_H_ | 46 #endif // NET_BASE_IO_BUFFER_H_ |
OLD | NEW |