1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-08-01 01:44:22 +03:00

folly::to<std::string> -> fmt::format

Reviewed By: sharmafb

Differential Revision: D74672231

fbshipit-source-id: d8f4fc542de10f26cf06df7ca42518865e8bba3a
This commit is contained in:
Konstantin Tsoy
2025-05-14 08:46:52 -07:00
committed by Facebook GitHub Bot
parent 731de1fd72
commit 813f6a6cd1
30 changed files with 147 additions and 196 deletions

View File

@ -37,7 +37,7 @@ QuicInternalException::QuicInternalException(
QuicInternalException::QuicInternalException(
folly::StringPiece msg,
LocalErrorCode errCode)
: std::runtime_error(folly::to<std::string>(msg)), errorCode_(errCode) {}
: std::runtime_error(fmt::format("{}", msg)), errorCode_(errCode) {}
QuicApplicationException::QuicApplicationException(
const std::string& msg,
@ -236,7 +236,7 @@ std::string toString(QuicErrorCode code) {
GenericApplicationErrorCode::NO_ERROR) {
return "No Error";
}
return folly::to<std::string>(*code.asApplicationErrorCode());
return fmt::format("{}", *code.asApplicationErrorCode());
case QuicErrorCode::Type::LocalErrorCode:
return toString(*code.asLocalErrorCode()).str();
case QuicErrorCode::Type::TransportErrorCode:
@ -254,15 +254,14 @@ std::string toString(const QuicError& error) {
break;
case QuicErrorCode::Type::LocalErrorCode:
err = "LocalError: " +
folly::to<std::string>(toString(*error.code.asLocalErrorCode())) +
", ";
fmt::format("{}, ", toString(*error.code.asLocalErrorCode()));
break;
case QuicErrorCode::Type::TransportErrorCode:
err = "TransportError: " + toString(*error.code.asTransportErrorCode()) +
", ";
}
if (!error.message.empty()) {
err = folly::to<std::string>(err, error.message);
err = fmt::format("{}{}", err, error.message);
}
return err;
}

View File

@ -138,14 +138,13 @@ folly::Expected<bool, QuicError> IOBufQuicBatch::flushInternal() {
(happyEyeballsState_ && !happyEyeballsState_->shouldWriteToFirstSocket &&
!happyEyeballsState_->shouldWriteToSecondSocket)) {
auto firstSocketErrorMsg = firstSocketErrno.has_value()
? folly::to<std::string>(
folly::errnoStr(firstSocketErrno.value()), ", ")
? fmt::format("{}, ", folly::errnoStr(firstSocketErrno.value()))
: "";
auto secondSocketErrorMsg = secondSocketErrno.has_value()
? folly::errnoStr(secondSocketErrno.value())
: "";
auto errorMsg =
folly::to<std::string>(firstSocketErrorMsg, secondSocketErrorMsg);
fmt::format("{}{}", firstSocketErrorMsg, secondSocketErrorMsg);
// Both sockets becomes fatal, close connection
VLOG(4) << "Error writing to the socket " << errorMsg << " "
<< peerAddress_;
@ -155,11 +154,11 @@ folly::Expected<bool, QuicError> IOBufQuicBatch::flushInternal() {
if (isNetworkUnreachable(errno)) {
return folly::makeUnexpected(QuicError(
LocalErrorCode::CONNECTION_ABANDONED,
folly::to<std::string>("Error on socket write ", errorMsg)));
fmt::format("Error on socket write {}", errorMsg)));
} else {
return folly::makeUnexpected(QuicError(
TransportErrorCode::INTERNAL_ERROR,
folly::to<std::string>("Error on socket write ", errorMsg)));
fmt::format("Error on socket write {}", errorMsg)));
}
}

View File

