diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-31 09:08:45 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-31 09:08:45 +0000 |
commit | 81ee3f12bb5c7afb64ccfce388ff4377868c5c0a (patch) | |
tree | 9eccf9dbf027ecbb2982d74704382f67b8f0bcc1 /net | |
parent | 56b0d069daf3ecd5b0ee68a252b5a5804a45bafa (diff) | |
download | chromium_src-81ee3f12bb5c7afb64ccfce388ff4377868c5c0a.zip chromium_src-81ee3f12bb5c7afb64ccfce388ff4377868c5c0a.tar.gz chromium_src-81ee3f12bb5c7afb64ccfce388ff4377868c5c0a.tar.bz2 |
net: Replace use of memmove() with DrainableIOBuffer.
This is yet another cleanup patch for HttpStreamParser.
BUG=72001
TEST=net_unittests
Review URL: http://codereview.chromium.org/9289004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119870 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/http/http_stream_parser.cc | 34 | ||||
-rw-r--r-- | net/http/http_stream_parser.h | 9 |
2 files changed, 23 insertions, 20 deletions
diff --git a/net/http/http_stream_parser.cc b/net/http/http_stream_parser.cc index be1c828..b85a342 100644 --- a/net/http/http_stream_parser.cc +++ b/net/http/http_stream_parser.cc @@ -87,9 +87,6 @@ HttpStreamParser::HttpStreamParser(ClientSocketHandle* connection, io_callback_( base::Bind(&HttpStreamParser::OnIOComplete, base::Unretained(this)))), - chunk_buffer_size_(UploadDataStream::GetBufferSize() + - kChunkHeaderFooterSize), - chunk_length_(0), chunk_length_without_encoding_(0), sent_last_chunk_(false) { } @@ -131,7 +128,10 @@ int HttpStreamParser::SendRequest(const std::string& request_line, request_body_.reset(request_body); if (request_body_ != NULL && request_body_->is_chunked()) { request_body_->set_chunk_callback(this); - chunk_buf_ = new IOBuffer(chunk_buffer_size_); + // The raw chunk buffer is guaranteed to be large enough to hold the + // encoded chunk. + raw_chunk_buf_ = new IOBufferWithSize(UploadDataStream::GetBufferSize() + + kChunkHeaderFooterSize); } io_state_ = STATE_SENDING_HEADERS; @@ -348,12 +348,14 @@ int HttpStreamParser::DoSendChunkedBody(int result) { // |result| is the number of bytes sent from the last call to // DoSendChunkedBody(), or 0 (i.e. OK) the first time. - chunk_length_ -= result; - if (chunk_length_) { - // Move the remaining data in the chunk buffer to the beginning. - memmove(chunk_buf_->data(), chunk_buf_->data() + result, chunk_length_); - return connection_->socket()->Write(chunk_buf_, chunk_length_, - io_callback_); + // Send the remaining data in the chunk buffer. + if (chunk_buf_.get()) { + chunk_buf_->DidConsume(result); + if (chunk_buf_->BytesRemaining() > 0) { + return connection_->socket()->Write(chunk_buf_, + chunk_buf_->BytesRemaining(), + io_callback_); + } } if (sent_last_chunk_) { @@ -367,22 +369,24 @@ int HttpStreamParser::DoSendChunkedBody(int result) { chunk_length_without_encoding_ = 0; if (request_body_->eof()) { - chunk_length_ = EncodeChunk( - base::StringPiece(), chunk_buf_->data(), chunk_buffer_size_); + const int chunk_length = EncodeChunk( + base::StringPiece(), raw_chunk_buf_->data(), raw_chunk_buf_->size()); + chunk_buf_ = new DrainableIOBuffer(raw_chunk_buf_, chunk_length); sent_last_chunk_ = true; } else if (request_body_->buf_len() > 0) { // Encode and send the buffer as 1 chunk. const base::StringPiece payload(request_body_->buf()->data(), request_body_->buf_len()); - chunk_length_ = EncodeChunk(payload, chunk_buf_->data(), - chunk_buffer_size_); + const int chunk_length = EncodeChunk( + payload, raw_chunk_buf_->data(), raw_chunk_buf_->size()); + chunk_buf_ = new DrainableIOBuffer(raw_chunk_buf_, chunk_length); chunk_length_without_encoding_ = payload.size(); } else { // Nothing to send. More POST data is yet to come? return ERR_IO_PENDING; } - return connection_->socket()->Write(chunk_buf_, chunk_length_, + return connection_->socket()->Write(chunk_buf_, chunk_buf_->BytesRemaining(), io_callback_); } diff --git a/net/http/http_stream_parser.h b/net/http/http_stream_parser.h index 303bc10..861fbe9 100644 --- a/net/http/http_stream_parser.h +++ b/net/http/http_stream_parser.h @@ -25,6 +25,7 @@ struct HttpRequestInfo; class HttpRequestHeaders; class HttpResponseInfo; class IOBuffer; +class IOBufferWithSize; class SSLCertRequestInfo; class SSLInfo; @@ -222,11 +223,9 @@ class NET_EXPORT_PRIVATE HttpStreamParser : public ChunkCallback { // Stores an encoded chunk for chunked uploads. // Note: This should perhaps be improved to not create copies of the data. - scoped_refptr<IOBuffer> chunk_buf_; - // The size of the chunk buffer (chunk_buf_). The chunk buffer is - // guaranteed to be large enough to hold the encoded chunk. - const size_t chunk_buffer_size_; - size_t chunk_length_; + scoped_refptr<IOBufferWithSize> raw_chunk_buf_; + // Wraps raw_chunk_buf_ to read the remaining data progressively. + scoped_refptr<DrainableIOBuffer> chunk_buf_; size_t chunk_length_without_encoding_; bool sent_last_chunk_; |