proxygen
proxygen::HPACKQueue Class Reference

#include <HPACKQueue.h>

Inheritance diagram for proxygen::HPACKQueue:
folly::DestructorCheck

Public Member Functions

 HPACKQueue (HPACKCodec &codec)
 
void enqueueHeaderBlock (uint32_t seqn, std::unique_ptr< folly::IOBuf > block, size_t length, HPACK::StreamingCallback *streamingCb, bool oooOk)
 
uint64_t getHolBlockCount () const
 
uint64_t getQueuedBytes () const
 
- Public Member Functions inherited from folly::DestructorCheck
virtual ~DestructorCheck ()
 

Private Member Functions

bool decodeBlock (int32_t seqn, std::unique_ptr< folly::IOBuf > block, size_t length, HPACK::StreamingCallback *cb, bool ooo)
 
void drainQueue ()
 

Private Attributes

size_t nextSeqn_ {0}
 
uint64_t holBlockCount_ {0}
 
uint64_t queuedBytes_ {0}
 
std::deque< std::tuple< uint32_t, std::unique_ptr< folly::IOBuf >, size_t, HPACK::StreamingCallback * > > queue_
 
HPACKCodeccodec_
 

Detailed Description

Definition at line 21 of file HPACKQueue.h.

Constructor & Destructor Documentation

proxygen::HPACKQueue::HPACKQueue ( HPACKCodec codec)
inlineexplicit

Definition at line 23 of file HPACKQueue.h.

24  : codec_(codec) {}
CodecFactory codec
HPACKCodec & codec_
Definition: HPACKQueue.h:123

Member Function Documentation

bool proxygen::HPACKQueue::decodeBlock ( int32_t  seqn,
std::unique_ptr< folly::IOBuf block,
size_t  length,
HPACK::StreamingCallback cb,
bool  ooo 
)
inlineprivate

Definition at line 85 of file HPACKQueue.h.

References c, codec_, proxygen::HPACKCodec::decodeStreaming(), and nextSeqn_.

Referenced by drainQueue(), and enqueueHeaderBlock().

87  {
88  if (length > 0) {
89  VLOG(5) << "decodeBlock for block=" << seqn << " len=" << length;
90  folly::io::Cursor c(block.get());
91  folly::DestructorCheck::Safety safety(*this);
92  codec_.decodeStreaming(c, length, cb);
93  if (safety.destroyed()) {
94  return true;
95  }
96  }
97  if (!ooo) {
98  nextSeqn_++;
99  }
100  return false;
101  }
void decodeStreaming(folly::io::Cursor &cursor, uint32_t length, HPACK::StreamingCallback *streamingCb) noexcept
Definition: HPACKCodec.cpp:67
char c
HPACKCodec & codec_
Definition: HPACKQueue.h:123
void proxygen::HPACKQueue::drainQueue ( )
inlineprivate

Definition at line 103 of file HPACKQueue.h.

References decodeBlock(), folly::gen::move, cpp.ast::next(), nextSeqn_, queue_, and queuedBytes_.

Referenced by enqueueHeaderBlock().

103  {
104  while (!queue_.empty() && nextSeqn_ == std::get<0>(queue_.front())) {
105  auto& next = queue_.front();
106  auto length = std::get<2>(next);
107  if (decodeBlock(std::get<0>(next), std::move(std::get<1>(next)),
108  length, std::get<3>(next),
109  false /* in order */)) {
110  return;
111  }
112  DCHECK_LE(length, queuedBytes_);
113  queuedBytes_ -= length;
114  queue_.pop_front();
115  }
116  }
bool decodeBlock(int32_t seqn, std::unique_ptr< folly::IOBuf > block, size_t length, HPACK::StreamingCallback *cb, bool ooo)
Definition: HPACKQueue.h:85
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::deque< std::tuple< uint32_t, std::unique_ptr< folly::IOBuf >, size_t, HPACK::StreamingCallback * > > queue_
Definition: HPACKQueue.h:122
def next(obj)
Definition: ast.py:58
void proxygen::HPACKQueue::enqueueHeaderBlock ( uint32_t  seqn,
std::unique_ptr< folly::IOBuf block,
size_t  length,
HPACK::StreamingCallback streamingCb,
bool  oooOk 
)
inline

