mirror of
https://github.com/facebookincubator/mvfst.git
synced 2025-11-25 15:43:13 +03:00
Back out "BufQueue::trimAtMost"
Summary: Original commit changeset: 0ace20d07d8b Original Phabricator Diff: D46776767 Reviewed By: lnicco Differential Revision: D47007928 fbshipit-source-id: 6c8760683692d1b50168f8f5d82d79c98ebe7c31
This commit is contained in:
committed by
Facebook GitHub Bot
parent
69ff02e35f
commit
711f0e30fc
@@ -840,22 +840,20 @@ QuicFrame parseFrame(
|
|||||||
throw QuicTransportException(
|
throw QuicTransportException(
|
||||||
"Invalid frame-type field", TransportErrorCode::FRAME_ENCODING_ERROR);
|
"Invalid frame-type field", TransportErrorCode::FRAME_ENCODING_ERROR);
|
||||||
}
|
}
|
||||||
queue.trimStart(frameTypeInt->second);
|
queue.trimStart(cursor - queue.front());
|
||||||
bool consumedQueue = false;
|
bool consumedQueue = false;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
SCOPE_EXIT {
|
SCOPE_EXIT {
|
||||||
if (consumedQueue || error) {
|
if (consumedQueue || error) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!queue.empty()) {
|
queue.trimStart(cursor - queue.front());
|
||||||
queue.trimStart(cursor - queue.front());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
// trimStart() may have free'd the IOBuf;
|
cursor.reset(queue.front());
|
||||||
folly::IOBuf emptyBuf{};
|
|
||||||
cursor.reset(queue.empty() ? &emptyBuf : queue.front());
|
|
||||||
FrameType frameType = static_cast<FrameType>(frameTypeInt->first);
|
FrameType frameType = static_cast<FrameType>(frameTypeInt->first);
|
||||||
try {
|
try
|
||||||
|
|
||||||
|
{
|
||||||
switch (frameType) {
|
switch (frameType) {
|
||||||
case FrameType::PADDING:
|
case FrameType::PADDING:
|
||||||
return QuicFrame(decodePaddingFrame(cursor));
|
return QuicFrame(decodePaddingFrame(cursor));
|
||||||
|
|||||||
@@ -59,9 +59,45 @@ Buf BufQueue::splitAtMost(size_t len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t BufQueue::trimStartAtMost(size_t amount) {
|
size_t BufQueue::trimStartAtMost(size_t amount) {
|
||||||
auto oldChainLength = chainLength_;
|
auto original = amount;
|
||||||
splitAtMost(amount);
|
folly::IOBuf* current = chain_.get();
|
||||||
return oldChainLength - chainLength_;
|
if (current == nullptr || amount == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
while (amount > 0) {
|
||||||
|
if (current->length() >= amount) {
|
||||||
|
current->trimStart(amount);
|
||||||
|
amount = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
amount -= current->length();
|
||||||
|
current = current->next();
|
||||||
|
if (current == chain_.get()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto prev = current->prev();
|
||||||
|
/** We are potentially in 2 states here,
|
||||||
|
* 1. we found the entire amount
|
||||||
|
* 2. or we did not.
|
||||||
|
* If we did not find the entire amount, then current ==
|
||||||
|
* chain and we can remove the entire chain.
|
||||||
|
* If we did, then we can split from the chain head to the previous buffer and
|
||||||
|
* then keep the current buffer.
|
||||||
|
*/
|
||||||
|
if (prev != current && current != chain_.get()) {
|
||||||
|
auto chain = chain_.release();
|
||||||
|
current->separateChain(chain, prev);
|
||||||
|
chain_ = std::unique_ptr<folly::IOBuf>(current);
|
||||||
|
} else if (amount > 0) {
|
||||||
|
DCHECK_EQ(current, chain_.get());
|
||||||
|
chain_ = nullptr;
|
||||||
|
}
|
||||||
|
size_t trimmed = original - amount;
|
||||||
|
DCHECK_GE(chainLength_, trimmed);
|
||||||
|
chainLength_ -= trimmed;
|
||||||
|
DCHECK(chainLength_ == 0 || !chain_->empty());
|
||||||
|
return trimmed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO replace users with trimStartAtMost
|
// TODO replace users with trimStartAtMost
|
||||||
|
|||||||
@@ -187,15 +187,6 @@ TEST(BufQueue, TrimStartAtMost) {
|
|||||||
checkConsistency(queue);
|
checkConsistency(queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(BufQueue, TrimStartOneByte) {
|
|
||||||
BufQueue queue;
|
|
||||||
queue.append(IOBuf::copyBuffer(SCL("H")));
|
|
||||||
checkConsistency(queue);
|
|
||||||
queue.trimStart(1);
|
|
||||||
checkConsistency(queue);
|
|
||||||
EXPECT_TRUE(queue.front() == nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(BufQueue, CloneBufNull) {
|
TEST(BufQueue, CloneBufNull) {
|
||||||
BufQueue queue;
|
BufQueue queue;
|
||||||
auto buf = queue.clone();
|
auto buf = queue.clone();
|
||||||
|
|||||||
Reference in New Issue
Block a user