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

@@ -277,7 +277,7 @@ class TestQuicTransport
Optional<std::vector<TransportParameter>> getPeerTransportParams()
const override {
return none;
return std::nullopt;
}
std::chrono::milliseconds getLossTimeoutRemainingTime() {
@@ -546,7 +546,7 @@ class TestQuicTransport
}
void closeWithoutWrite() {
closeImpl(none, false, false);
closeImpl(std::nullopt, false, false);
}
void invokeWriteSocketData() {
@@ -604,7 +604,7 @@ class TestQuicTransport
const std::string&,
const Optional<ByteRange>&,
uint16_t) const override {
return none;
return std::nullopt;
}
void updateWriteLooper(bool thisIteration, bool /* runInline */ = false) {
@@ -616,7 +616,7 @@ class TestQuicTransport
}
void closeImpl(
folly::Optional<QuicError> error,
Optional<QuicError> error,
bool drainConnection = true,
bool sendCloseImmediately = true) {
QuicTransportBase::closeImpl(
@@ -836,7 +836,7 @@ TEST_P(QuicTransportImplTestBase, StopSendingClosesIngress) {
// suppose we tx a rst stream (and rx its corresponding ack), expect
// terminal state and queued in closed streams
transport->resetStream(streamID, GenericApplicationErrorCode::NO_ERROR);
ASSERT_FALSE(sendRstAckSMHandler(*stream, folly::none).hasError());
ASSERT_FALSE(sendRstAckSMHandler(*stream, std::nullopt).hasError());
EXPECT_TRUE(stream->inTerminalStates());
EXPECT_TRUE(streamManager.closedStreams().contains(streamID));
transport->driveReadCallbacks();
@@ -872,7 +872,7 @@ TEST_P(QuicTransportImplTestBase, StopSendingClosesIngress) {
// suppose we tx a rst stream (and rx its corresponding ack)
transport->resetStream(streamID, GenericApplicationErrorCode::NO_ERROR);
ASSERT_FALSE(sendRstAckSMHandler(*stream, folly::none).hasError());
ASSERT_FALSE(sendRstAckSMHandler(*stream, std::nullopt).hasError());
EXPECT_EQ(stream->sendState, StreamSendState::Closed);
EXPECT_EQ(stream->recvState, StreamRecvState::Open);
transport->driveReadCallbacks();
@@ -1996,7 +1996,7 @@ TEST_P(QuicTransportImplTestBase, CloseStreamAfterReadFin) {
TEST_P(QuicTransportImplTestBase, CloseTransportCleansupOutstandingCounters) {
transport->transportConn->outstandings
.packetCount[PacketNumberSpace::Handshake] = 200;
transport->closeNow(none);
transport->closeNow(std::nullopt);
EXPECT_EQ(
0,
transport->transportConn->outstandings
@@ -2020,7 +2020,7 @@ TEST_P(QuicTransportImplTestBase, DeliveryCallbackUnsetAll) {
EXPECT_CALL(dcb1, onCanceled(_, _)).Times(0);
EXPECT_CALL(dcb2, onCanceled(_, _)).Times(0);
transport->close(none);
transport->close(std::nullopt);
}
TEST_P(QuicTransportImplTestBase, DeliveryCallbackUnsetOne) {
@@ -2040,7 +2040,7 @@ TEST_P(QuicTransportImplTestBase, DeliveryCallbackUnsetOne) {
EXPECT_CALL(dcb1, onCanceled(_, _)).Times(0);
EXPECT_CALL(dcb2, onCanceled(_, _));
transport->close(none);
transport->close(std::nullopt);
}
TEST_P(QuicTransportImplTestBase, ByteEventCallbacksManagementSingleStream) {
@@ -2234,7 +2234,7 @@ TEST_P(QuicTransportImplTestBase, RegisterTxDeliveryCallbackLowerThanExpected) {
EXPECT_CALL(txcb2, onByteEventCanceled(getTxMatcher(stream, 20)));
EXPECT_CALL(dcb1, onCanceled(_, _));
EXPECT_CALL(dcb2, onCanceled(_, _));
transport->close(none);
transport->close(std::nullopt);
Mock::VerifyAndClearExpectations(&txcb1);
Mock::VerifyAndClearExpectations(&txcb2);
Mock::VerifyAndClearExpectations(&txcb3);
@@ -2260,7 +2260,7 @@ TEST_F(
EXPECT_CALL(dcb, onCanceled(_, _));
transport->registerTxCallback(stream, 2, &txcb);
transport->registerDeliveryCallback(stream, 2, &dcb);
transport->close(none);
transport->close(std::nullopt);
qEvb->loopOnce();
Mock::VerifyAndClearExpectations(&txcb);
Mock::VerifyAndClearExpectations(&dcb);
@@ -2472,7 +2472,7 @@ TEST_P(QuicTransportImplTestBase, RegisterDeliveryCallbackAsyncDeliveryTx) {
Mock::VerifyAndClearExpectations(&txcb2);
EXPECT_CALL(txcb2, onByteEventCanceled(getTxMatcher(stream, 10)));
transport->close(none);
transport->close(std::nullopt);
Mock::VerifyAndClearExpectations(&txcb2);
}
@@ -2521,7 +2521,7 @@ TEST_P(QuicTransportImplTestBase, RegisterDeliveryCallbackAsyncDeliveryAck) {
Mock::VerifyAndClearExpectations(&txcb2);
EXPECT_CALL(txcb2, onByteEventCanceled(getAckMatcher(stream, 10)));
transport->close(none);
transport->close(std::nullopt);
Mock::VerifyAndClearExpectations(&txcb2);
}
@@ -2595,7 +2595,7 @@ TEST_P(QuicTransportImplTestBase, CancelAllByteEventCallbacks) {
EXPECT_CALL(dcb1, onCanceled(_, _)).Times(0);
EXPECT_CALL(dcb2, onCanceled(_, _)).Times(0);
transport->close(none);
transport->close(std::nullopt);
Mock::VerifyAndClearExpectations(&txcb1);
Mock::VerifyAndClearExpectations(&txcb2);
Mock::VerifyAndClearExpectations(&dcb1);
@@ -2671,7 +2671,7 @@ TEST_P(QuicTransportImplTestBase, CancelByteEventCallbacksForStream) {
EXPECT_CALL(dcb1, onCanceled(stream1, _)).Times(0);
EXPECT_CALL(dcb2, onCanceled(_, 20));
transport->close(none);
transport->close(std::nullopt);
Mock::VerifyAndClearExpectations(&txcb1);
Mock::VerifyAndClearExpectations(&txcb2);
Mock::VerifyAndClearExpectations(&dcb1);
@@ -2830,7 +2830,7 @@ TEST_P(QuicTransportImplTestBase, CancelByteEventCallbacksForStreamWithOffset) {
EXPECT_CALL(dcb2, onCanceled(stream2, 15));
EXPECT_CALL(dcb2, onCanceled(stream2, 20));
transport->close(none);
transport->close(std::nullopt);
Mock::VerifyAndClearExpectations(&txcb1);
Mock::VerifyAndClearExpectations(&txcb2);
Mock::VerifyAndClearExpectations(&dcb1);
@@ -2931,7 +2931,7 @@ TEST_P(QuicTransportImplTestBase, CancelByteEventCallbacksTx) {
EXPECT_CALL(dcb2, onCanceled(stream2, 10));
EXPECT_CALL(dcb2, onCanceled(stream2, 15));
transport->close(none);
transport->close(std::nullopt);
Mock::VerifyAndClearExpectations(&txcb1);
Mock::VerifyAndClearExpectations(&txcb2);
Mock::VerifyAndClearExpectations(&dcb1);
@@ -3013,7 +3013,7 @@ TEST_P(QuicTransportImplTestBase, CancelByteEventCallbacksDelivery) {
EXPECT_CALL(txcb2, onByteEventCanceled(getTxMatcher(stream2, 10)));
EXPECT_CALL(txcb2, onByteEventCanceled(getTxMatcher(stream2, 15)));
transport->close(none);
transport->close(std::nullopt);
Mock::VerifyAndClearExpectations(&txcb1);
Mock::VerifyAndClearExpectations(&txcb2);
Mock::VerifyAndClearExpectations(&dcb1);
@@ -3028,7 +3028,7 @@ TEST_P(
wcb,
onConnectionWriteError(IsError(GenericApplicationErrorCode::NO_ERROR)));
transport->notifyPendingWriteOnConnection(&wcb);
transport->close(none);
transport->close(std::nullopt);
qEvb->loopOnce();
}
@@ -3044,7 +3044,7 @@ TEST_P(QuicTransportImplTestClose, TestNotifyPendingConnWriteOnCloseWithError) {
QuicErrorCode(GenericApplicationErrorCode::UNKNOWN),
std::string("Bye")));
} else {
transport->close(none);
transport->close(std::nullopt);
}
qEvb->loopOnce();
}
@@ -3068,7 +3068,7 @@ TEST_P(QuicTransportImplTestBase, TestNotifyPendingWriteOnCloseWithoutError) {
onStreamWriteError(
stream, IsError(GenericApplicationErrorCode::NO_ERROR)));
transport->notifyPendingWriteOnStream(stream, &wcb);
transport->close(none);
transport->close(std::nullopt);
qEvb->loopOnce();
}
@@ -3085,7 +3085,7 @@ TEST_P(QuicTransportImplTestClose, TestNotifyPendingWriteOnCloseWithError) {
QuicErrorCode(GenericApplicationErrorCode::UNKNOWN),
std::string("Bye")));
} else {
transport->close(none);
transport->close(std::nullopt);
}
qEvb->loopOnce();
}
@@ -3201,7 +3201,7 @@ TEST_P(QuicTransportImplTestBase, TestGracefulCloseWithNoActiveStream) {
transport->transportConn->streamManager->addTx(stream);
transport->transportConn->streamManager->addDeliverable(stream);
transport->closeStream(stream);
transport->close(none);
transport->close(std::nullopt);
ASSERT_TRUE(transport->transportClosed);
EXPECT_FALSE(transport->createBidirectionalStream());
@@ -3238,7 +3238,7 @@ TEST_P(QuicTransportImplTestBase, TestResetRemovesDeliveryCb) {
.hasError());
EXPECT_EQ(transport->getNumByteEventCallbacksForStream(stream1), 0);
EXPECT_EQ(transport->getNumByteEventCallbacksForStream(stream2), 1);
transport->close(none);
transport->close(std::nullopt);
}
TEST_P(QuicTransportImplTestBase, TestImmediateClose) {
@@ -4141,7 +4141,7 @@ TEST_P(QuicTransportImplTestBase, StreamWriteCallbackUnregister) {
EXPECT_TRUE(transport->unregisterStreamWriteCallback(stream));
wcb.reset();
}));
transport->close(none);
transport->close(std::nullopt);
qEvb->loopOnce();
}
@@ -4253,7 +4253,7 @@ TEST_P(QuicTransportImplTestBase, ObserverDetachAfterClose) {
EXPECT_CALL(*cb, closeStarted(transport.get(), _));
EXPECT_CALL(*cb, closing(transport.get(), _));
transport->close(none);
transport->close(std::nullopt);
Mock::VerifyAndClearExpectations(cb.get());
EXPECT_CALL(*cb, observerDetach(transport.get()));