summaryrefslogtreecommitdiffstats
path: root/net/spdy/spdy_http_stream.cc
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-17 09:59:38 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-17 09:59:38 +0000
commit47fb09645a42f399af3e1380db0dc911a9cd1032 (patch)
treec54eb3a438f563b4d097c040d8b289dae8db3601 /net/spdy/spdy_http_stream.cc
parent3203953f3166c4a331e60a80bcc65b4201105457 (diff)
downloadchromium_src-47fb09645a42f399af3e1380db0dc911a9cd1032.zip
chromium_src-47fb09645a42f399af3e1380db0dc911a9cd1032.tar.gz
chromium_src-47fb09645a42f399af3e1380db0dc911a9cd1032.tar.bz2
[SPDY] Replace SpdyIOBuffer with new SpdyBuffer class
Use SpdyBuffer for both SPDY reads and writes. A future CL will add hooks to SpdyBuffer so that we keep track of flow control windows properly. Replace SpdyFrameProducer with SpdyBufferProducer. Also introduce new SpdyReadQueue class for delegates of SpdyStream to use. BUG=176592 Review URL: https://codereview.chromium.org/13990005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194560 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy/spdy_http_stream.cc')
-rw-r--r--net/spdy/spdy_http_stream.cc45
1 files changed, 10 insertions, 35 deletions
diff --git a/net/spdy/spdy_http_stream.cc b/net/spdy/spdy_http_stream.cc
index 4eb82bf..9053bc3 100644
--- a/net/spdy/spdy_http_stream.cc
+++ b/net/spdy/spdy_http_stream.cc
@@ -135,28 +135,11 @@ int SpdyHttpStream::ReadResponseBody(
CHECK(!callback.is_null());
// If we have data buffered, complete the IO immediately.
- if (!response_body_.empty()) {
- int bytes_read = 0;
- while (!response_body_.empty() && buf_len > 0) {
- scoped_refptr<IOBufferWithSize> data = response_body_.front();
- const int bytes_to_copy = std::min(buf_len, data->size());
- memcpy(&(buf->data()[bytes_read]), data->data(), bytes_to_copy);
- buf_len -= bytes_to_copy;
- if (bytes_to_copy == data->size()) {
- response_body_.pop_front();
- } else {
- const int bytes_remaining = data->size() - bytes_to_copy;
- IOBufferWithSize* new_buffer = new IOBufferWithSize(bytes_remaining);
- memcpy(new_buffer->data(), &(data->data()[bytes_to_copy]),
- bytes_remaining);
- response_body_.pop_front();
- response_body_.push_front(make_scoped_refptr(new_buffer));
- }
- bytes_read += bytes_to_copy;
- }
+ if (!response_body_queue_.IsEmpty()) {
+ size_t bytes_consumed = response_body_queue_.Dequeue(buf->data(), buf_len);
if (stream_)
- stream_->IncreaseRecvWindowSize(bytes_read);
- return bytes_read;
+ stream_->IncreaseRecvWindowSize(bytes_consumed);
+ return bytes_consumed;
} else if (stream_closed_) {
return closed_stream_status_;
}
@@ -434,7 +417,7 @@ void SpdyHttpStream::OnHeadersSent() {
NOTREACHED();
}
-int SpdyHttpStream::OnDataReceived(const char* data, int length) {
+int SpdyHttpStream::OnDataReceived(scoped_ptr<SpdyBuffer> buffer) {
// SpdyStream won't call us with data if the header block didn't contain a
// valid set of headers. So we don't expect to not have headers received
// here.
@@ -446,11 +429,8 @@ int SpdyHttpStream::OnDataReceived(const char* data, int length) {
// happen for server initiated streams.
DCHECK(stream_.get());
DCHECK(!stream_->closed() || stream_->pushed());
- if (length > 0) {
- // Save the received data.
- IOBufferWithSize* io_buffer = new IOBufferWithSize(length);
- memcpy(io_buffer->data(), data, length);
- response_body_.push_back(make_scoped_refptr(io_buffer));
+ if (buffer) {
+ response_body_queue_.Enqueue(buffer.Pass());
if (user_buffer_) {
// Handing small chunks of data to the caller creates measurable overhead.
@@ -509,14 +489,9 @@ bool SpdyHttpStream::ShouldWaitForMoreBufferedData() const {
if (stream_closed_)
return false;
- int bytes_buffered = 0;
- std::list<scoped_refptr<IOBufferWithSize> >::const_iterator it;
- for (it = response_body_.begin();
- it != response_body_.end() && bytes_buffered < user_buffer_len_;
- ++it)
- bytes_buffered += (*it)->size();
-
- return bytes_buffered < user_buffer_len_;
+ DCHECK_GT(user_buffer_len_, 0);
+ return response_body_queue_.GetTotalSize() <
+ static_cast<size_t>(user_buffer_len_);
}
bool SpdyHttpStream::DoBufferedReadCallback() {