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

Getter API of Quic stream priority

Summary: as title

Reviewed By: afrind, avasylev

Differential Revision: D26744365

fbshipit-source-id: 5c5d104ca76c77f14371c20d6f791fca8d7cfe38
This commit is contained in:
Yang Chi
2021-03-02 19:38:43 -08:00
committed by Facebook GitHub Bot
parent 6f63fa59ca
commit 0b42e07216
6 changed files with 40 additions and 1 deletions

View File

@@ -17,6 +17,7 @@
#include <quic/codec/Types.h> #include <quic/codec/Types.h>
#include <quic/common/SmallVec.h> #include <quic/common/SmallVec.h>
#include <quic/state/QuicConnectionStats.h> #include <quic/state/QuicConnectionStats.h>
#include <quic/state/QuicPriorityQueue.h>
#include <quic/state/StateData.h> #include <quic/state/StateData.h>
#include <chrono> #include <chrono>
@@ -458,6 +459,12 @@ class QuicSocket {
virtual folly::Expected<folly::Unit, LocalErrorCode> virtual folly::Expected<folly::Unit, LocalErrorCode>
setStreamPriority(StreamId id, PriorityLevel level, bool incremental) = 0; setStreamPriority(StreamId id, PriorityLevel level, bool incremental) = 0;
/**
* Get stream priority.
*/
virtual folly::Expected<Priority, LocalErrorCode> getStreamPriority(
StreamId id) = 0;
/** /**
* ===== Read API ==== * ===== Read API ====
*/ */

View File

@@ -2999,6 +2999,18 @@ QuicTransportBase::setStreamPriority(
return folly::unit; return folly::unit;
} }
folly::Expected<Priority, LocalErrorCode> QuicTransportBase::getStreamPriority(
StreamId id) {
if (closeState_ != CloseState::OPEN) {
return folly::makeUnexpected(LocalErrorCode::CONNECTION_CLOSED);
}
auto stream = conn_->streamManager->findStream(id);
if (!stream) {
return folly::makeUnexpected(LocalErrorCode::STREAM_NOT_EXISTS);
}
return stream->priority;
}
void QuicTransportBase::validateCongestionAndPacing( void QuicTransportBase::validateCongestionAndPacing(
CongestionControlType& type) { CongestionControlType& type) {
// Fallback to Cubic if Pacing isn't enabled with BBR together // Fallback to Cubic if Pacing isn't enabled with BBR together

View File

@@ -323,6 +323,9 @@ class QuicTransportBase : public QuicSocket {
PriorityLevel level, PriorityLevel level,
bool incremental) override; bool incremental) override;
folly::Expected<Priority, LocalErrorCode> getStreamPriority(
StreamId id) override;
/** /**
* Invoke onCanceled on all the delivery callbacks registered for streamId. * Invoke onCanceled on all the delivery callbacks registered for streamId.
*/ */

View File

@@ -99,6 +99,9 @@ class MockQuicSocket : public QuicSocket {
MOCK_METHOD3( MOCK_METHOD3(
setStreamPriority, setStreamPriority,
folly::Expected<folly::Unit, LocalErrorCode>(StreamId, uint8_t, bool)); folly::Expected<folly::Unit, LocalErrorCode>(StreamId, uint8_t, bool));
MOCK_METHOD1(
getStreamPriority,
folly::Expected<Priority, LocalErrorCode>(StreamId));
MOCK_METHOD3( MOCK_METHOD3(
setReadCallback, setReadCallback,
folly::Expected<folly::Unit, LocalErrorCode>( folly::Expected<folly::Unit, LocalErrorCode>(

View File

@@ -3265,5 +3265,19 @@ TEST_F(QuicTransportTest, GetStreamPacketsTxedMultiplePackets) {
Mock::VerifyAndClearExpectations(&lastByteTxCb); Mock::VerifyAndClearExpectations(&lastByteTxCb);
} }
TEST_F(QuicTransportTest, PrioritySetAndGet) {
auto stream = transport_->createBidirectionalStream().value();
EXPECT_EQ(kDefaultPriority, transport_->getStreamPriority(stream).value());
transport_->setStreamPriority(stream, 0, false);
EXPECT_EQ(Priority(0, false), transport_->getStreamPriority(stream).value());
auto nonExistStreamPri = transport_->getStreamPriority(stream + 4);
EXPECT_TRUE(nonExistStreamPri.hasError());
EXPECT_EQ(LocalErrorCode::STREAM_NOT_EXISTS, nonExistStreamPri.error());
transport_->close(folly::none);
auto closedConnStreamPri = transport_->getStreamPriority(stream);
EXPECT_TRUE(closedConnStreamPri.hasError());
EXPECT_EQ(LocalErrorCode::CONNECTION_CLOSED, closedConnStreamPri.error());
}
} // namespace test } // namespace test
} // namespace quic } // namespace quic

View File

@@ -19,7 +19,7 @@ struct Priority {
Priority(uint8_t l, bool i) : level(l), incremental(i) {} Priority(uint8_t l, bool i) : level(l), incremental(i) {}
bool operator==(Priority other) { bool operator==(Priority other) const noexcept {
return level == other.level && incremental == other.incremental; return level == other.level && incremental == other.incremental;
} }
}; };