Skip to content

Commit

Permalink
Implement Delivery callbacks for QuicWebTransport
Browse files Browse the repository at this point in the history
Summary: I'm modifying `QuicWebTransport::sendWebTransportStreamData` so that delivery callbacks are conveyed to the passed-in `DeliveryCallback*` if it is non-`nullptr`.

Reviewed By: hanidamlaj

Differential Revision: D69618959

fbshipit-source-id: 280c8581ed00bf1364f24cfb8f269d7883e872ea
  • Loading branch information
Aman Sharma authored and facebook-github-bot committed Feb 20, 2025
1 parent 0ac22de commit 1ff5e10
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
12 changes: 10 additions & 2 deletions proxygen/lib/http/webtransport/QuicWebTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include <proxygen/lib/http/webtransport/QuicWebTransport.h>
#include <proxygen/lib/http/webtransport/QuicWtDeliveryCallbackWrapper.h>

using FCState = proxygen::WebTransport::FCState;

Expand Down Expand Up @@ -97,9 +98,16 @@ QuicWebTransport::sendWebTransportStreamData(
HTTPCodec::StreamID id,
std::unique_ptr<folly::IOBuf> data,
bool eof,
WebTransport::DeliveryCallback* /* deliveryCallback */) {
DeliveryCallback* deliveryCallback) {
XCHECK(quicSocket_);
auto res = quicSocket_->writeChain(id, std::move(data), eof);
std::unique_ptr<QuicWtDeliveryCallbackWrapper> deliveryCallbackWrapper =
nullptr;
if (deliveryCallback) {
deliveryCallbackWrapper =
std::make_unique<QuicWtDeliveryCallbackWrapper>(deliveryCallback, 0);
}
auto res = quicSocket_->writeChain(
id, std::move(data), eof, deliveryCallbackWrapper.release());
if (!res) {
return folly::makeUnexpected(WebTransport::ErrorCode::GENERIC_ERROR);
}
Expand Down
26 changes: 26 additions & 0 deletions proxygen/lib/http/webtransport/test/QuicWebTransportTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ using namespace proxygen::test;
using namespace testing;
using quic::MockQuicSocketDriver;

class MockDeliveryCallback : public WebTransport::DeliveryCallback {
public:
MOCK_METHOD(void, onDelivery, (uint64_t, uint32_t), (noexcept));

MOCK_METHOD(void, onDeliveryCancelled, (uint64_t, uint32_t), (noexcept));
};

namespace {
const uint32_t WT_ERROR_1 = 19;
const uint32_t WT_ERROR_2 = 77;
Expand Down Expand Up @@ -149,6 +156,25 @@ TEST_F(QuicWebTransportTest, SetPriority) {
eventBase_.loop();
}

TEST_F(QuicWebTransportTest, WriteWithDeliveryCallback) {
auto handle = webTransport()->createUniStream();
EXPECT_TRUE(handle.hasValue());
auto mockCallback = std::make_unique<StrictMock<MockDeliveryCallback>>();

folly::StringPiece data = "test data";

uint64_t expectedStreamId = handle.value()->getID();
uint32_t expectedOffset = data.size();
EXPECT_CALL(*mockCallback, onDelivery(expectedStreamId, expectedOffset))
.Times(1);

handle.value()->writeStreamData(
folly::IOBuf::copyBuffer(data), true, mockCallback.get());
// The MockQuicSocketDriver automatically simulates the delivery of data
// written to the QUIC socket.
eventBase_.loop();
}

// TODO:
//
// new streams with no handler
Expand Down

0 comments on commit 1ff5e10

Please sign in to comment.