diff options
Diffstat (limited to 'net/base/io_buffer.h')
-rw-r--r-- | net/base/io_buffer.h | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/net/base/io_buffer.h b/net/base/io_buffer.h index 39399ad..88066c2 100644 --- a/net/base/io_buffer.h +++ b/net/base/io_buffer.h @@ -19,7 +19,7 @@ class IOBuffer : public base::RefCountedThreadSafe<IOBuffer> { DCHECK(buffer_size); data_ = new char[buffer_size]; } - explicit IOBuffer(char* buffer) : data_(buffer) {} + explicit IOBuffer(char* data) : data_(data) {} virtual ~IOBuffer() { delete[] data_; } @@ -30,6 +30,20 @@ class IOBuffer : public base::RefCountedThreadSafe<IOBuffer> { char* data_; }; +// This class allows the creation of a temporary IOBuffer that doesn't really +// own the underlying buffer. Please use this class only as a last resort. +// A good example is the buffer for a synchronous operation, where we can be +// sure that nobody is keeping an extra reference to this object so the lifetime +// of the buffer can be completely managed by its intended owner. +class WrappedIOBuffer : public net::IOBuffer { + public: + explicit WrappedIOBuffer(const char* data) + : net::IOBuffer(const_cast<char*>(data)) {} + ~WrappedIOBuffer() { + data_ = NULL; + } +}; + } // namespace net #endif // NET_BASE_IO_BUFFER_H_ |