@ -52,8 +52,8 @@ void QuicStreamAsyncTransport::setStreamId(quic::StreamId id) {
if (streamWriteOffset.hasError()) {
folly::AsyncSocketException ex(
folly::AsyncSocketException::INTERNAL_ERROR,
folly::to<std::string>(
"QuicSocket::getStreamWriteOffset error: ",
fmt::format(
"QuicSocket::getStreamWriteOffset error: {}",
toString(streamWriteOffset.error())));
closeNowImpl(std::move(ex));
return;
@ -328,7 +328,7 @@ void QuicStreamAsyncTransport::readError(
QuicError error) noexcept {
ex_ = folly::AsyncSocketException(
folly::AsyncSocketException::UNKNOWN,
folly::to<std::string>("Quic read error: ", toString(error)));
fmt::format("Quic read error: {}", toString(error)));
sock_->getEventBase()->runInLoop(this, true);
// TODO: RST here?
}
@ -360,7 +360,7 @@ void QuicStreamAsyncTransport::handleRead() {
if (readData.hasError()) {
ex_ = folly::AsyncSocketException(
folly::AsyncSocketException::UNKNOWN,
folly::to<std::string>("Quic read error: ", readData.error()));
fmt::format("Quic read error: {}", toString(readData.error())));
} else {
if (!readData->first) {
emptyRead = true;
@ -423,7 +423,7 @@ void QuicStreamAsyncTransport::send(uint64_t maxToSend) {
if (res.hasError()) {
folly::AsyncSocketException ex(
folly::AsyncSocketException::UNKNOWN,
folly::to<std::string>("Quic write error: ", toString(res.error())));
fmt::format("Quic write error: {}", toString(res.error())));
failWrites(ex);
return;
}
@ -435,7 +435,7 @@ void QuicStreamAsyncTransport::send(uint64_t maxToSend) {
if (!res2) {
folly::AsyncSocketException ex(
folly::AsyncSocketException::UNKNOWN,
folly::to<std::string>("Quic write error: ", toString(res2.error())));
fmt::format("Quic write error: {}", toString(res2.error())));
failWrites(ex);
return;
}
@ -490,7 +490,7 @@ void QuicStreamAsyncTransport::onStreamWriteError(
if (writeEOF_ != EOFState::DELIVERED) {
closeNowImpl(folly::AsyncSocketException(
folly::AsyncSocketException::UNKNOWN,
folly::to<std::string>("Quic write error: ", toString(error))));
fmt::format("Quic write error: {}", toString(error))));
}
}

View File

@ -1198,7 +1198,7 @@ void QuicTransportBaseLite::checkForClosedStream() {
VLOG(10) << "Closing stream=" << *itr;
if (conn_->qLogger) {
conn_->qLogger->addTransportStateUpdate(
getClosingStream(folly::to<std::string>(*itr)));
getClosingStream(fmt::format("{}", *itr)));
}
if (connCallback_) {
connCallback_->onStreamPreReaped(*itr);
@ -1531,12 +1531,10 @@ void QuicTransportBaseLite::closeImpl(
sendCloseImmediately);
}
} else if (conn_->qLogger) {
auto reason = folly::to<std::string>(
"Server: ",
auto reason = fmt::format(
"Server: {}, Peer: isReset: {}, Peer: isAbandon: {}",
kNoError,
", Peer: isReset: ",
isReset,
", Peer: isAbandon: ",
isAbandon);
conn_->qLogger->addConnectionClose(
kNoError, std::move(reason), drainConnection, sendCloseImmediately);
@ -2299,9 +2297,9 @@ void QuicTransportBaseLite::idleTimeoutExpired(bool drain) noexcept {
closeImpl(
quic::QuicError(
QuicErrorCode(localError),
folly::to<std::string>(
fmt::format(
"{}, num non control streams: {}",
toString(localError),
", num non control streams: ",
numOpenStreans - conn_->streamManager->numControlStreams())),
drain /* drainConnection */,
!drain /* sendCloseImmediately */);

View File

@ -45,43 +45,37 @@ std::string optionalToString(const quic::Optional<quic::PacketNum>& packetNum) {
if (!packetNum) {
return "-";
}
return folly::to<std::string>(*packetNum);
return fmt::format("{}", *packetNum);
}
std::string largestAckScheduledToString(
const quic::QuicConnectionStateBase& conn) noexcept {
return folly::to<std::string>(
"[",
return fmt::format(
"[{},{},{}]",
optionalToString(
conn.ackStates.initialAckState
? conn.ackStates.initialAckState->largestAckScheduled
: std::nullopt),
",",
optionalToString(
conn.ackStates.handshakeAckState
? conn.ackStates.handshakeAckState->largestAckScheduled
: std::nullopt),
",",
optionalToString(conn.ackStates.appDataAckState.largestAckScheduled),
"]");
optionalToString(conn.ackStates.appDataAckState.largestAckScheduled));
}
std::string largestAckToSendToString(
const quic::QuicConnectionStateBase& conn) noexcept {
return folly::to<std::string>(
"[",
return fmt::format(
"[{},{},{}]",
optionalToString(
conn.ackStates.initialAckState
? largestAckToSend(*conn.ackStates.initialAckState)
: std::nullopt),
",",
optionalToString(
conn.ackStates.handshakeAckState
? largestAckToSend(*conn.ackStates.handshakeAckState)
: std::nullopt),
",",
optionalToString(largestAckToSend(conn.ackStates.appDataAckState)),
"]");
optionalToString(largestAckToSend(conn.ackStates.appDataAckState)));
}
using namespace quic;

View File

@ -49,7 +49,7 @@ void QuicClientAsyncTransport::onConnectionEnd() noexcept {
void QuicClientAsyncTransport::onConnectionError(QuicError error) noexcept {
folly::AsyncSocketException ex(
folly::AsyncSocketException::UNKNOWN,
folly::to<std::string>("Quic connection error", error.message));
fmt::format("Quic connection error {}", error.message));
// TODO: closeNow inside this callback may actually trigger graceful close
closeNowImpl(std::move(ex));
}

View File

@ -679,8 +679,8 @@ QuicClientTransportLite::processUdpPacketData(
}
case QuicFrame::Type::ConnectionCloseFrame: {
ConnectionCloseFrame& connFrame = *quicFrame.asConnectionCloseFrame();
auto errMsg = folly::to<std::string>(
"Client closed by peer reason=", connFrame.reasonPhrase);
auto errMsg = fmt::format(
"Client closed by peer reason={}", connFrame.reasonPhrase);
VLOG(4) << errMsg << " " << *this;
// we want to deliver app callbacks with the peer supplied error,
// but send a NO_ERROR to the peer.
@ -1347,8 +1347,8 @@ folly::Expected<folly::Unit, QuicError> QuicClientTransportLite::recvMsg(
if (familyResult.hasError()) {
return folly::makeUnexpected(QuicError(
QuicErrorCode(TransportErrorCode::INTERNAL_ERROR),
folly::to<std::string>(
"Failed to get address family: ",
fmt::format(
"Failed to get address family: {}",
familyResult.error().message)));
}
rawAddr->sa_family = familyResult.value();
@ -1424,8 +1424,8 @@ folly::Expected<folly::Unit, QuicError> QuicClientTransportLite::recvMsg(
}
return folly::makeUnexpected(QuicError(
QuicErrorCode(LocalErrorCode::CONNECTION_ABANDONED),
folly::to<std::string>(
"recvmsg() failed, errno=", errno, " ", folly::errnoStr(errno))));
fmt::format(
"recvmsg() failed, errno={} {}", errno, folly::errnoStr(errno))));
} else if (ret == 0) {
break;
}
@ -1522,8 +1522,8 @@ folly::Expected<folly::Unit, QuicError> QuicClientTransportLite::recvFrom(
if (familyResult.hasError()) {
return folly::makeUnexpected(QuicError(
QuicErrorCode(TransportErrorCode::INTERNAL_ERROR),
folly::to<std::string>(
"Failed to get address family: ",
fmt::format(
"Failed to get address family: {}",
familyResult.error().message)));
}
rawAddr->sa_family = familyResult.value();
@ -1547,10 +1547,9 @@ folly::Expected<folly::Unit, QuicError> QuicClientTransportLite::recvFrom(
}
return folly::makeUnexpected(QuicError(
QuicErrorCode(TransportErrorCode::INTERNAL_ERROR),
folly::to<std::string>(
"recvfrom() failed, errno=",
fmt::format(
"recvfrom() failed, errno={} {}",
errno,
" ",
folly::errnoStr(errno))));
} else if (ret == 0) {
break;
@ -1587,8 +1586,8 @@ folly::Expected<folly::Unit, QuicError> QuicClientTransportLite::recvMmsg(
if (groResult.hasError()) {
return folly::makeUnexpected(QuicError(
QuicErrorCode(TransportErrorCode::INTERNAL_ERROR),
folly::to<std::string>(
"Failed to get GRO status: ", groResult.error().message)));
fmt::format(
"Failed to get GRO status: {}", groResult.error().message)));
}
bool useGRO = groResult.value() > 0;
@ -1596,8 +1595,9 @@ folly::Expected<folly::Unit, QuicError> QuicClientTransportLite::recvMmsg(
if (tsResult.hasError()) {
return folly::makeUnexpected(QuicError(
QuicErrorCode(TransportErrorCode::INTERNAL_ERROR),
folly::to<std::string>(
"Failed to get timestamping status: ", tsResult.error().message)));
fmt::format(
"Failed to get timestamping status: {}",
tsResult.error().message)));
}
bool useTs = tsResult.value() > 0;
@ -1605,8 +1605,8 @@ folly::Expected<folly::Unit, QuicError> QuicClientTransportLite::recvMmsg(
if (tosResult.hasError()) {
return folly::makeUnexpected(QuicError(
QuicErrorCode(TransportErrorCode::INTERNAL_ERROR),
folly::to<std::string>(
"Failed to get TOS status: ", tosResult.error().message)));
fmt::format(
"Failed to get TOS status: {}", tosResult.error().message)));
}
bool recvTos = tosResult.value();
@ -1641,8 +1641,8 @@ folly::Expected<folly::Unit, QuicError> QuicClientTransportLite::recvMmsg(
if (addrResult.hasError()) {
return folly::makeUnexpected(QuicError(
QuicErrorCode(TransportErrorCode::INTERNAL_ERROR),
folly::to<std::string>(
"Failed to get socket address: ", addrResult.error().message)));
fmt::format(
"Failed to get socket address: {}", addrResult.error().message)));
}
rawAddr->sa_family = addrResult.value().getFamily();
msg->msg_name = rawAddr;
@ -1673,8 +1673,8 @@ folly::Expected<folly::Unit, QuicError> QuicClientTransportLite::recvMmsg(
}
return folly::makeUnexpected(QuicError(
QuicErrorCode(TransportErrorCode::INTERNAL_ERROR),
folly::to<std::string>(
"recvmmsg() failed, errno=", errno, " ", folly::errnoStr(errno))));
fmt::format(
"recvmmsg() failed, errno={} {}", errno, folly::errnoStr(errno))));
}
CHECK_LE(numMsgsRecvd, numPackets);

View File

@ -307,8 +307,8 @@ folly::Expected<folly::Unit, QuicError> processServerInitialParams(
if (*packetSize < kMinMaxUDPPayload) {
return folly::makeUnexpected(QuicError(
TransportErrorCode::TRANSPORT_PARAMETER_ERROR,
folly::to<std::string>(
"Max packet size too small. received max_packetSize = ",
fmt::format(
"Max packet size too small. received max_packetSize = {}",
*packetSize)));
}

View File

@ -1198,7 +1198,7 @@ folly::Expected<QuicFrame, QuicError> parseFrame(
return folly::makeUnexpected(QuicError(
TransportErrorCode::FRAME_ENCODING_ERROR,
folly::to<std::string>("Unknown frame, type=", frameTypeInt->first)));
fmt::format("Unknown frame, type={}", frameTypeInt->first)));
}
// Parse packet

View File

@ -615,8 +615,8 @@ std::string QuicReadCodec::connIdToHex() const {
static ConnectionId zeroConn = ConnectionId::createZeroLength();
const auto& serverId = serverConnectionId_.value_or(zeroConn);
const auto& clientId = clientConnectionId_.value_or(zeroConn);
return folly::to<std::string>(
"server=", serverId.hex(), " ", "client=", clientId.hex());
return fmt::format(
"server={} client={}", serverId.hex(), "client=", clientId.hex());
}
CodecResult::CodecResult(RegularQuicPacket&& regularPacketIn)

View File

@ -332,13 +332,13 @@ BufPtr QuicAddrValidationToken::getPlaintextToken() const {
}
BufPtr RetryToken::genAeadAssocData() const {
return BufHelpers::copyBuffer(folly::to<std::string>(
toString(tokenType), originalDstConnId.hex() + clientIp.str()));
return BufHelpers::copyBuffer(fmt::format(
"{}{}{}", toString(tokenType), originalDstConnId.hex(), clientIp.str()));
}
BufPtr NewToken::genAeadAssocData() const {
return BufHelpers::copyBuffer(
folly::to<std::string>(toString(tokenType), clientIp.str()));
fmt::format("{}{}", toString(tokenType), clientIp.str()));
}
std::string_view toString(PacketNumberSpace pnSpace) {

View File

@ -511,7 +511,7 @@ TEST(BufWriterTest, BufQueueChainCopyPartial) {
outputBuffer->append(bufWriter.getBytesWritten());
Cursor reader(outputBuffer.get());
EXPECT_EQ(
folly::to<std::string>(testStr1, "That you l"),
fmt::format("{}That you l", testStr1),
reader.readFixedString(testStr1.size() + 10));
}

View File

@ -22,12 +22,11 @@ std::string Bandwidth::unitName() const noexcept {
}
std::string Bandwidth::describe() const noexcept {
return folly::to<std::string>(
units, " ", unitName(), "/", interval.count(), "us");
return fmt::format("{} {}/{}us", units, unitName(), interval.count());
}
std::string Bandwidth::normalizedDescribe() const noexcept {
return folly::to<std::string>(normalize(), " ", unitName(), "/s");
return fmt::format("{} {}/s", normalize(), unitName());
}
bool operator<(const Bandwidth& lhs, const Bandwidth& rhs) {

View File

@ -291,11 +291,11 @@ Handshake::TLSSummary FizzClientHandshake::getTLSSummary() const {
}
if (state_.group().has_value()) {
summary.namedGroup =
folly::to<std::string>(fizz::toString(state_.group().value()));
fmt::format("{}", fizz::toString(state_.group().value()));
}
if (state_.pskType().has_value()) {
summary.pskType =
folly::to<std::string>(fizz::toString(state_.pskType().value()));
fmt::format("{}", fizz::toString(state_.pskType().value()));
}
if (state_.echState().has_value()) {
summary.echStatus =

View File

@ -3142,8 +3142,8 @@ TEST_F(QuicClientTransportAfterStartTest, CloseConnectionWithStreamPending) {
auto tmp2 = std::move(qLogger->logs[indices[1]]);
auto event2 = dynamic_cast<QLogConnectionCloseEvent*>(tmp2.get());
EXPECT_EQ(event2->error, kNoError);
auto reason = folly::to<std::string>(
"Server: ", kNoError, ", Peer: isReset: ", 0, ", Peer: isAbandon: ", 0);
auto reason = fmt::format(
"Server: {}, Peer: isReset: false, Peer: isAbandon: false", kNoError);
EXPECT_EQ(event2->reason, reason);
EXPECT_TRUE(event2->drainConnection);
EXPECT_TRUE(event2->sendCloseImmediately);

View File

@ -193,8 +193,7 @@ folly::Expected<folly::Unit, QuicError> updateFlowControlOnStreamData(
if (stream.flowControlState.advertisedMaxOffset < bufferEndOffset) {
return folly::makeUnexpected(QuicError(
TransportErrorCode::FLOW_CONTROL_ERROR,
folly::to<std::string>(
"Stream flow control violation on stream ", stream.id)));
fmt::format("Stream flow control violation on stream {}", stream.id)));
}
auto curMaxOffsetObserved =
std::max(previousMaxOffsetObserved, bufferEndOffset);

View File

@ -24,8 +24,8 @@ folly::Expected<Optional<uint64_t>, QuicError> getIntegerParameter(
if (!parameter) {
return folly::makeUnexpected(QuicError(
TransportErrorCode::TRANSPORT_PARAMETER_ERROR,
folly::to<std::string>(
"Failed to decode integer from TransportParameterId: ",
fmt::format(
"Failed to decode integer from TransportParameterId: {}",
u64_tp(id))));
}
return Optional<uint64_t>(parameter->first);

View File

@ -37,7 +37,7 @@ void FileQLogger::setupStream() {
endLine_ = prettyJson_ ? "\n" : "";
auto extension = compress_ ? kCompressedQlogExtension : kQlogExtension;
std::string outputPath =
folly::to<std::string>(path_, "/", (dcid.value()).hex(), extension);
fmt::format("{}/{}{}", path_, (dcid.value()).hex(), extension);
try {
writer_ = std::make_unique<folly::AsyncFileWriter>(outputPath);
} catch (const std::system_error& err) {
@ -138,7 +138,7 @@ void FileQLogger::finishStream() {
std::string summaryPadding = "";
// add padding to every line in the summary except the first
while (getline(summaryBuffer, line)) {
writeToStream(folly::to<std::string>(summaryPadding, line, endLine_));
writeToStream(fmt::format("{}{}{}", summaryPadding, line, endLine_));
summaryPadding = basePadding_;
}
writeToStream(folly::StringPiece("}"));
@ -182,7 +182,7 @@ void FileQLogger::handleEvent(std::unique_ptr<QLogEvent> event) {
// add padding to every line in the event
while (getline(eventBuffer, line)) {
writeToStream(endLine_);
writeToStream(folly::to<std::string>(basePadding_, eventsPadding_, line));
writeToStream(fmt::format("{}{}{}", basePadding_, eventsPadding_, line));
}
} else {
@ -549,7 +549,7 @@ void FileQLogger::outputLogsToFile(const std::string& path, bool prettyJson) {
}
auto extension = compress_ ? kCompressedQlogExtension : kQlogExtension;
std::string outputPath =
folly::to<std::string>(path, "/", (dcid.value()).hex(), extension);
fmt::format("{}/{}{}", path, (dcid.value()).hex(), extension);
std::ofstream fileObj(outputPath);
if (fileObj) {

View File

@ -12,32 +12,33 @@
namespace quic {
std::string getFlowControlEvent(int offset) {
return "flow control event, new offset: " + folly::to<std::string>(offset);
return fmt::format("flow control event, new offset: {}", offset);
}
std::string
getRxStreamWU(StreamId streamId, PacketNum packetNum, uint64_t maximumData) {
return "rx stream, streamId: " + folly::to<std::string>(streamId) +
", packetNum: " + folly::to<std::string>(packetNum) +
", maximumData: " + folly::to<std::string>(maximumData);
return fmt::format(
"rx stream, streamId: {}, packetNum: {}, maximumData: {}",
streamId,
packetNum,
maximumData);
}
std::string getRxConnWU(PacketNum packetNum, uint64_t maximumData) {
return "rx, packetNum: " + folly::to<std::string>(packetNum) +
", maximumData: " + folly::to<std::string>(maximumData);
return fmt::format(
"rx, packetNum: {}, maximumData: {}", packetNum, maximumData);
}
std::string getPeerClose(const std::string& peerCloseReason) {
return "error message: " + peerCloseReason;
return fmt::format("error message: {}", peerCloseReason);
}
std::string getFlowControlWindowAvailable(uint64_t windowAvailable) {
return "on flow control, window available: " +
folly::to<std::string>(windowAvailable);
return fmt::format("on flow control, window available: {}", windowAvailable);
}
std::string getClosingStream(const std::string& streamId) {
return "closing stream, stream id: " + streamId;
return fmt::format("closing stream, stream id: {}", streamId);
}
} // namespace quic

View File

@ -150,7 +150,7 @@ folly::dynamic StreamFrameLog::toDynamic() const {
d["offset"] = offset;
d["length"] = len;
d["fin"] = fin;
d["stream_id"] = folly::to<std::string>(streamId);
d["stream_id"] = fmt::format("{}", streamId);
d["frame_type"] = toQlogString(FrameType::STREAM);
return d;
}
@ -325,9 +325,7 @@ folly::dynamic QLogPacketEvent::toDynamic() const {
// creating a folly::dynamic array to hold the information corresponding to
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
"transport",
toString(eventType));
fmt::format("{}", refTime.count()), "transport", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["header"] = folly::dynamic::object("packet_size", packetSize);
@ -352,9 +350,7 @@ folly::dynamic QLogVersionNegotiationEvent::toDynamic() const {
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
"transport",
toString(eventType));
fmt::format("{}", refTime.count()), "transport", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["versions"] = versionLog->toDynamic();
@ -367,9 +363,7 @@ folly::dynamic QLogVersionNegotiationEvent::toDynamic() const {
folly::dynamic QLogRetryEvent::toDynamic() const {
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
"transport",
toString(eventType));
fmt::format("{}", refTime.count()), "transport", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["header"] = folly::dynamic::object("packet_size", packetSize);
@ -398,9 +392,7 @@ folly::dynamic QLogConnectionCloseEvent::toDynamic() const {
// creating a folly::dynamic array to hold the information corresponding to
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
"connectivity",
toString(eventType));
fmt::format("{}", refTime.count()), "connectivity", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["error"] = error;
@ -474,9 +466,7 @@ folly::dynamic QLogTransportSummaryEvent::toDynamic() const {
// creating a folly::dynamic array to hold the information corresponding to
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
"transport",
toString(eventType));
fmt::format("{}", refTime.count()), "transport", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["total_bytes_sent"] = totalBytesSent;
@ -537,9 +527,7 @@ folly::dynamic QLogCongestionMetricUpdateEvent::toDynamic() const {
// creating a folly::dynamic array to hold the information corresponding to
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
"metric_update",
toString(eventType));
fmt::format("{}", refTime.count()), "metric_update", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["bytes_in_flight"] = bytesInFlight;
@ -562,7 +550,7 @@ QLogAppLimitedUpdateEvent::QLogAppLimitedUpdateEvent(
folly::dynamic QLogAppLimitedUpdateEvent::toDynamic() const {
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
fmt::format("{}", refTime.count()),
"app_limited_update",
toString(eventType));
folly::dynamic data = folly::dynamic::object();
@ -582,7 +570,7 @@ QLogBandwidthEstUpdateEvent::QLogBandwidthEstUpdateEvent(
folly::dynamic QLogBandwidthEstUpdateEvent::toDynamic() const {
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
fmt::format("{}", refTime.count()),
"bandwidth_est_update",
toString(eventType));
folly::dynamic data = folly::dynamic::object();
@ -605,9 +593,7 @@ folly::dynamic QLogPacingMetricUpdateEvent::toDynamic() const {
// creating a folly::dynamic array to hold the information corresponding to
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
"metric_update",
toString(eventType));
fmt::format("{}", refTime.count()), "metric_update", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["pacing_burst_size"] = pacingBurstSize;
@ -634,9 +620,7 @@ QLogPacingObservationEvent::QLogPacingObservationEvent(
// users are not supposed to use them after toDynamic() is called.
folly::dynamic QLogPacingObservationEvent::toDynamic() const {
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
"metric_update",
toString(eventType));
fmt::format("{}", refTime.count()), "metric_update", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["actual_pacing_rate"] = actual;
@ -660,9 +644,7 @@ folly::dynamic QLogAppIdleUpdateEvent::toDynamic() const {
// creating a folly::dynamic array to hold the information corresponding to
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
"idle_update",
toString(eventType));
fmt::format("{}", refTime.count()), "idle_update", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["idle_event"] = idleEvent;
@ -685,7 +667,7 @@ folly::dynamic QLogPacketDropEvent::toDynamic() const {
// creating a folly::dynamic array to hold the information corresponding to
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()), "loss", toString(eventType));
fmt::format("{}", refTime.count()), "loss", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["packet_size"] = packetSize;
@ -707,9 +689,7 @@ folly::dynamic QLogDatagramReceivedEvent::toDynamic() const {
// creating a folly::dynamic array to hold the information corresponding to
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
"transport",
toString(eventType));
fmt::format("{}", refTime.count()), "transport", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["data_len"] = dataLen;
@ -736,7 +716,7 @@ folly::dynamic QLogLossAlarmEvent::toDynamic() const {
// creating a folly::dynamic array to hold the information corresponding to
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()), "loss", toString(eventType));
fmt::format("{}", refTime.count()), "loss", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["largest_sent"] = largestSent;
@ -764,7 +744,7 @@ folly::dynamic QLogPacketsLostEvent::toDynamic() const {
// creating a folly::dynamic array to hold the information corresponding to
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()), "loss", toString(eventType));
fmt::format("{}", refTime.count()), "loss", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["largest_lost_packet_num"] = largestLostPacketNum;
@ -787,9 +767,7 @@ folly::dynamic QLogTransportStateUpdateEvent::toDynamic() const {
// creating a folly::dynamic array to hold the information corresponding to
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
"transport",
toString(eventType));
fmt::format("{}", refTime.count()), "transport", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["update"] = update;
@ -811,9 +789,7 @@ folly::dynamic QLogPacketBufferedEvent::toDynamic() const {
// creating a folly::dynamic array to hold the information corresponding to
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
"transport",
toString(eventType));
fmt::format("{}", refTime.count()), "transport", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["protection_type"] = toString(protectionType);
@ -836,12 +812,10 @@ folly::dynamic QLogPacketAckEvent::toDynamic() const {
// creating a folly::dynamic array to hold the information corresponding to
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
"transport",
toString(eventType));
fmt::format("{}", refTime.count()), "transport", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["packet_num_space"] = folly::to<std::string>(packetNumSpace);
data["packet_num_space"] = fmt::format("{}", toString(packetNumSpace));
data["packet_num"] = packetNum;
d.push_back(std::move(data));
@ -863,7 +837,7 @@ folly::dynamic QLogMetricUpdateEvent::toDynamic() const {
// creating a folly::dynamic array to hold the information corresponding to
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()), "recovery", toString(eventType));
fmt::format("{}", refTime.count()), "recovery", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["latest_rtt"] = latestRtt.count();
@ -893,7 +867,7 @@ folly::dynamic QLogStreamStateUpdateEvent::toDynamic() const {
// creating a folly::dynamic array to hold the information corresponding to
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()), "HTTP3", toString(eventType));
fmt::format("{}", refTime.count()), "HTTP3", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["id"] = id;
@ -925,9 +899,7 @@ folly::dynamic QLogConnectionMigrationEvent::toDynamic() const {
// creating a folly::dynamic array to hold the information corresponding to
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
"transport",
toString(eventType));
fmt::format("{}", refTime.count()), "transport", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["intentional"] = intentionalMigration_;
@ -953,9 +925,7 @@ folly::dynamic QLogPathValidationEvent::toDynamic() const {
// creating a folly::dynamic array to hold the information corresponding to
// the event fields relative_time, category, event_type, trigger, data
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
"transport",
toString(eventType));
fmt::format("{}", refTime.count()), "transport", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["success"] = success_;
@ -979,7 +949,7 @@ QLogPriorityUpdateEvent::QLogPriorityUpdateEvent(
folly::dynamic QLogPriorityUpdateEvent::toDynamic() const {
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()), "HTTP3", toString(eventType));
fmt::format("{}", refTime.count()), "HTTP3", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["id"] = streamId_;
@ -1004,9 +974,7 @@ QLogL4sWeightUpdateEvent::QLogL4sWeightUpdateEvent(
folly::dynamic QLogL4sWeightUpdateEvent::toDynamic() const {
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
"metric_update",
toString(eventType));
fmt::format("{}", refTime.count()), "metric_update", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["weight"] = l4sWeight_;
data["new_ect1"] = newECT1Echoed_;
@ -1035,9 +1003,7 @@ QLogNetworkPathModelUpdateEvent::QLogNetworkPathModelUpdateEvent(
folly::dynamic QLogNetworkPathModelUpdateEvent::toDynamic() const {
folly::dynamic d = folly::dynamic::array(
folly::to<std::string>(refTime.count()),
"metric_update",
toString(eventType));
fmt::format("{}", refTime.count()), "metric_update", toString(eventType));
folly::dynamic data = folly::dynamic::object();
data["inflight_hi"] = inflightHi_;
data["inflight_lo"] = inflightLo_;

View File

@ -1411,7 +1411,7 @@ TEST_F(QLoggerTest, PrettyStream) {
EXPECT_EQ(q->logs.size(), 0);
std::string outputPath =
folly::to<std::string>(dir, "/", (q->dcid.value()).hex(), ".qlog");
fmt::format("{}/{}.qlog", dir, (q->dcid.value()).hex());
delete q;
std::ifstream file(outputPath, std::ifstream::in);
@ -1522,7 +1522,7 @@ TEST_F(QLoggerTest, NonPrettyStream) {
EXPECT_EQ(q->logs.size(), 0);
std::string outputPath =
folly::to<std::string>(dir, "/", (q->dcid.value()).hex(), ".qlog");
fmt::format("{}/{}.qlog", dir, (q->dcid.value()).hex());
delete q;
std::ifstream file(outputPath, std::ifstream::in);
@ -1566,7 +1566,7 @@ TEST_F(QLoggerTest, CompressedStream) {
EXPECT_EQ(q->logs.size(), 0);
std::string outputPath =
folly::to<std::string>(dir, "/", (q->dcid.value()).hex(), ".qlog.gz");
fmt::format("{}/{}.qlog.gz", dir, (q->dcid.value()).hex());
LOG(INFO) << outputPath;
delete q;
@ -1614,7 +1614,7 @@ TEST_F(QLoggerTest, CompressedNonStream) {
q.outputLogsToFile(dir, false);
std::string outputPath =
folly::to<std::string>(dir, "/", (q.dcid.value()).hex(), ".qlog.gz");
fmt::format("{}/{}.qlog.gz", dir, (q.dcid.value()).hex());
std::string compressedData;
auto success = folly::readFile(outputPath.c_str(), compressedData);
@ -1660,7 +1660,7 @@ TEST_F(QLoggerTest, NoThrowOnStreamingWithNonExistentDirectory) {
0); // Packet is not written but also not being kept in memory
std::string outputPath =
folly::to<std::string>(dir, "/", (q->dcid.value()).hex(), ".qlog.gz");
fmt::format("{}/{}.qlog.gz", dir, (q->dcid.value()).hex());
delete q;
@ -1762,7 +1762,7 @@ TEST_F(QLoggerTest, PrettyDatagram) {
EXPECT_EQ(q->logs.size(), 0);
std::string outputPath =
folly::to<std::string>(dir, "/", (q->dcid.value()).hex(), ".qlog");
fmt::format("{}/{}.qlog", dir, (q->dcid.value()).hex());
delete q;
std::ifstream file(outputPath, std::ifstream::in);
@ -1919,7 +1919,7 @@ TEST_F(QLoggerTest, ReadAckReceiveTimestampsFrame) {
EXPECT_EQ(q->logs.size(), 0);
std::string outputPath =
folly::to<std::string>(dir, "/", (q->dcid.value()).hex(), ".qlog");
fmt::format("{}/{}.qlog", dir, (q->dcid.value()).hex());
delete q;
std::ifstream file(outputPath, std::ifstream::in);

View File

@ -39,7 +39,7 @@ void QuicServerAsyncTransport::onConnectionEnd() noexcept {
void QuicServerAsyncTransport::onConnectionError(QuicError code) noexcept {
folly::AsyncSocketException ex(
folly::AsyncSocketException::UNKNOWN,
folly::to<std::string>("Quic connection error", code.message));
fmt::format("Quic connection error {}", code.message));
closeNowImpl(std::move(ex));
}

View File

@ -344,11 +344,11 @@ Handshake::TLSSummary ServerHandshake::getTLSSummary() const {
}
if (state_.group().has_value()) {
summary.namedGroup =
folly::to<std::string>(fizz::toString(state_.group().value()));
fmt::format("{}", fizz::toString(state_.group().value()));
}
if (state_.pskType().has_value()) {
summary.pskType =
folly::to<std::string>(fizz::toString(state_.pskType().value()));
fmt::format("{}", fizz::toString(state_.pskType().value()));
}
if (state_.echState().has_value()) {
summary.echStatus = fizz::server::toString(state_.echStatus());

View File

@ -424,8 +424,8 @@ folly::Expected<folly::Unit, QuicError> processClientInitialParams(
if (packetSize && *packetSize < kMinMaxUDPPayload) {
return folly::makeUnexpected(QuicError(
TransportErrorCode::TRANSPORT_PARAMETER_ERROR,
folly::to<std::string>(
"Max packet size too small. received max_packetSize = ",
fmt::format(
"Max packet size too small. received max_packetSize = {}",
*packetSize)));
}
@ -1512,8 +1512,8 @@ folly::Expected<folly::Unit, QuicError> onServerReadDataFromOpen(
case QuicFrame::Type::ConnectionCloseFrame: {
isNonProbingPacket = true;
ConnectionCloseFrame& connFrame = *quicFrame.asConnectionCloseFrame();
auto errMsg = folly::to<std::string>(
"Server closed by peer reason=", connFrame.reasonPhrase);
auto errMsg = fmt::format(
"Server closed by peer reason={}", connFrame.reasonPhrase);
VLOG(4) << errMsg << " " << conn;
// we want to deliver app callbacks with the peer supplied error,
// but send a NO_ERROR to the peer.
@ -1809,8 +1809,8 @@ folly::Expected<folly::Unit, QuicError> onServerReadDataFromClosed(
switch (quicFrame.type()) {
case QuicFrame::Type::ConnectionCloseFrame: {
ConnectionCloseFrame& connFrame = *quicFrame.asConnectionCloseFrame();
auto errMsg = folly::to<std::string>(
"Server closed by peer reason=", connFrame.reasonPhrase);
auto errMsg = fmt::format(
"Server closed by peer reason={}", connFrame.reasonPhrase);
VLOG(4) << errMsg << " " << conn;
if (conn.qLogger) {
conn.qLogger->addTransportStateUpdate(getPeerClose(errMsg));

View File

@ -1421,8 +1421,7 @@ TEST_F(QuicServerTransportTest, ReceiveConnectionClose) {
EXPECT_EQ(
server->getConn().peerConnectionError->code,
QuicErrorCode(TransportErrorCode::NO_ERROR));
auto closedMsg =
folly::to<std::string>("Server closed by peer reason=", errMsg);
auto closedMsg = fmt::format("Server closed by peer reason={}", errMsg);
EXPECT_EQ(server->getConn().peerConnectionError->message, closedMsg);
EXPECT_TRUE(server->isClosed());
EXPECT_TRUE(verifyFramePresent(
@ -1516,8 +1515,7 @@ TEST_F(QuicServerTransportTest, ReceiveConnectionCloseBeforeDatagram) {
EXPECT_EQ(
server->getConn().peerConnectionError->code,
QuicErrorCode(TransportErrorCode::NO_ERROR));
auto closedMsg =
folly::to<std::string>("Server closed by peer reason=", errMsg);
auto closedMsg = fmt::format("Server closed by peer reason={}", errMsg);
EXPECT_EQ(server->getConn().peerConnectionError->message, closedMsg);
EXPECT_TRUE(server->isClosed());
EXPECT_TRUE(verifyFramePresent(
@ -1560,8 +1558,7 @@ TEST_F(QuicServerTransportTest, ReceiveApplicationClose) {
EXPECT_EQ(
server->getConn().peerConnectionError->code,
QuicErrorCode(GenericApplicationErrorCode::UNKNOWN));
auto closedMsg =
folly::to<std::string>("Server closed by peer reason=", errMsg);
auto closedMsg = fmt::format("Server closed by peer reason={}", errMsg);
EXPECT_EQ(server->getConn().peerConnectionError->message, closedMsg);
EXPECT_TRUE(server->isClosed());
EXPECT_TRUE(verifyFramePresent(
@ -1597,8 +1594,7 @@ TEST_F(QuicServerTransportTest, ReceiveConnectionCloseTwice) {
EXPECT_EQ(
server->getConn().peerConnectionError->code,
QuicErrorCode(TransportErrorCode::NO_ERROR));
auto closedMsg =
folly::to<std::string>("Server closed by peer reason=", errMsg);
auto closedMsg = fmt::format("Server closed by peer reason={}", errMsg);
EXPECT_EQ(server->getConn().peerConnectionError->message, closedMsg);
EXPECT_TRUE(server->isClosed());
EXPECT_TRUE(verifyFramePresent(

View File

@ -71,8 +71,8 @@ folly::Expected<folly::Unit, QuicError> receiveReadStreamFrameSMHandler(
case StreamRecvState::Invalid: {
return folly::makeUnexpected(QuicError(
TransportErrorCode::STREAM_STATE_ERROR,
folly::to<std::string>(
"Invalid transition from state=",
fmt::format(
"Invalid transition from state={}",
streamStateToString(stream.recvState))));
}
}
@ -115,8 +115,8 @@ folly::Expected<folly::Unit, QuicError> receiveRstStreamSMHandler(
case StreamRecvState::Invalid: {
return folly::makeUnexpected(QuicError(
TransportErrorCode::STREAM_STATE_ERROR,
folly::to<std::string>(
"Invalid transition from state=",
fmt::format(
"Invalid transition from state={}",
streamStateToString(stream.recvState))));
}
}

View File

@ -67,8 +67,8 @@ folly::Expected<folly::Unit, QuicError> sendStopSendingSMHandler(
case StreamSendState::Invalid: {
return folly::makeUnexpected(QuicError(
TransportErrorCode::STREAM_STATE_ERROR,
folly::to<std::string>(
"Invalid transition from state=",
fmt::format(
"Invalid transition from state={}",
streamStateToString(stream.sendState))));
}
}
@ -120,8 +120,8 @@ folly::Expected<folly::Unit, QuicError> sendRstSMHandler(
case StreamSendState::Invalid: {
return folly::makeUnexpected(QuicError(
TransportErrorCode::STREAM_STATE_ERROR,
folly::to<std::string>(
"Invalid transition from state=",
fmt::format(
"Invalid transition from state={}",
streamStateToString(stream.sendState))));
}
}
@ -196,8 +196,8 @@ folly::Expected<folly::Unit, QuicError> sendAckSMHandler(
case StreamSendState::Invalid: {
return folly::makeUnexpected(QuicError(
TransportErrorCode::STREAM_STATE_ERROR,
folly::to<std::string>(
"Invalid transition from state=",
fmt::format(
"Invalid transition from state={}",
streamStateToString(stream.sendState))));
}
}
@ -238,8 +238,8 @@ folly::Expected<folly::Unit, QuicError> sendRstAckSMHandler(
case StreamSendState::Invalid: {
return folly::makeUnexpected(QuicError(
TransportErrorCode::STREAM_STATE_ERROR,
folly::to<std::string>(
"Invalid transition from state=",
fmt::format(
"Invalid transition from state={}",
streamStateToString(stream.sendState))));
}
}

View File

@ -58,8 +58,8 @@ folly::Expected<folly::Unit, QuicError> onResetQuicStream(
return folly::makeUnexpected(QuicError(
TransportErrorCode::STREAM_STATE_ERROR,
"Read offset mismatch, " +
folly::to<std::string>(stream.finalReadOffset.value()) +
" != " + folly::to<std::string>(frame.finalSize)));
fmt::format(
"{} != {}", stream.finalReadOffset.value(), frame.finalSize)));
}
if (stream.streamReadError &&
stream.streamReadError.value().asApplicationErrorCode() &&

View File

@ -117,8 +117,8 @@ quic::CongestionControlType flagsToCongestionControlType(
const std::string& congestionControlFlag) {
auto ccType = quic::congestionControlStrToType(congestionControlFlag);
if (!ccType) {
throw std::invalid_argument(folly::to<std::string>(
"Unknown congestion controller ", congestionControlFlag));
throw std::invalid_argument(
fmt::format("Unknown congestion controller {}", congestionControlFlag));
}
return *ccType;
}

View File

@ -216,8 +216,8 @@ folly::Expected<folly::Unit, std::runtime_error> XskSender::bind(int queueId) {
xskFd_, queueId, xskSenderConfig_.sharedState->sharedXskFd);
}
if (bind_result < 0) {
std::string errorMsg = folly::to<std::string>(
"Failed to bind xdp socket: ", folly::errnoStr(errno));
std::string errorMsg =
fmt::format("Failed to bind xdp socket: {}", folly::errnoStr(errno));
return folly::makeUnexpected(std::runtime_error(errorMsg));
}