1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-04-18 17:24:03 +03:00

Use "Buf" typealias instead of "std::unique_ptr<folly::IOBuf>"

Summary: This is a fairly trivial no-op change in which I'm using `Buf` in place of `std::unique_ptr<folly::IOBuf>`.

Reviewed By: hanidamlaj

Differential Revision: D72483588

fbshipit-source-id: 64d05e6d2466e0d09b9a69b5cd19f87970c18fa8
This commit is contained in:
Aman Sharma 2025-04-14 23:08:59 -07:00 committed by Facebook GitHub Bot
parent 34dc7be5b6
commit 5d06f22fdc
25 changed files with 68 additions and 87 deletions

View File

@ -24,9 +24,7 @@ IOBufQuicBatch::IOBufQuicBatch(
statsCallback_(statsCallback),
happyEyeballsState_(happyEyeballsState) {}
bool IOBufQuicBatch::write(
std::unique_ptr<folly::IOBuf>&& buf,
size_t encodedSize) {
bool IOBufQuicBatch::write(Buf&& buf, size_t encodedSize) {
result_.packetsSent++;
result_.bytesSent += encodedSize;

View File

@ -30,7 +30,7 @@ class IOBufQuicBatch {
~IOBufQuicBatch() = default;
// returns true if it succeeds and false if the loop should end
bool write(std::unique_ptr<folly::IOBuf>&& buf, size_t encodedSize);
bool write(Buf&& buf, size_t encodedSize);
bool flush();

View File

@ -19,7 +19,7 @@ void SinglePacketBatchWriter::reset() {
}
bool SinglePacketBatchWriter::append(
std::unique_ptr<folly::IOBuf>&& buf,
Buf&& buf,
size_t /*unused*/,
const folly::SocketAddress& /*unused*/,
QuicAsyncUDPSocket* /*unused*/) {
@ -43,7 +43,7 @@ void SinglePacketInplaceBatchWriter::reset() {
}
bool SinglePacketInplaceBatchWriter::append(
std::unique_ptr<folly::IOBuf>&& /* buf */,
Buf&& /* buf */,
size_t /*unused*/,
const folly::SocketAddress& /*unused*/,
QuicAsyncUDPSocket* /*unused*/) {
@ -94,7 +94,7 @@ void SinglePacketBackpressureBatchWriter::reset() {
}
bool SinglePacketBackpressureBatchWriter::append(
std::unique_ptr<folly::IOBuf>&& buf,
Buf&& buf,
size_t /* unused */,
const folly::SocketAddress& /*unused*/,
QuicAsyncUDPSocket* /*unused*/) {
@ -134,7 +134,7 @@ void SendmmsgPacketBatchWriter::reset() {
}
bool SendmmsgPacketBatchWriter::append(
std::unique_ptr<folly::IOBuf>&& buf,
Buf&& buf,
size_t size,
const folly::SocketAddress& /*unused*/,
QuicAsyncUDPSocket* /*unused*/) {
@ -243,7 +243,7 @@ void SendmmsgInplacePacketBatchWriter::reset() {
}
bool SendmmsgInplacePacketBatchWriter::append(
std::unique_ptr<folly::IOBuf>&& /* buf */,
Buf&& /* buf */,
size_t size,
const folly::SocketAddress& /*unused*/,
QuicAsyncUDPSocket* /*unused*/) {

View File

@ -42,7 +42,7 @@ class BatchWriter {
* writer needs to be flushed
*/
virtual bool append(
std::unique_ptr<folly::IOBuf>&& buf,
Buf&& buf,
size_t bufSize,
const folly::SocketAddress& addr,
QuicAsyncUDPSocket* sock) = 0;
@ -65,7 +65,7 @@ class IOBufBatchWriter : public BatchWriter {
}
protected:
std::unique_ptr<folly::IOBuf> buf_;
Buf buf_;
};
class SinglePacketBatchWriter : public IOBufBatchWriter {
@ -75,7 +75,7 @@ class SinglePacketBatchWriter : public IOBufBatchWriter {
void reset() override;
bool append(
std::unique_ptr<folly::IOBuf>&& buf,
Buf&& buf,
size_t /*unused*/,
const folly::SocketAddress& /*unused*/,
QuicAsyncUDPSocket* /*unused*/) override;
@ -97,7 +97,7 @@ class SinglePacketInplaceBatchWriter : public IOBufBatchWriter {
void reset() override;
bool append(
std::unique_ptr<folly::IOBuf>&& /* buf */,
Buf&& /* buf */,
size_t /*unused*/,
const folly::SocketAddress& /*unused*/,
QuicAsyncUDPSocket* /*unused*/) override;
@ -116,7 +116,7 @@ class SinglePacketBackpressureBatchWriter : public IOBufBatchWriter {
void reset() override;
bool append(
std::unique_ptr<folly::IOBuf>&& buf,
Buf&& buf,
size_t size,
const folly::SocketAddress& /*unused*/,
QuicAsyncUDPSocket* /*unused*/) override;
@ -140,7 +140,7 @@ class SendmmsgPacketBatchWriter : public BatchWriter {
void reset() override;
bool append(
std::unique_ptr<folly::IOBuf>&& buf,
Buf&& buf,
size_t size,
const folly::SocketAddress& /*unused*/,
QuicAsyncUDPSocket* /*unused*/) override;
@ -156,7 +156,7 @@ class SendmmsgPacketBatchWriter : public BatchWriter {
// size of data in all the buffers
size_t currSize_{0};
// array of IOBufs
std::vector<std::unique_ptr<folly::IOBuf>> bufs_;
std::vector<Buf> bufs_;
};
class SendmmsgInplacePacketBatchWriter : public BatchWriter {
@ -172,7 +172,7 @@ class SendmmsgInplacePacketBatchWriter : public BatchWriter {
void reset() override;
bool append(
std::unique_ptr<folly::IOBuf>&& /* buf */,
Buf&& /* buf */,
size_t size,
const folly::SocketAddress& /*unused*/,
QuicAsyncUDPSocket* /*unused*/) override;

View File

@ -35,7 +35,7 @@ bool GSOPacketBatchWriter::needsFlush(size_t size) {
}
bool GSOPacketBatchWriter::append(
std::unique_ptr<folly::IOBuf>&& buf,
Buf&& buf,
size_t size,
const folly::SocketAddress& /*unused*/,
QuicAsyncUDPSocket* /*unused*/) {
@ -104,7 +104,7 @@ bool GSOInplacePacketBatchWriter::needsFlush(size_t size) {
}
bool GSOInplacePacketBatchWriter::append(
std::unique_ptr<folly::IOBuf>&& /*buf*/,
Buf&& /*buf*/,
size_t size,
const folly::SocketAddress& /* addr */,
QuicAsyncUDPSocket* /* sock */) {
@ -235,7 +235,7 @@ void SendmmsgGSOPacketBatchWriter::reset() {
}
bool SendmmsgGSOPacketBatchWriter::append(
std::unique_ptr<folly::IOBuf>&& buf,
Buf&& buf,
size_t size,
const folly::SocketAddress& addr,
QuicAsyncUDPSocket* /*unused*/) {
@ -337,7 +337,7 @@ void SendmmsgGSOInplacePacketBatchWriter::reset() {
}
bool SendmmsgGSOInplacePacketBatchWriter::append(
std::unique_ptr<folly::IOBuf>&& /* buf */,
Buf&& /* buf */,
size_t size,
const folly::SocketAddress& addr,
QuicAsyncUDPSocket* /*unused*/) {

View File

@ -20,7 +20,7 @@ class GSOPacketBatchWriter : public IOBufBatchWriter {
void reset() override;
bool needsFlush(size_t size) override;
bool append(
std::unique_ptr<folly::IOBuf>&& buf,
Buf&& buf,
size_t size,
const folly::SocketAddress& /*unused*/,
QuicAsyncUDPSocket* /*unused*/) override;
@ -52,7 +52,7 @@ class GSOInplacePacketBatchWriter : public BatchWriter {
void reset() override;
bool needsFlush(size_t size) override;
bool append(
std::unique_ptr<folly::IOBuf>&& buf,
Buf&& buf,
size_t size,
const folly::SocketAddress& addr,
QuicAsyncUDPSocket* sock) override;
@ -94,7 +94,7 @@ class SendmmsgGSOPacketBatchWriter : public BatchWriter {
void reset() override;
bool append(
std::unique_ptr<folly::IOBuf>&& buf,
Buf&& buf,
size_t size,
const folly::SocketAddress& address,
QuicAsyncUDPSocket* sock) override;
@ -109,7 +109,7 @@ class SendmmsgGSOPacketBatchWriter : public BatchWriter {
// size of data in all the buffers
size_t currSize_{0};
// array of IOBufs
std::vector<std::unique_ptr<folly::IOBuf>> bufs_;
std::vector<Buf> bufs_;
std::vector<QuicAsyncUDPSocket::WriteOptions> options_;
std::vector<size_t> prevSize_;
std::vector<folly::SocketAddress> addrs_;
@ -147,7 +147,7 @@ class SendmmsgGSOInplacePacketBatchWriter : public BatchWriter {
void reset() override;
bool append(
std::unique_ptr<folly::IOBuf>&& buf,
Buf&& buf,
size_t size,
const folly::SocketAddress& address,
QuicAsyncUDPSocket* sock) override;

View File

@ -59,9 +59,7 @@ void ClientHandshake::connect(
}
}
void ClientHandshake::doHandshake(
std::unique_ptr<folly::IOBuf> data,
EncryptionLevel encryptionLevel) {
void ClientHandshake::doHandshake(Buf data, EncryptionLevel encryptionLevel) {
if (!data) {
return;
}

View File

@ -43,9 +43,7 @@ class ClientHandshake : public Handshake {
* This can change the state of the transport which may result in ciphers
* being initialized, bytes written out, or the write phase changing.
*/
virtual void doHandshake(
std::unique_ptr<folly::IOBuf> data,
EncryptionLevel encryptionLevel);
virtual void doHandshake(Buf data, EncryptionLevel encryptionLevel);
/**
* Provides facilities to get, put and remove a PSK from the cache in case the

View File

@ -1208,7 +1208,7 @@ folly::Expected<QuicFrame, QuicError> parseFrame(
folly::Expected<RegularQuicPacket, QuicError> decodeRegularPacket(
PacketHeader&& header,
const CodecParameters& params,
std::unique_ptr<folly::IOBuf> packetData) {
Buf packetData) {
RegularQuicPacket packet(std::move(header));
BufQueue queue;
queue.append(std::move(packetData));

View File

@ -71,7 +71,7 @@ Optional<VersionNegotiationPacket> decodeVersionNegotiation(
[[nodiscard]] folly::Expected<RegularQuicPacket, QuicError> decodeRegularPacket(
PacketHeader&& header,
const CodecParameters& params,
std::unique_ptr<folly::IOBuf> packetData);
Buf packetData);
/**
* Parses a single frame from the queue. Throws a QuicException if the frame

View File

@ -191,15 +191,13 @@ void RegularQuicPacketBuilder::appendBytes(
remainingBytes_ -= byteNumber;
}
void RegularQuicPacketBuilder::insert(std::unique_ptr<folly::IOBuf> buf) {
void RegularQuicPacketBuilder::insert(Buf buf) {
remainingBytes_ -= buf->computeChainDataLength();
bodyAppender_.insert(std::move(buf));
}
void RegularQuicPacketBuilder::insert(
std::unique_ptr<folly::IOBuf> buf,
size_t limit) {
std::unique_ptr<folly::IOBuf> streamData;
void RegularQuicPacketBuilder::insert(Buf buf, size_t limit) {
Buf streamData;
folly::io::Cursor cursor(buf.get());
cursor.clone(streamData, limit);
// reminaingBytes_ update is taken care of inside this insert call:
@ -207,7 +205,7 @@ void RegularQuicPacketBuilder::insert(
}
void RegularQuicPacketBuilder::insert(const BufQueue& buf, size_t limit) {
std::unique_ptr<folly::IOBuf> streamData;
Buf streamData;
folly::io::Cursor cursor(buf.front());
cursor.clone(streamData, limit);
// reminaingBytes_ update is taken care of inside this insert call:
@ -218,7 +216,7 @@ void RegularQuicPacketBuilder::insert(
const ChainedByteRangeHead& buf,
size_t limit) {
limit = std::min(limit, buf.chainLength());
std::unique_ptr<folly::IOBuf> streamData = folly::IOBuf::wrapBuffer(
Buf streamData = folly::IOBuf::wrapBuffer(
buf.getHead()->getRange().begin(),
std::min(limit, buf.getHead()->length()));
limit -= std::min(limit, buf.getHead()->length());
@ -685,14 +683,12 @@ void InplaceQuicPacketBuilder::appendBytes(
remainingBytes_ -= byteNumber;
}
void InplaceQuicPacketBuilder::insert(std::unique_ptr<folly::IOBuf> buf) {
void InplaceQuicPacketBuilder::insert(Buf buf) {
remainingBytes_ -= buf->computeChainDataLength();
bufWriter_.insert(buf.get());
}
void InplaceQuicPacketBuilder::insert(
std::unique_ptr<folly::IOBuf> buf,
size_t limit) {
void InplaceQuicPacketBuilder::insert(Buf buf, size_t limit) {
remainingBytes_ -= limit;
bufWriter_.insert(buf.get(), limit);
}

View File

@ -74,8 +74,8 @@ class PacketBuilderInterface {
appendBytes(BufAppender& appender, PacketNum value, uint8_t byteNumber) = 0;
virtual void
appendBytes(BufWriter& writer, PacketNum value, uint8_t byteNumber) = 0;
virtual void insert(std::unique_ptr<folly::IOBuf> buf) = 0;
virtual void insert(std::unique_ptr<folly::IOBuf> buf, size_t limit) = 0;
virtual void insert(Buf buf) = 0;
virtual void insert(Buf buf, size_t limit) = 0;
virtual void insert(const ChainedByteRangeHead& buf, size_t limit) = 0;
virtual void insert(const BufQueue& buf, size_t limit) = 0;
virtual void push(const uint8_t* data, size_t len) = 0;
@ -148,8 +148,8 @@ class InplaceQuicPacketBuilder final : public PacketBuilderInterface {
void appendBytes(BufWriter& writer, PacketNum value, uint8_t byteNumber)
override;
void insert(std::unique_ptr<folly::IOBuf> buf) override;
void insert(std::unique_ptr<folly::IOBuf> buf, size_t limit) override;
void insert(Buf buf) override;
void insert(Buf buf, size_t limit) override;
void insert(const ChainedByteRangeHead& buf, size_t limit) override;
void insert(const BufQueue& buf, size_t limit) override;
void push(const uint8_t* data, size_t len) override;
@ -230,8 +230,8 @@ class RegularQuicPacketBuilder final : public PacketBuilderInterface {
CHECK(false) << "Invalid BufWriter";
}
void insert(std::unique_ptr<folly::IOBuf> buf) override;
void insert(std::unique_ptr<folly::IOBuf> buf, size_t limit) override;
void insert(Buf buf) override;
void insert(Buf buf, size_t limit) override;
void insert(const BufQueue& buf, size_t limit) override;
void insert(const ChainedByteRangeHead& buf, size_t limit) override;
@ -383,7 +383,7 @@ class VersionNegotiationPacketBuilder {
private:
uint32_t remainingBytes_;
VersionNegotiationPacket packet_;
std::unique_ptr<folly::IOBuf> data_;
Buf data_;
};
/*
@ -457,7 +457,7 @@ class StatelessResetPacketBuilder {
Buf buildPacket() &&;
private:
std::unique_ptr<folly::IOBuf> data_;
Buf data_;
};
/**
@ -520,11 +520,11 @@ class PacketBuilderWrapper : public PacketBuilderInterface {
builder.appendBytes(writer, value, byteNumber);
}
void insert(std::unique_ptr<folly::IOBuf> buf) override {
void insert(Buf buf) override {
builder.insert(std::move(buf));
}
void insert(std::unique_ptr<folly::IOBuf> buf, size_t limit) override {
void insert(Buf buf, size_t limit) override {
builder.insert(std::move(buf), limit);
}

View File

@ -9,7 +9,7 @@
namespace quic {
size_t fillIovec(std::unique_ptr<folly::IOBuf>& buf, iovec (&vec)[16]) {
size_t fillIovec(Buf& buf, iovec (&vec)[16]) {
size_t iovec_len = buf->fillIov(vec, sizeof(vec) / sizeof(vec[0])).numIovecs;
if (FOLLY_UNLIKELY(iovec_len == 0)) {
buf->coalesce();
@ -64,7 +64,7 @@ Buf BufQueue::splitAtMost(size_t len) {
}
// update chain_
(void)chain_.release();
chain_ = std::unique_ptr<folly::IOBuf>(current);
chain_ = Buf(current);
DCHECK_EQ(chainLength_, chain_ ? chain_->computeChainDataLength() : 0);
return result;
}
@ -148,7 +148,7 @@ void BufAppender::push(const uint8_t* data, size_t len) {
lastBufShared_ = false;
}
void BufAppender::insert(std::unique_ptr<folly::IOBuf> data) {
void BufAppender::insert(Buf data) {
// just skip the current buffer and append it to the end of the current
// buffer.
folly::IOBuf* dataPtr = data.get();

View File

@ -13,7 +13,7 @@
namespace quic {
size_t fillIovec(std::unique_ptr<folly::IOBuf>& buf, iovec (&vec)[16]);
size_t fillIovec(Buf& buf, iovec (&vec)[16]);
class BufQueue {
public:
@ -89,7 +89,7 @@ class BufAppender {
void push(const uint8_t* data, size_t len);
void insert(std::unique_ptr<folly::IOBuf> data);
void insert(Buf data);
private:
folly::IOBuf* crtBuf_;

View File

@ -148,8 +148,8 @@ struct NetworkData {
return totalData_;
}
std::unique_ptr<folly::IOBuf> moveAllData() && {
std::unique_ptr<folly::IOBuf> buf;
Buf moveAllData() && {
Buf buf;
for (auto& packet : packets_) {
if (buf) {
buf->prependChain(packet.buf.move());

View File

@ -86,7 +86,7 @@ ssize_t FollyQuicAsyncUDPSocket::writeGSO(
int FollyQuicAsyncUDPSocket::writemGSO(
folly::Range<folly::SocketAddress const*> addrs,
const std::unique_ptr<folly::IOBuf>* bufs,
const Buf* bufs,
size_t count,
const WriteOptions* options) {
std::vector<folly::AsyncUDPSocket::WriteOptions> follyOptions(count);

View File

@ -88,7 +88,7 @@ class FollyQuicAsyncUDPSocket : public QuicAsyncUDPSocketImpl {
/**
* Send the data in buffers to destination. Returns the return code from
* ::sendmmsg.
* bufs is an array of std::unique_ptr<folly::IOBuf>
* bufs is an array of Buf
* of size num
* options is an array of WriteOptions or nullptr
* Before calling writeGSO with a positive value
@ -96,7 +96,7 @@ class FollyQuicAsyncUDPSocket : public QuicAsyncUDPSocketImpl {
*/
int writemGSO(
folly::Range<folly::SocketAddress const*> addrs,
const std::unique_ptr<folly::IOBuf>* bufs,
const Buf* bufs,
size_t count,
const WriteOptions* options) override;

View File

@ -58,7 +58,7 @@ class LibevQuicAsyncUDPSocket : public QuicAsyncUDPSocketImpl {
/**
* Send the data in buffers to destination. Returns the return code from
* ::sendmmsg.
* bufs is an array of std::unique_ptr<folly::IOBuf>
* bufs is an array of Buf
* of size num
* options is an array of WriteOptions or nullptr
* Before calling writeGSO with a positive value
@ -66,7 +66,7 @@ class LibevQuicAsyncUDPSocket : public QuicAsyncUDPSocketImpl {
*/
int writemGSO(
folly::Range<folly::SocketAddress const*> /*addrs*/,
const std::unique_ptr<folly::IOBuf>* /*bufs*/,
const Buf* /*bufs*/,
size_t /*count*/,
const WriteOptions* /*options*/) override {
LOG(FATAL) << __func__ << " not supported in LibevQuicAsyncUDPSocket";

View File

@ -210,7 +210,7 @@ class QuicAsyncUDPSocket {
/**
* Send the data in buffers to destination. Returns the return code from
* ::sendmmsg.
* bufs is an array of std::unique_ptr<folly::IOBuf>
* bufs is an array of Buf
* of size num
* options is an array of WriteOptions or nullptr
* Before calling writeGSO with a positive value
@ -218,7 +218,7 @@ class QuicAsyncUDPSocket {
*/
virtual int writemGSO(
folly::Range<folly::SocketAddress const*> addrs,
const std::unique_ptr<folly::IOBuf>* bufs,
const Buf* bufs,
size_t count,
const WriteOptions* options) = 0;

View File

@ -57,7 +57,7 @@ class CipherBuilder {
CipherPair buildCiphers(
fizz::TrafficKey&& trafficKey,
fizz::CipherSuite cipherSuite,
std::unique_ptr<folly::IOBuf> packetProtectionKey) {
Buf packetProtectionKey) {
auto aead = FizzAead::wrap(deriveRecordAeadWithLabel(
*quicFizzCryptoFactory_.getFizzFactory(),
std::move(trafficKey),
@ -86,7 +86,7 @@ class QuicPacketizer {
public:
virtual ~QuicPacketizer() = default;
virtual std::unique_ptr<folly::IOBuf> sendQuicPacket(
virtual Buf sendQuicPacket(
ConnectionId dcid,
const folly::SocketAddress& clientAddr,
PacketNum packetNum,

View File

@ -67,7 +67,7 @@ Optional<StatelessResetToken> getStatelessResetTokenParameter(
TransportParameter encodeIntegerParameter(
TransportParameterId id,
uint64_t value) {
std::unique_ptr<folly::IOBuf> data = folly::IOBuf::create(8);
Buf data = folly::IOBuf::create(8);
BufAppender appender(data.get(), 8);
auto encoded = encodeQuicInteger(
value, [appender = std::move(appender)](auto val) mutable {

View File

@ -531,7 +531,7 @@ void QuicServerWorker::handleNetworkData(
void QuicServerWorker::recvmsgMultishotCallback(
MultishotHdr* hdr,
int res,
std::unique_ptr<folly::IOBuf> io_buf) {
Buf io_buf) {
if (res < 0) {
return;
}

View File

@ -146,10 +146,8 @@ class QuicServerWorker : public FollyAsyncUDPSocketAlias::ReadCallback,
delete m;
}
static void cb(
folly::EventRecvmsgMultishotCallback::Hdr* h,
int res,
std::unique_ptr<folly::IOBuf> io_buf) {
static void
cb(folly::EventRecvmsgMultishotCallback::Hdr* h, int res, Buf io_buf) {
reinterpret_cast<QuicServerWorker*>(h->arg_)->recvmsgMultishotCallback(
reinterpret_cast<MultishotHdr*>(h), res, std::move(io_buf));
}
@ -587,10 +585,7 @@ class QuicServerWorker : public FollyAsyncUDPSocketAlias::ReadCallback,
std::string logRoutingInfo(const ConnectionId& connId) const;
void eventRecvmsgCallback(MsgHdr* msgHdr, int res);
void recvmsgMultishotCallback(
MultishotHdr* msgHdr,
int res,
std::unique_ptr<folly::IOBuf> io_buf);
void recvmsgMultishotCallback(MultishotHdr* msgHdr, int res, Buf io_buf);
bool hasTimestamping() {
return (socket_ && (socket_->getTimestamping() > 0));

View File

@ -33,9 +33,7 @@ void ServerHandshake::initialize(
initializeImpl(callback, std::move(validator));
}
void ServerHandshake::doHandshake(
std::unique_ptr<folly::IOBuf> data,
EncryptionLevel encryptionLevel) {
void ServerHandshake::doHandshake(Buf data, EncryptionLevel encryptionLevel) {
SCOPE_EXIT {
inHandshakeStack_ = false;
};

View File

@ -92,9 +92,7 @@ class ServerHandshake : public Handshake {
* Performs the handshake, after a handshake you should check whether or
* not an event is available.
*/
virtual void doHandshake(
std::unique_ptr<folly::IOBuf> data,
EncryptionLevel encryptionLevel);
virtual void doHandshake(Buf data, EncryptionLevel encryptionLevel);
/**
* Writes a session ticket on the connection.