diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-08 06:07:00 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-08 06:07:00 +0000 |
commit | 0ab2e24c5fd9b65352e54456954f6a9406c2f8df (patch) | |
tree | 245bc5d1be6c3119e8e00c804cbbe5cb9d0c11c3 /chrome_frame | |
parent | 631a595935c53d14158fd5ec2e9348a249a34957 (diff) | |
download | chromium_src-0ab2e24c5fd9b65352e54456954f6a9406c2f8df.zip chromium_src-0ab2e24c5fd9b65352e54456954f6a9406c2f8df.tar.gz chromium_src-0ab2e24c5fd9b65352e54456954f6a9406c2f8df.tar.bz2 |
net: Rework UploadDataStream API by introducing Read().
Replace buf()+buf_len()+MarkConsumedAndFillBuffer()+GetBufferSize() with
a single function Read(). This is done by externalizing the read buffer.
As a byproduct, use of memmove() in handling of SPDY HTTP requests is
significantly reduced. There, a write is done with kMaxSpdyFrameChunkSize
which is about 2.8KB, at a time, that caused MarkConsumedAndFillBuffer()
to move the remaining 13.2KB data in the internal buffer to the beginning by
memmove(), which ends up memmoving 13.2KB of data every time a chunk of 2.8KB
is written.
Along the way, UploadDataStream::IsOnLastChunk() is removed, which is
no longer necessary. Some TODO(satish)s have also been addressed.
This is in preparation for adding asynchronous API to UploadDataStream.
This is why Read() takes IOBuffer*, rather than char*.
BUG=72001
TEST=try bots
Review URL: https://chromiumcodereview.appspot.com/9317055
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@120946 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame')
-rw-r--r-- | chrome_frame/urlmon_upload_data_stream.cc | 31 |
1 files changed, 15 insertions, 16 deletions
diff --git a/chrome_frame/urlmon_upload_data_stream.cc b/chrome_frame/urlmon_upload_data_stream.cc index 3673a21..454b076 100644 --- a/chrome_frame/urlmon_upload_data_stream.cc +++ b/chrome_frame/urlmon_upload_data_stream.cc @@ -22,43 +22,42 @@ STDMETHODIMP UrlmonUploadDataStream::Read(void* pv, ULONG cb, ULONG* read) { } // Have we already read past the end of the stream? - if (request_body_stream_->eof()) { + if (request_body_stream_->IsEOF()) { if (read) { *read = 0; } return S_FALSE; } - uint64 total_bytes_to_copy = std::min(static_cast<uint64>(cb), - static_cast<uint64>(request_body_stream_->buf_len())); + // The data in request_body_stream_ can be smaller than 'cb' so it's not + // guaranteed that we'll be able to read total_bytes_to_copy bytes. + uint64 total_bytes_to_copy = cb; uint64 bytes_copied = 0; char* write_pointer = reinterpret_cast<char*>(pv); while (bytes_copied < total_bytes_to_copy) { - net::IOBuffer* buf = request_body_stream_->buf(); + size_t bytes_to_copy_now = total_bytes_to_copy - bytes_copied; - // Make sure our length doesn't run past the end of the available data. - size_t bytes_to_copy_now = static_cast<size_t>( - std::min(static_cast<uint64>(request_body_stream_->buf_len()), - total_bytes_to_copy - bytes_copied)); + scoped_refptr<net::IOBufferWithSize> buf( + new net::IOBufferWithSize(bytes_to_copy_now)); + int bytes_read = request_body_stream_->Read(buf, buf->size()); + if (bytes_read == 0) // Reached the end of the stream. + break; - memcpy(write_pointer, buf->data(), bytes_to_copy_now); + memcpy(write_pointer, buf->data(), bytes_read); // Advance our copy tally - bytes_copied += bytes_to_copy_now; + bytes_copied += bytes_read; // Advance our write pointer - write_pointer += bytes_to_copy_now; - - // Advance the UploadDataStream read pointer: - request_body_stream_->MarkConsumedAndFillBuffer(bytes_to_copy_now); + write_pointer += bytes_read; } - DCHECK(bytes_copied == total_bytes_to_copy); + DCHECK_LE(bytes_copied, total_bytes_to_copy); if (read) { - *read = static_cast<ULONG>(total_bytes_to_copy); + *read = static_cast<ULONG>(bytes_copied); } return S_OK; |