mirror of
https://github.com/facebookincubator/mvfst.git
synced 2025-04-18 17:24:03 +03:00
Eliminate usage of folly::io::Appender [2/n]
Summary: When we're writing to a single continuous section of memory (e.g. one created by the `folly::IOBuf` constructor or `folly::IOBuf::create`), we can just use our `BufWriter` from `quic/common/BufUtil.h` instead of using `folly::io::Appender`. Reviewed By: hanidamlaj Differential Revision: D72476189 fbshipit-source-id: 4f8e8b1c27c7d2abe156b7532f678452b32cc91f
This commit is contained in:
parent
a801a8351c
commit
34dc7be5b6
@ -138,14 +138,16 @@ void TakeoverPacketHandler::forwardPacketToAnotherServer(
|
||||
auto bufSize = sizeof(TakeoverProtocolVersion) + sizeof(uint16_t) +
|
||||
peerAddress.getActualSize() + sizeof(uint64_t);
|
||||
Buf writeBuffer = folly::IOBuf::create(bufSize);
|
||||
folly::io::Appender appender(writeBuffer.get(), bufSize);
|
||||
appender.writeBE<uint32_t>(static_cast<uint32_t>(takeoverProtocol_));
|
||||
BufWriter bufWriter(writeBuffer->writableData(), bufSize);
|
||||
bufWriter.writeBE<uint32_t>(folly::to_underlying(takeoverProtocol_));
|
||||
sockaddr_storage addrStorage;
|
||||
uint16_t socklen = peerAddress.getAddress(&addrStorage);
|
||||
appender.writeBE<uint16_t>(socklen);
|
||||
appender.push((uint8_t*)&addrStorage, socklen);
|
||||
bufWriter.writeBE<uint16_t>(socklen);
|
||||
bufWriter.push((uint8_t*)&addrStorage, socklen);
|
||||
uint64_t tick = receiveTimePoint.time_since_epoch().count();
|
||||
appender.writeBE<uint64_t>(tick);
|
||||
bufWriter.writeBE<uint64_t>(tick);
|
||||
writeBuffer->append(bufSize);
|
||||
|
||||
writeBuffer->prependChain(std::move(buf));
|
||||
forwardPacket(std::move(writeBuffer));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user