diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/base/io_buffer.cc | 89 | ||||
-rw-r--r-- | net/base/io_buffer.h | 59 | ||||
-rw-r--r-- | net/http/http_basic_stream.cc | 2 | ||||
-rw-r--r-- | net/http/http_basic_stream.h | 2 | ||||
-rw-r--r-- | net/http/http_stream_parser.cc | 2 | ||||
-rw-r--r-- | net/http/http_stream_parser.h | 2 | ||||
-rw-r--r-- | net/socket_stream/socket_stream.cc | 4 | ||||
-rw-r--r-- | net/socket_stream/socket_stream.h | 4 |
8 files changed, 121 insertions, 43 deletions
diff --git a/net/base/io_buffer.cc b/net/base/io_buffer.cc index 9ad0570..b922733 100644 --- a/net/base/io_buffer.cc +++ b/net/base/io_buffer.cc @@ -8,17 +8,81 @@ namespace net { +IOBuffer::IOBuffer() + : data_(NULL) { +} + IOBuffer::IOBuffer(int buffer_size) { DCHECK(buffer_size > 0); data_ = new char[buffer_size]; } +IOBuffer::IOBuffer(char* data) + : data_(data) { +} + +IOBuffer::~IOBuffer() { + delete[] data_; +} + +IOBufferWithSize::IOBufferWithSize(int size) + : IOBuffer(size), + size_(size) { +} + +StringIOBuffer::StringIOBuffer(const std::string& s) + : IOBuffer(static_cast<char*>(NULL)), + string_data_(s) { + data_ = const_cast<char*>(string_data_.data()); +} + +StringIOBuffer::~StringIOBuffer() { + // We haven't allocated the buffer, so remove it before the base class + // destructor tries to delete[] it. + data_ = NULL; +} + +DrainableIOBuffer::DrainableIOBuffer(IOBuffer* base, int size) + : IOBuffer(base->data()), + base_(base), + size_(size), + used_(0) { +} + +DrainableIOBuffer::~DrainableIOBuffer() { + // The buffer is owned by the |base_| instance. + data_ = NULL; +} + +void DrainableIOBuffer::DidConsume(int bytes) { + SetOffset(used_ + bytes); +} + +int DrainableIOBuffer::BytesRemaining() const { + return size_ - used_; +} + +// Returns the number of consumed bytes. +int DrainableIOBuffer::BytesConsumed() const { + return used_; +} + void DrainableIOBuffer::SetOffset(int bytes) { DCHECK(bytes >= 0 && bytes <= size_); used_ = bytes; data_ = base_->data() + used_; } +GrowableIOBuffer::GrowableIOBuffer() + : IOBuffer(), + capacity_(0), + offset_(0) { +} + +GrowableIOBuffer::~GrowableIOBuffer() { + data_ = NULL; +} + void GrowableIOBuffer::SetCapacity(int capacity) { DCHECK(capacity >= 0); // realloc will crash if it fails. @@ -36,4 +100,29 @@ void GrowableIOBuffer::set_offset(int offset) { data_ = real_data_.get() + offset; } +int GrowableIOBuffer::RemainingCapacity() { + return capacity_ - offset_; +} + +char* GrowableIOBuffer::StartOfBuffer() { + return real_data_.get(); +} + +PickledIOBuffer::PickledIOBuffer() : IOBuffer() {} + +PickledIOBuffer::~PickledIOBuffer() { data_ = NULL; } + +void PickledIOBuffer::Done() { + data_ = const_cast<char*>(static_cast<const char*>(pickle_.data())); +} + + +WrappedIOBuffer::WrappedIOBuffer(const char* data) + : IOBuffer(const_cast<char*>(data)) { +} + +WrappedIOBuffer::~WrappedIOBuffer() { + data_ = NULL; +} + } // namespace net diff --git a/net/base/io_buffer.h b/net/base/io_buffer.h index d908eec..cc6092a 100644 --- a/net/base/io_buffer.h +++ b/net/base/io_buffer.h @@ -17,7 +17,7 @@ namespace net { // easier asynchronous IO handling. class IOBuffer : public base::RefCountedThreadSafe<IOBuffer> { public: - IOBuffer() : data_(NULL) {} + IOBuffer(); explicit IOBuffer(int buffer_size); char* data() { return data_; } @@ -27,11 +27,9 @@ class IOBuffer : public base::RefCountedThreadSafe<IOBuffer> { // Only allow derived classes to specify data_. // In all other cases, we own data_, and must delete it at destruction time. - explicit IOBuffer(char* data) : data_(data) {} + explicit IOBuffer(char* data); - virtual ~IOBuffer() { - delete[] data_; - } + virtual ~IOBuffer(); char* data_; }; @@ -42,7 +40,7 @@ class IOBuffer : public base::RefCountedThreadSafe<IOBuffer> { // argument to IO functions. Please keep using IOBuffer* for API declarations. class IOBufferWithSize : public IOBuffer { public: - explicit IOBufferWithSize(int size) : IOBuffer(size), size_(size) {} + explicit IOBufferWithSize(int size); int size() const { return size_; } @@ -56,20 +54,12 @@ class IOBufferWithSize : public IOBuffer { // the IOBuffer interface does not provide a proper way to modify it. class StringIOBuffer : public IOBuffer { public: - explicit StringIOBuffer(const std::string& s) - : IOBuffer(static_cast<char*>(NULL)), - string_data_(s) { - data_ = const_cast<char*>(string_data_.data()); - } + explicit StringIOBuffer(const std::string& s); int size() const { return string_data_.size(); } private: - ~StringIOBuffer() { - // We haven't allocated the buffer, so remove it before the base class - // destructor tries to delete[] it. - data_ = NULL; - } + ~StringIOBuffer(); std::string string_data_; }; @@ -78,18 +68,17 @@ class StringIOBuffer : public IOBuffer { // to progressively read all the data. class DrainableIOBuffer : public IOBuffer { public: - DrainableIOBuffer(IOBuffer* base, int size) - : IOBuffer(base->data()), base_(base), size_(size), used_(0) {} + DrainableIOBuffer(IOBuffer* base, int size); // DidConsume() changes the |data_| pointer so that |data_| always points // to the first unconsumed byte. - void DidConsume(int bytes) { SetOffset(used_ + bytes); } + void DidConsume(int bytes); // Returns the number of unconsumed bytes. - int BytesRemaining() const { return size_ - used_; } + int BytesRemaining() const; // Returns the number of consumed bytes. - int BytesConsumed() const { return used_; } + int BytesConsumed() const; // Seeks to an arbitrary point in the buffer. The notion of bytes consumed // and remaining are updated appropriately. @@ -98,10 +87,7 @@ class DrainableIOBuffer : public IOBuffer { int size() const { return size_; } private: - ~DrainableIOBuffer() { - // The buffer is owned by the |base_| instance. - data_ = NULL; - } + ~DrainableIOBuffer(); scoped_refptr<IOBuffer> base_; int size_; @@ -111,7 +97,7 @@ class DrainableIOBuffer : public IOBuffer { // This version provides a resizable buffer and a changeable offset. class GrowableIOBuffer : public IOBuffer { public: - GrowableIOBuffer() : IOBuffer(), capacity_(0), offset_(0) {} + GrowableIOBuffer(); // realloc memory to the specified capacity. void SetCapacity(int capacity); @@ -121,11 +107,11 @@ class GrowableIOBuffer : public IOBuffer { void set_offset(int offset); int offset() { return offset_; } - int RemainingCapacity() { return capacity_ - offset_; } - char* StartOfBuffer() { return real_data_.get(); } + int RemainingCapacity(); + char* StartOfBuffer(); private: - ~GrowableIOBuffer() { data_ = NULL; } + ~GrowableIOBuffer(); scoped_ptr_malloc<char> real_data_; int capacity_; @@ -136,18 +122,16 @@ class GrowableIOBuffer : public IOBuffer { // operation, avoiding an extra data copy. class PickledIOBuffer : public IOBuffer { public: - PickledIOBuffer() : IOBuffer() {} + PickledIOBuffer(); Pickle* pickle() { return &pickle_; } // Signals that we are done writing to the picke and we can use it for a // write-style IO operation. - void Done() { - data_ = const_cast<char*>(static_cast<const char*>(pickle_.data())); - } + void Done(); private: - ~PickledIOBuffer() { data_ = NULL; } + ~PickledIOBuffer(); Pickle pickle_; }; @@ -159,13 +143,10 @@ class PickledIOBuffer : public IOBuffer { // of the buffer can be completely managed by its intended owner. class WrappedIOBuffer : public IOBuffer { public: - explicit WrappedIOBuffer(const char* data) - : IOBuffer(const_cast<char*>(data)) {} + explicit WrappedIOBuffer(const char* data); protected: - ~WrappedIOBuffer() { - data_ = NULL; - } + ~WrappedIOBuffer(); }; } // namespace net diff --git a/net/http/http_basic_stream.cc b/net/http/http_basic_stream.cc index 807e4ebf..8303357 100644 --- a/net/http/http_basic_stream.cc +++ b/net/http/http_basic_stream.cc @@ -21,6 +21,8 @@ int HttpBasicStream::SendRequest(const HttpRequestInfo* request, request, headers, request_body, response, callback); } +HttpBasicStream::~HttpBasicStream() {} + uint64 HttpBasicStream::GetUploadProgress() const { return parser_->GetUploadProgress(); } diff --git a/net/http/http_basic_stream.h b/net/http/http_basic_stream.h index 8a31d64..ff3bcf2 100644 --- a/net/http/http_basic_stream.h +++ b/net/http/http_basic_stream.h @@ -27,7 +27,7 @@ class UploadDataStream; class HttpBasicStream : public HttpStream { public: HttpBasicStream(ClientSocketHandle* handle, const BoundNetLog& net_log); - virtual ~HttpBasicStream() {} + virtual ~HttpBasicStream(); // HttpStream methods: virtual int SendRequest(const HttpRequestInfo* request, diff --git a/net/http/http_stream_parser.cc b/net/http/http_stream_parser.cc index bcbce58..1426957 100644 --- a/net/http/http_stream_parser.cc +++ b/net/http/http_stream_parser.cc @@ -36,6 +36,8 @@ HttpStreamParser::HttpStreamParser(ClientSocketHandle* connection, DCHECK_EQ(0, read_buffer->offset()); } +HttpStreamParser::~HttpStreamParser() {} + int HttpStreamParser::SendRequest(const HttpRequestInfo* request, const std::string& headers, UploadDataStream* request_body, diff --git a/net/http/http_stream_parser.h b/net/http/http_stream_parser.h index 724127f..44cc9e8 100644 --- a/net/http/http_stream_parser.h +++ b/net/http/http_stream_parser.h @@ -30,7 +30,7 @@ class HttpStreamParser { HttpStreamParser(ClientSocketHandle* connection, GrowableIOBuffer* read_buffer, const BoundNetLog& net_log); - ~HttpStreamParser() {} + ~HttpStreamParser(); // These functions implement the interface described in HttpStream with // some additional functionality diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc index d4ad1f9..d1ead09 100644 --- a/net/socket_stream/socket_stream.cc +++ b/net/socket_stream/socket_stream.cc @@ -35,6 +35,9 @@ static const int kReadBufferSize = 4096; namespace net { +SocketStream::ResponseHeaders::ResponseHeaders() : IOBuffer() {} +SocketStream::ResponseHeaders::~ResponseHeaders() { data_ = NULL; } + void SocketStream::ResponseHeaders::Realloc(size_t new_size) { headers_.reset(static_cast<char*>(realloc(headers_.release(), new_size))); } @@ -987,3 +990,4 @@ ProxyService* SocketStream::proxy_service() const { } } // namespace net + diff --git a/net/socket_stream/socket_stream.h b/net/socket_stream/socket_stream.h index fcedc0d..d0e8b2e 100644 --- a/net/socket_stream/socket_stream.h +++ b/net/socket_stream/socket_stream.h @@ -170,7 +170,7 @@ class SocketStream : public base::RefCountedThreadSafe<SocketStream> { class ResponseHeaders : public IOBuffer { public: - ResponseHeaders() : IOBuffer() {} + ResponseHeaders(); void SetDataOffset(size_t offset) { data_ = headers_.get() + offset; } char* headers() const { return headers_.get(); } @@ -178,7 +178,7 @@ class SocketStream : public base::RefCountedThreadSafe<SocketStream> { void Realloc(size_t new_size); private: - ~ResponseHeaders() { data_ = NULL; } + ~ResponseHeaders(); scoped_ptr_malloc<char> headers_; }; |