in ctsTraffic/ctsConfig.cpp [3359:3477]
void PrintConnectionResults(uint32_t error) noexcept try
{
ctsConfigInitOnce();
// write even after shutdown so can print the final summaries
auto writeToConsole = false;
// ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
switch (g_consoleVerbosity) // NOLINT(hicpp-multiway-paths-covered)
{
// case 0: // nothing
// case 1: // status updates
// case 2: // error info
case 3: // connection info
case 4: // connection info + error info
case 5: // connection info + error info + status updates
case 6: // above + debug info
{
writeToConsole = true;
}
}
enum class ErrorType
{
Success,
NetworkError,
ProtocolError
} errorType = ErrorType::Success;
if (0 == error)
{
errorType = ErrorType::Success;
}
else if (ctsIoPattern::IsProtocolError(error))
{
errorType = ErrorType::ProtocolError;
}
else
{
errorType = ErrorType::NetworkError;
}
const float currentTime = GetStatusTimeStamp();
wstring csvString;
wstring textString;
wstring errorString;
if (ErrorType::ProtocolError != errorType)
{
if (0 == error)
{
errorString = L"Succeeded";
}
else
{
errorString = wil::str_printf<std::wstring>(
L"%lu: %ws",
error,
ctString::ctFormatMessage(error).c_str());
// remove any commas from the formatted string - since that will mess up csv files
ctString::ctReplaceAll(errorString, L",", L" ");
}
}
if (g_connectionLogger && g_connectionLogger->IsCsvFormat())
{
// csv format : L"TimeSlice,LocalAddress,RemoteAddress,SendBytes,SendBps,RecvBytes,RecvBps,TimeMs,Result,ConnectionId"
static const auto* tcpResultCsvFormat = L"%.3f,%ws,%ws,%lld,%lld,%lld,%lld,%lld,%ws,%hs\r\n";
csvString = wil::str_printf<std::wstring>(
tcpResultCsvFormat,
currentTime,
ctSockaddr().WriteCompleteAddress().c_str(),
ctSockaddr().WriteCompleteAddress().c_str(),
0LL,
0LL,
0LL,
0LL,
0LL,
errorString.c_str(),
L"");
}
// we'll never write csv format to the console so we'll need a text string in that case
// - and/or in the case the g_ConnectionLogger isn't writing to csv
if (writeToConsole || g_connectionLogger && !g_connectionLogger->IsCsvFormat())
{
static const auto* tcpNetworkFailureResultTextFormat = L"[%.3f] TCP connection failed with the error %ws : [%ws - %ws] [%hs] : SendBytes[%lld] SendBps[%lld] RecvBytes[%lld] RecvBps[%lld] Time[%lld ms]";
textString = wil::str_printf<std::wstring>(
tcpNetworkFailureResultTextFormat,
currentTime,
errorString.c_str(),
ctSockaddr().WriteCompleteAddress().c_str(),
ctSockaddr().WriteCompleteAddress().c_str(),
L"",
0LL,
0LL,
0LL,
0LL,
0LL);
}
if (writeToConsole)
{
// text strings always go to the console
wprintf(L"%ws\n", textString.c_str());
}
if (g_connectionLogger)
{
if (g_connectionLogger->IsCsvFormat())
{
g_connectionLogger->LogMessage(csvString.c_str());
}
else
{
g_connectionLogger->LogMessage(
wil::str_printf<std::wstring>(L"%ws\r\n", textString.c_str()).c_str());
}
}
}