Skip to content

Commit

Permalink
Make an allBytesAckedTill function
Browse files Browse the repository at this point in the history
Summary: With reliable resets, we can only safely close a stream once all bytes until the reliable size have been ACKed by the peer. We're going to use this helper function to aid us in that.

Reviewed By: mjoras

Differential Revision: D66781309

fbshipit-source-id: 66094929b53c9eab3185e05b8a033b112577b60b
  • Loading branch information
Aman Sharma authored and facebook-github-bot committed Dec 11, 2024
1 parent fca90d4 commit 132a6b8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
9 changes: 9 additions & 0 deletions quic/state/StreamData.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,15 @@ struct QuicStreamLike {
pendingWrites.splitAtMost(pendingWrites.chainLength());
}
}

[[nodiscard]] bool allBytesAckedTill(uint64_t offset) const {
if (ackedIntervals.empty()) {
return false;
}

return ackedIntervals.front().start == 0 &&
ackedIntervals.front().end >= offset;
}
};

struct QuicConnectionStateBase;
Expand Down
45 changes: 45 additions & 0 deletions quic/state/test/StreamDataTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,4 +585,49 @@ TEST(StreamDataTest, WriteBufferMetaRemovalNoChange) {
EXPECT_EQ(state.writeBufMeta.length, 12);
}

TEST(StreamDataTest, AllBytesAckedTillEmptyAck) {
QuicConnectionStateBase qcsb(QuicNodeType::Client);
QuicStreamState state(0, qcsb);

EXPECT_TRUE(state.ackedIntervals.empty());
EXPECT_EQ(state.allBytesAckedTill(0), false);
}

TEST(StreamDataTest, AllBytesAckedTillNotStartAtZero) {
QuicConnectionStateBase qcsb(QuicNodeType::Client);
QuicStreamState state(0, qcsb);

EXPECT_TRUE(state.ackedIntervals.empty());
state.updateAckedIntervals(1, 5, false);
EXPECT_EQ(state.allBytesAckedTill(5), false);
}

TEST(StreamDataTest, AllBytesAckedTillNotEnoughLength) {
QuicConnectionStateBase qcsb(QuicNodeType::Client);
QuicStreamState state(0, qcsb);

EXPECT_TRUE(state.ackedIntervals.empty());
state.updateAckedIntervals(0, 5, false);
EXPECT_EQ(state.allBytesAckedTill(5), false);
}

TEST(StreamDataTest, AllBytesAckedPass) {
QuicConnectionStateBase qcsb(QuicNodeType::Client);
QuicStreamState state(0, qcsb);

EXPECT_TRUE(state.ackedIntervals.empty());
state.updateAckedIntervals(0, 6, false);
EXPECT_EQ(state.allBytesAckedTill(5), true);
}

TEST(StreamDataTest, AllBytesAckedDisjointIntervals) {
QuicConnectionStateBase qcsb(QuicNodeType::Client);
QuicStreamState state(0, qcsb);

EXPECT_TRUE(state.ackedIntervals.empty());
state.updateAckedIntervals(0, 2, false);
state.updateAckedIntervals(3, 5, false);
EXPECT_EQ(state.allBytesAckedTill(5), false);
}

} // namespace quic::test

0 comments on commit 132a6b8

Please sign in to comment.