1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-08-08 09:42:06 +03:00

Mostly remove folly::Optional

Summary:
This is an API break, but it should mostly be a manageable one. We want to be able to compile mvfst internally without exceptions, and folly::Optional is one dependency that makes this challenging. Additionally, we already have an imported secondary optional type for performance/struct size reasons, tiny-optional.

This second optional interface is mostly compatible in an API sense (including the use of std::nullopt) with std::optional. Thus our approach is to remove the dependency on folly::Optional, and offer a quic::Optional instead.

The next diff will properly vendor tiny-optional so that quic::Optional is an independent version of it.

Reviewed By: sharmafb, kvtsoy

Differential Revision: D74133131

fbshipit-source-id: 715f8bb5043ba3bb876cacfe54236887e0686b30
This commit is contained in:
Matt Joras
2025-05-07 23:01:49 -07:00
committed by Facebook GitHub Bot
parent d306793640
commit 9a9dcca57c
159 changed files with 1502 additions and 1209 deletions

View File

@@ -50,12 +50,12 @@ class TransportClosingDeliveryCallback : public QuicSocket::DeliveryCallback {
void onDeliveryAck(StreamId, uint64_t offset, std::chrono::microseconds)
override {
if (offset >= targetOffset_) {
transport_->close(none);
transport_->close(std::nullopt);
}
}
void onCanceled(StreamId, uint64_t) override {
transport_->close(none);
transport_->close(std::nullopt);
}
private:
@@ -298,7 +298,7 @@ TEST_F(QuicTransportTest, WriteDataWithProbing) {
}));
transport_->writeChain(streamId, buf->clone(), true);
loopForWrites();
transport_->close(none);
transport_->close(std::nullopt);
}
TEST_F(QuicTransportTest, NotAppLimitedWithLoss) {
@@ -328,7 +328,7 @@ TEST_F(QuicTransportTest, NotAppLimitedWithLoss) {
EXPECT_CALL(*rawCongestionController, setAppLimited()).Times(0);
EXPECT_CALL(connCallback_, onAppRateLimited()).Times(0);
loopForWrites();
transport_->close(none);
transport_->close(std::nullopt);
}
TEST_F(QuicTransportTest, NotAppLimitedWithNoWritableBytes) {
@@ -351,7 +351,7 @@ TEST_F(QuicTransportTest, NotAppLimitedWithNoWritableBytes) {
EXPECT_CALL(*rawCongestionController, setAppLimited()).Times(0);
EXPECT_CALL(connCallback_, onAppRateLimited()).Times(0);
loopForWrites();
transport_->close(none);
transport_->close(std::nullopt);
}
TEST_F(QuicTransportTest, NotAppLimitedWithLargeBuffer) {
@@ -369,7 +369,7 @@ TEST_F(QuicTransportTest, NotAppLimitedWithLargeBuffer) {
EXPECT_CALL(*rawCongestionController, setAppLimited()).Times(0);
EXPECT_CALL(connCallback_, onAppRateLimited()).Times(0);
loopForWrites();
transport_->close(none);
transport_->close(std::nullopt);
}
TEST_F(QuicTransportTest, AppLimited) {
@@ -388,7 +388,7 @@ TEST_F(QuicTransportTest, AppLimited) {
EXPECT_CALL(*rawCongestionController, setAppLimited()).Times(1);
EXPECT_CALL(connCallback_, onAppRateLimited()).Times(1);
loopForWrites();
transport_->close(none);
transport_->close(std::nullopt);
}
TEST_F(QuicTransportTest, ObserverNotAppLimitedWithNoWritableBytes) {
@@ -441,7 +441,7 @@ TEST_F(QuicTransportTest, ObserverNotAppLimitedWithNoWritableBytes) {
EXPECT_CALL(*cb1, destroy(transport_.get()));
EXPECT_CALL(*cb2, destroy(transport_.get()));
EXPECT_CALL(*cb3, destroy(transport_.get()));
transport_->close(none);
transport_->close(std::nullopt);
transport_ = nullptr;
}
@@ -490,7 +490,7 @@ TEST_F(QuicTransportTest, ObserverNotAppLimitedWithLargeBuffer) {
EXPECT_CALL(*cb1, destroy(transport_.get()));
EXPECT_CALL(*cb2, destroy(transport_.get()));
EXPECT_CALL(*cb3, destroy(transport_.get()));
transport_->close(none);
transport_->close(std::nullopt);
transport_ = nullptr;
}
@@ -541,7 +541,7 @@ TEST_F(QuicTransportTest, ObserverAppLimited) {
EXPECT_CALL(*cb1, destroy(transport_.get()));
EXPECT_CALL(*cb2, destroy(transport_.get()));
EXPECT_CALL(*cb3, destroy(transport_.get()));
transport_->close(none);
transport_->close(std::nullopt);
transport_ = nullptr;
}
@@ -929,7 +929,7 @@ TEST_F(QuicTransportTest, ObserverPacketsWrittenCycleCheckDetails) {
invokeForAllObservers(([this](MockLegacyObserver& observer) {
EXPECT_CALL(observer, destroy(transport_.get()));
}));
transport_->close(none);
transport_->close(std::nullopt);
transport_ = nullptr;
}
@@ -1144,7 +1144,7 @@ TEST_F(QuicTransportTest, ObserverPacketsWrittenCheckBytesSent) {
invokeForAllObservers(([this](MockLegacyObserver& observer) {
EXPECT_CALL(observer, destroy(transport_.get()));
}));
transport_->close(none);
transport_->close(std::nullopt);
transport_ = nullptr;
}
@@ -1427,7 +1427,7 @@ TEST_F(QuicTransportTest, ObserverWriteEventsCheckCwndPacketsWritable) {
invokeForAllObservers(([this](MockLegacyObserver& observer) {
EXPECT_CALL(observer, destroy(transport_.get()));
}));
transport_->close(none);
transport_->close(std::nullopt);
transport_ = nullptr;
}
@@ -2135,11 +2135,11 @@ TEST_F(QuicTransportTest, NoWritePendingAckIfHavingData) {
ackFound = true;
}
EXPECT_FALSE(ackFound);
EXPECT_EQ(conn.ackStates.appDataAckState.largestAckScheduled, none);
EXPECT_EQ(conn.ackStates.appDataAckState.largestAckScheduled, std::nullopt);
auto pnSpace = packet.header.getPacketNumberSpace();
auto ackState = getAckState(conn, pnSpace);
EXPECT_EQ(ackState.largestAckScheduled, none);
EXPECT_EQ(ackState.largestAckScheduled, std::nullopt);
EXPECT_FALSE(ackState.needsToSendAckImmediately);
EXPECT_EQ(3, ackState.numNonRxPacketsRecvd);
}
@@ -2173,11 +2173,11 @@ TEST_F(QuicTransportTest, NoWritePendingAckIfHavingDataNonStream) {
ackFound = true;
}
EXPECT_FALSE(ackFound);
EXPECT_EQ(conn.ackStates.appDataAckState.largestAckScheduled, none);
EXPECT_EQ(conn.ackStates.appDataAckState.largestAckScheduled, std::nullopt);
auto pnSpace = packet.header.getPacketNumberSpace();
auto ackState = getAckState(conn, pnSpace);
EXPECT_EQ(ackState.largestAckScheduled, none);
EXPECT_EQ(ackState.largestAckScheduled, std::nullopt);
EXPECT_FALSE(ackState.needsToSendAckImmediately);
EXPECT_EQ(3, ackState.numNonRxPacketsRecvd);
}
@@ -2497,7 +2497,7 @@ TEST_F(QuicTransportTest, StopSendingReadCallbackNone) {
auto streamId = transport_->createBidirectionalStream().value();
NiceMock<MockReadCallback> readCb;
transport_->setReadCallback(streamId, &readCb);
transport_->setReadCallback(streamId, nullptr, none);
transport_->setReadCallback(streamId, nullptr, std::nullopt);
loopForWrites();
EXPECT_EQ(0, transport_->getConnectionState().outstandings.packets.size());
}
@@ -2508,7 +2508,7 @@ TEST_F(QuicTransportTest, NoStopSendingReadCallback) {
transport_->setReadCallback(streamId, &readCb);
loopForWrites();
EXPECT_EQ(0, transport_->getConnectionState().outstandings.packets.size());
transport_->setReadCallback(streamId, nullptr, none);
transport_->setReadCallback(streamId, nullptr, std::nullopt);
}
TEST_F(QuicTransportTest, SendPathChallenge) {
@@ -2612,7 +2612,7 @@ TEST_F(QuicTransportTest, SendPathValidationWhileThereIsOutstandingOne) {
PathChallengeFrame pathChallenge2(456);
transport_->getPathValidationTimeout().cancelTimerCallback();
conn.pendingEvents.schedulePathValidationTimeout = false;
conn.outstandingPathValidation = none;
conn.outstandingPathValidation = std::nullopt;
conn.pendingEvents.pathChallenge = pathChallenge2;
EXPECT_EQ(conn.pendingEvents.pathChallenge, pathChallenge2);
EXPECT_FALSE(conn.pendingEvents.schedulePathValidationTimeout);
@@ -2685,7 +2685,7 @@ TEST_F(QuicTransportTest, OnlyClonePathValidationIfOutstanding) {
// Reset outstandingPathValidation
// This could happen when an endpoint migrates to an unvalidated address, and
// then migrates back to a validated address before timer expires
conn.outstandingPathValidation = none;
conn.outstandingPathValidation = std::nullopt;
// Force a timeout with no data so that it clones the packet
transport_->lossTimeout().timeoutExpired();
@@ -2805,7 +2805,7 @@ TEST_F(QuicTransportTest, CloneAfterRecvReset) {
conn.outstandings.packets.begin(),
conn.outstandings.packets.end(),
[](const auto& packet) {
return packet.maybeClonedPacketIdentifier.hasValue();
return packet.maybeClonedPacketIdentifier.has_value();
});
EXPECT_LE(1, cloneCounter);
}
@@ -2985,7 +2985,7 @@ TEST_F(QuicTransportTest, BusyWriteLoopDetection) {
EXPECT_EQ(1, conn.outstandings.packets.size());
EXPECT_EQ(1, conn.writeDebugState.currentEmptyLoopCount);
transport_->close(none);
transport_->close(std::nullopt);
}
TEST_F(QuicTransportTest, ResendNewConnectionIdOnLoss) {
@@ -3416,7 +3416,7 @@ TEST_F(QuicTransportTest, DeliveryCallbackClosesClosedTransport) {
.WillRepeatedly(testing::WithArgs<1, 2>(Invoke(getTotalIovecLen)));
transport_->writeChain(stream1, buf1->clone(), true, &dc);
loopForWrites();
transport_->close(none);
transport_->close(std::nullopt);
}
TEST_F(QuicTransportTest, DeliveryCallbackClosesTransportOnDelivered) {
@@ -3704,7 +3704,7 @@ TEST_F(QuicTransportTest, InvokeDeliveryCallbacksSingleByte) {
// unsentByteDeliveryCb::onByteEvent will never get called
// cancel gets called instead
EXPECT_CALL(unsentByteDeliveryCb, onCanceled(stream, 1)).Times(1);
transport_->close(none);
transport_->close(std::nullopt);
Mock::VerifyAndClearExpectations(&unsentByteDeliveryCb);
}
@@ -3763,7 +3763,7 @@ TEST_F(QuicTransportTest, InvokeDeliveryCallbacksSingleByteWithFin) {
// unsentByteDeliveryCb::onByteEvent will never get called
// cancel gets called instead
EXPECT_CALL(unsentByteDeliveryCb, onCanceled(stream, 2)).Times(1);
transport_->close(none);
transport_->close(std::nullopt);
Mock::VerifyAndClearExpectations(&unsentByteDeliveryCb);
}
@@ -3826,7 +3826,7 @@ TEST_F(QuicTransportTest, InvokeTxCallbacksSingleByte) {
// an error. So, onByteEventCanceled should be called only once.
EXPECT_CALL(pastlastByteTxCb, onByteEventCanceled(getTxMatcher(stream, 1)))
.Times(1);
transport_->close(none);
transport_->close(std::nullopt);
Mock::VerifyAndClearExpectations(&pastlastByteTxCb);
}
@@ -3887,7 +3887,7 @@ TEST_F(QuicTransportTest, InvokeTxCallbacksSingleByteWithFin) {
// cancel gets called instead
EXPECT_CALL(pastlastByteTxCb, onByteEventCanceled(getTxMatcher(stream, 2)))
.Times(1);
transport_->close(none);
transport_->close(std::nullopt);
Mock::VerifyAndClearExpectations(&pastlastByteTxCb);
}
@@ -3950,7 +3950,7 @@ TEST_F(QuicTransportTest, InvokeTxCallbacksMultipleBytes) {
EXPECT_CALL(
pastlastByteTxCb, onByteEventCanceled(getTxMatcher(stream, lastByte + 1)))
.Times(1);
transport_->close(none);
transport_->close(std::nullopt);
Mock::VerifyAndClearExpectations(&pastlastByteTxCb);
}
@@ -4022,7 +4022,7 @@ TEST_F(QuicTransportTest, InvokeTxCallbacksMultipleBytesWriteRateLimited) {
EXPECT_CALL(
pastlastByteTxCb, onByteEventCanceled(getTxMatcher(stream, lastByte + 1)))
.Times(1);
transport_->close(none);
transport_->close(std::nullopt);
Mock::VerifyAndClearExpectations(&pastlastByteTxCb);
}
@@ -4531,7 +4531,7 @@ TEST_F(QuicTransportTest, NotifyPendingWriteConnDuringClose) {
} else {
EXPECT_CALL(writeCallback_, onStreamWriteError(streamId, _));
}
transport_->close(none);
transport_->close(std::nullopt);
}));
PacketNum num = 10;
// Give the conn some headroom.
@@ -4571,7 +4571,7 @@ TEST_F(QuicTransportTest, NotifyPendingWriteStreamDuringClose) {
EXPECT_CALL(connCallback_, onFlowControlUpdate(stream->id));
EXPECT_CALL(writeCallback_, onStreamWriteError(streamId2, _));
EXPECT_CALL(writeCallback_, onStreamWriteReady(stream->id, _))
.WillOnce(Invoke([&](auto, auto) { transport_->close(none); }));
.WillOnce(Invoke([&](auto, auto) { transport_->close(std::nullopt); }));
transport_->onNetworkData(
SocketAddress("::1", 10000),
NetworkData(ReceivedUdpPacket(IOBuf::copyBuffer("fake data"))));
@@ -4663,7 +4663,7 @@ TEST_F(QuicTransportTest, WriteStreamFromMiddleOfMap) {
if (oldWriteQueue) {
oldWriteQueue->setNextScheduledStream(s2);
} else {
conn.streamManager->writeQueue().getNextScheduledID(quic::none);
conn.streamManager->writeQueue().getNextScheduledID(std::nullopt);
}
writableBytes = kDefaultUDPSendPacketLen;
EXPECT_CALL(*socket_, write(_, _, _))
@@ -4691,7 +4691,7 @@ TEST_F(QuicTransportTest, WriteStreamFromMiddleOfMap) {
const WriteStreamFrame* streamFrame4 = frame4.asWriteStreamFrame();
EXPECT_TRUE(streamFrame4);
EXPECT_EQ(streamFrame4->streamId, s1);
transport_->close(none);
transport_->close(std::nullopt);
}
TEST_F(QuicTransportTest, NoStream) {
@@ -4802,7 +4802,7 @@ TEST_F(QuicTransportTest, CloseTransportCancelsAckTimeout) {
transport_->scheduleLossTimeout(500ms);
EXPECT_TRUE(transport_->isLossTimeoutScheduled());
transport_->closeNow(none);
transport_->closeNow(std::nullopt);
EXPECT_FALSE(transport_->getAckTimeout()->isTimerCallbackScheduled());
EXPECT_FALSE(transport_->isLossTimeoutScheduled());
}
@@ -4816,7 +4816,7 @@ TEST_F(QuicTransportTest, DrainTimeoutExpired) {
TEST_F(QuicTransportTest, CloseWithDrainWillKeepSocketAround) {
EXPECT_CALL(*socket_, pauseRead()).Times(0);
EXPECT_CALL(*socket_, close()).Times(0);
transport_->close(none);
transport_->close(std::nullopt);
// Manual shut it, otherwise transport_'s dtor will shut the socket and mess
// up the EXPECT_CALLs above
@@ -5149,7 +5149,7 @@ TEST_F(QuicTransportTest, PrioritySetAndGet) {
auto nonExistStreamPri = transport_->getStreamPriority(stream + 4);
EXPECT_TRUE(nonExistStreamPri.hasError());
EXPECT_EQ(LocalErrorCode::STREAM_NOT_EXISTS, nonExistStreamPri.error());
transport_->close(none);
transport_->close(std::nullopt);
auto closedConnStreamPri = transport_->getStreamPriority(stream);
EXPECT_TRUE(closedConnStreamPri.hasError());
EXPECT_EQ(LocalErrorCode::CONNECTION_CLOSED, closedConnStreamPri.error());