Definition at line 26 of file HPACKQueue.h.

References proxygen::HPACK::BAD_SEQUENCE_NUMBER, decodeBlock(), drainQueue(), holBlockCount_, int32_t, folly::gen::move, nextSeqn_, proxygen::HPACK::StreamingCallback::onDecodeError(), queue_, and queuedBytes_.

Referenced by proxygen::compress::HPACKScheme::decode().

29  {
30  if (seqn < nextSeqn_) {
31  streamingCb->onDecodeError(HPACK::DecodeError::BAD_SEQUENCE_NUMBER);
32  return;
33  }
34  if (nextSeqn_ == seqn) {
35  // common case, decode immediately
36  if (decodeBlock(seqn, std::move(block), length, streamingCb,
37  false /* in order */)) {
38  return;
39  }
40  drainQueue();
41  } else {
42  // there's a gap, have to queue
43  auto it = queue_.begin();
44  while (it != queue_.end()) {
45  auto qSeqn = std::get<0>(*it);
46  if (seqn == qSeqn) {
47  streamingCb->onDecodeError(HPACK::DecodeError::BAD_SEQUENCE_NUMBER);
48  return;
49  } else if (seqn < qSeqn) {
50  break;
51  }
52  it++;
53  }
54  if (oooOk) {
55  // out-of-order allowed. Decode the block, but make an empty entry in
56  // the queue
57  if (decodeBlock(seqn, std::move(block), length, streamingCb,
58  true /* ooo */)) {
59  return;
60  }
61  length = 0;
62  streamingCb = nullptr;
63  } else {
65  }
66  VLOG(5) << "queued block=" << seqn << " len=" << length <<
67  " placeholder=" << int32_t(oooOk);
68  queuedBytes_ += length;
69  queue_.emplace(it, seqn, std::move(block), length, streamingCb);
70  }
71  }
bool decodeBlock(int32_t seqn, std::unique_ptr< folly::IOBuf > block, size_t length, HPACK::StreamingCallback *cb, bool ooo)
Definition: HPACKQueue.h:85
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::deque< std::tuple< uint32_t, std::unique_ptr< folly::IOBuf >, size_t, HPACK::StreamingCallback * > > queue_
Definition: HPACKQueue.h:122
uint64_t holBlockCount_
Definition: HPACKQueue.h:119
uint64_t proxygen::HPACKQueue::getHolBlockCount ( ) const
inline

Definition at line 73 of file HPACKQueue.h.

References holBlockCount_.

Referenced by proxygen::compress::HPACKScheme::getHolBlockCount().

73  {
74  return holBlockCount_;
75  }
uint64_t holBlockCount_
Definition: HPACKQueue.h:119
uint64_t proxygen::HPACKQueue::getQueuedBytes ( ) const
inline

Definition at line 77 of file HPACKQueue.h.

References queuedBytes_.

Referenced by proxygen::compress::HPACKScheme::decode(), and proxygen::compress::HPACKScheme::~HPACKScheme().

77  {
78  return queuedBytes_;
79  }

Member Data Documentation

HPACKCodec& proxygen::HPACKQueue::codec_
private

Definition at line 123 of file HPACKQueue.h.

Referenced by decodeBlock().

uint64_t proxygen::HPACKQueue::holBlockCount_ {0}
private

Definition at line 119 of file HPACKQueue.h.

Referenced by enqueueHeaderBlock(), and getHolBlockCount().

size_t proxygen::HPACKQueue::nextSeqn_ {0}
private

Definition at line 118 of file HPACKQueue.h.

Referenced by decodeBlock(), drainQueue(), and enqueueHeaderBlock().

std::deque<std::tuple<uint32_t, std::unique_ptr<folly::IOBuf>, size_t, HPACK::StreamingCallback*> > proxygen::HPACKQueue::queue_
private

Definition at line 122 of file HPACKQueue.h.

Referenced by drainQueue(), and enqueueHeaderBlock().

uint64_t proxygen::HPACKQueue::queuedBytes_ {0}
private

Definition at line 120 of file HPACKQueue.h.

Referenced by drainQueue(), enqueueHeaderBlock(), and getQueuedBytes().


The documentation for this class was generated from the following file: