Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: net/spdy/spdy_read_queue.cc

Issue 13990005: [SPDY] Replace SpdyIOBuffer with new SpdyBuffer class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "net/spdy/spdy_read_queue.h"
6
7 #include "base/logging.h"
8 #include "base/stl_util.h"
9 #include "net/spdy/spdy_buffer.h"
10
11 namespace net {
12
13 SpdyReadQueue::SpdyReadQueue() : total_size_(0) {}
14
15 SpdyReadQueue::~SpdyReadQueue() {
16 Clear();
17 }
18
19 bool SpdyReadQueue::IsEmpty() const {
20 DCHECK_EQ(queue_.empty(), total_size_ == 0);
21 return queue_.empty();
22 }
23
24 size_t SpdyReadQueue::GetTotalSize() const {
25 return total_size_;
26 }
27
28 void SpdyReadQueue::Enqueue(scoped_ptr<SpdyBuffer> buffer) {
29 DCHECK_GT(buffer->GetRemainingSize(), 0u);
30 total_size_ += buffer->GetRemainingSize();
31 queue_.push_back(buffer.release());
32 }
33
34 size_t SpdyReadQueue::Dequeue(char* out, size_t len) {
35 DCHECK_GT(len, 0u);
36 size_t bytes_copied = 0;
37 while (!queue_.empty() && bytes_copied < len) {
38 SpdyBuffer* buffer = queue_.front();
39 size_t bytes_to_copy = std::min(len, buffer->GetRemainingSize());
40 memcpy(out + bytes_copied, buffer->GetRemainingData(), bytes_to_copy);
41 bytes_copied += bytes_to_copy;
42 if (bytes_to_copy == buffer->GetRemainingSize()) {
43 delete queue_.front();
44 queue_.pop_front();
45 } else {
46 buffer->Consume(bytes_to_copy);
47 }
48 }
49 total_size_ -= bytes_copied;
50 return bytes_copied;
51 }
52
53 void SpdyReadQueue::Clear() {
54 STLDeleteElements(&queue_);
55 queue_.clear();
56 }
57
58 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698