1 // Copyright 2013 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_SPDY_SPDY_READ_QUEUE_H_ 6 #define NET_SPDY_SPDY_READ_QUEUE_H_ 7 8 #include <cstddef> 9 #include <memory> 10 11 #include "base/containers/circular_deque.h" 12 #include "net/base/net_export.h" 13 14 namespace net { 15 16 class SpdyBuffer; 17 18 // A FIFO queue of incoming data from a SPDY connection. Useful for 19 // SpdyStream delegates. 20 class NET_EXPORT_PRIVATE SpdyReadQueue { 21 public: 22 SpdyReadQueue(); 23 24 SpdyReadQueue(const SpdyReadQueue&) = delete; 25 SpdyReadQueue& operator=(const SpdyReadQueue&) = delete; 26 27 ~SpdyReadQueue(); 28 29 // Returns whether there's anything in the queue. 30 bool IsEmpty() const; 31 32 // Returns the total number of bytes in the queue. 33 size_t GetTotalSize() const; 34 35 // Enqueues the bytes in |buffer|. 36 void Enqueue(std::unique_ptr<SpdyBuffer> buffer); 37 38 // Dequeues up to |len| (which must be positive) bytes into 39 // |out|. Returns the number of bytes dequeued. 40 size_t Dequeue(char* out, size_t len); 41 42 // Removes all bytes from the queue. 43 void Clear(); 44 45 private: 46 // Class invariant: 47 // |total_size_| is the sum of GetRemainingSize() of |queue_|'s elements. 48 base::circular_deque<std::unique_ptr<SpdyBuffer>> queue_; 49 size_t total_size_ = 0; 50 }; 51 52 } // namespace net 53 54 #endif // NET_SPDY_SPDY_READ_QUEUE_H_ 55