spdy_read_queue.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #ifndef NET_SPDY_SPDY_READ_QUEUE_H_
  5. #define NET_SPDY_SPDY_READ_QUEUE_H_
  6. #include <cstddef>
  7. #include <memory>
  8. #include "base/containers/circular_deque.h"
  9. #include "net/base/net_export.h"
  10. namespace net {
  11. class SpdyBuffer;
  12. // A FIFO queue of incoming data from a SPDY connection. Useful for
  13. // SpdyStream delegates.
  14. class NET_EXPORT_PRIVATE SpdyReadQueue {
  15. public:
  16. SpdyReadQueue();
  17. SpdyReadQueue(const SpdyReadQueue&) = delete;
  18. SpdyReadQueue& operator=(const SpdyReadQueue&) = delete;
  19. ~SpdyReadQueue();
  20. // Returns whether there's anything in the queue.
  21. bool IsEmpty() const;
  22. // Returns the total number of bytes in the queue.
  23. size_t GetTotalSize() const;
  24. // Enqueues the bytes in |buffer|.
  25. void Enqueue(std::unique_ptr<SpdyBuffer> buffer);
  26. // Dequeues up to |len| (which must be positive) bytes into
  27. // |out|. Returns the number of bytes dequeued.
  28. size_t Dequeue(char* out, size_t len);
  29. // Removes all bytes from the queue.
  30. void Clear();
  31. private:
  32. // Class invariant:
  33. // |total_size_| is the sum of GetRemainingSize() of |queue_|'s elements.
  34. base::circular_deque<std::unique_ptr<SpdyBuffer>> queue_;
  35. size_t total_size_ = 0;
  36. };
  37. } // namespace net
  38. #endif // NET_SPDY_SPDY_READ_QUEUE_H_