From c5cd8d354d9a577d8c518ef000b4508977759502 Mon Sep 17 00:00:00 2001 From: heinrich5991 Date: Tue, 15 Jun 2021 00:12:06 +0200 Subject: [PATCH] Add a new failure log level to the HTTP module Use it for the "determine best masterserver" job, so that we can debug failures. --- src/engine/client/http.cpp | 16 ++++++++-------- src/engine/client/http.h | 17 ++++++++++++----- src/engine/client/serverbrowser_http.cpp | 4 ++-- src/game/client/components/skins.cpp | 4 ++-- src/game/client/components/skins.h | 2 +- 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/engine/client/http.cpp b/src/engine/client/http.cpp index ae5da4eb8..5445d8884 100644 --- a/src/engine/client/http.cpp +++ b/src/engine/client/http.cpp @@ -86,7 +86,7 @@ void EscapeUrl(char *pBuf, int Size, const char *pStr) curl_free(pEsc); } -CRequest::CRequest(const char *pUrl, CTimeout Timeout, bool LogProgress) : +CRequest::CRequest(const char *pUrl, CTimeout Timeout, HTTPLOG LogProgress) : m_Timeout(Timeout), m_Size(0), m_Progress(0), @@ -153,19 +153,19 @@ int CRequest::RunImpl(CURL *pHandle) return HTTP_ERROR; } - if(g_Config.m_DbgCurl || m_LogProgress) + if(g_Config.m_DbgCurl || m_LogProgress >= HTTPLOG::ALL) dbg_msg("http", "fetching %s", m_aUrl); m_State = HTTP_RUNNING; int Ret = curl_easy_perform(pHandle); if(Ret != CURLE_OK) { - if(g_Config.m_DbgCurl || m_LogProgress) - dbg_msg("http", "task failed. libcurl error: %s", aErr); + if(g_Config.m_DbgCurl || m_LogProgress >= HTTPLOG::FAILURE) + dbg_msg("http", "%s failed. libcurl error: %s", m_aUrl, aErr); return (Ret == CURLE_ABORTED_BY_CALLBACK) ? HTTP_ABORTED : HTTP_ERROR; } else { - if(g_Config.m_DbgCurl || m_LogProgress) + if(g_Config.m_DbgCurl || m_LogProgress >= HTTPLOG::ALL) dbg_msg("http", "task done %s", m_aUrl); return HTTP_DONE; } @@ -186,7 +186,7 @@ int CRequest::ProgressCallback(void *pUser, double DlTotal, double DlCurr, doubl return pTask->m_Abort ? -1 : 0; } -CHead::CHead(const char *pUrl, CTimeout Timeout, bool LogProgress) : +CHead::CHead(const char *pUrl, CTimeout Timeout, HTTPLOG LogProgress) : CRequest(pUrl, Timeout, LogProgress) { } @@ -202,7 +202,7 @@ bool CHead::AfterInit(void *pCurl) return true; } -CGet::CGet(const char *pUrl, CTimeout Timeout, bool LogProgress) : +CGet::CGet(const char *pUrl, CTimeout Timeout, HTTPLOG LogProgress) : CRequest(pUrl, Timeout, LogProgress), m_BufferSize(0), m_BufferLength(0), @@ -275,7 +275,7 @@ size_t CGet::OnData(char *pData, size_t DataSize) return DataSize; } -CGetFile::CGetFile(IStorage *pStorage, const char *pUrl, const char *pDest, int StorageType, CTimeout Timeout, bool LogProgress) : +CGetFile::CGetFile(IStorage *pStorage, const char *pUrl, const char *pDest, int StorageType, CTimeout Timeout, HTTPLOG LogProgress) : CRequest(pUrl, Timeout, LogProgress), m_pStorage(pStorage), m_File(0), diff --git a/src/engine/client/http.h b/src/engine/client/http.h index 3365d6ac5..450e3893b 100644 --- a/src/engine/client/http.h +++ b/src/engine/client/http.h @@ -17,6 +17,13 @@ enum HTTP_ABORTED, }; +enum class HTTPLOG +{ + NONE, + FAILURE, + ALL, +}; + struct CTimeout { long ConnectTimeoutMs; @@ -42,7 +49,7 @@ class CRequest : public IJob double m_Size; double m_Current; int m_Progress; - bool m_LogProgress; + HTTPLOG m_LogProgress; std::atomic m_State; std::atomic m_Abort; @@ -57,7 +64,7 @@ protected: virtual int OnCompletion(int State) { return State; } public: - CRequest(const char *pUrl, CTimeout Timeout, bool LogProgress = true); + CRequest(const char *pUrl, CTimeout Timeout, HTTPLOG LogProgress = HTTPLOG::ALL); double Current() const { return m_Current; } double Size() const { return m_Size; } @@ -72,7 +79,7 @@ class CHead : public CRequest virtual bool AfterInit(void *pCurl); public: - CHead(const char *pUrl, CTimeout Timeout, bool LogProgress = true); + CHead(const char *pUrl, CTimeout Timeout, HTTPLOG LogProgress = HTTPLOG::ALL); ~CHead(); }; @@ -85,7 +92,7 @@ class CGet : public CRequest unsigned char *m_pBuffer; public: - CGet(const char *pUrl, CTimeout Timeout, bool LogProgress = true); + CGet(const char *pUrl, CTimeout Timeout, HTTPLOG LogProgress = HTTPLOG::ALL); ~CGet(); size_t ResultSize() const @@ -121,7 +128,7 @@ protected: virtual int OnCompletion(int State); public: - CGetFile(IStorage *pStorage, const char *pUrl, const char *pDest, int StorageType = -2, CTimeout Timeout = CTimeout{4000, 500, 5}, bool LogProgress = true); + CGetFile(IStorage *pStorage, const char *pUrl, const char *pDest, int StorageType = -2, CTimeout Timeout = CTimeout{4000, 500, 5}, HTTPLOG LogProgress = HTTPLOG::ALL); const char *Dest() const { return m_aDest; } }; diff --git a/src/engine/client/serverbrowser_http.cpp b/src/engine/client/serverbrowser_http.cpp index 36acc6c1a..b0a63205c 100644 --- a/src/engine/client/serverbrowser_http.cpp +++ b/src/engine/client/serverbrowser_http.cpp @@ -137,14 +137,14 @@ void CChooseMaster::CJob::Run() { aTimeMs[i] = -1; const char *pUrl = m_pData->m_aaUrls[aRandomized[i]]; - CHead Head(pUrl, Timeout, false); + CHead Head(pUrl, Timeout, HTTPLOG::FAILURE); IEngine::RunJobBlocking(&Head); if(Head.State() != HTTP_DONE) { continue; } int64 StartTime = time_get(); - CGet Get(pUrl, Timeout, false); + CGet Get(pUrl, Timeout, HTTPLOG::FAILURE); IEngine::RunJobBlocking(&Get); int Time = (time_get() - StartTime) * 1000 / time_freq(); if(Get.State() != HTTP_DONE) diff --git a/src/game/client/components/skins.cpp b/src/game/client/components/skins.cpp index e613ce80f..865a6bef2 100644 --- a/src/game/client/components/skins.cpp +++ b/src/game/client/components/skins.cpp @@ -41,7 +41,7 @@ int CSkins::CGetPngFile::OnCompletion(int State) return State; } -CSkins::CGetPngFile::CGetPngFile(CSkins *pSkins, IStorage *pStorage, const char *pUrl, const char *pDest, int StorageType, CTimeout Timeout, bool LogProgress) : +CSkins::CGetPngFile::CGetPngFile(CSkins *pSkins, IStorage *pStorage, const char *pUrl, const char *pDest, int StorageType, CTimeout Timeout, HTTPLOG LogProgress) : CGetFile(pStorage, pUrl, pDest, StorageType, Timeout, LogProgress), m_pSkins(pSkins) { } @@ -420,7 +420,7 @@ int CSkins::FindImpl(const char *pName) char aUrl[256]; str_format(aUrl, sizeof(aUrl), "%s%s.png", g_Config.m_ClSkinDownloadUrl, pName); str_format(Skin.m_aPath, sizeof(Skin.m_aPath), "downloadedskins/%s.%d.tmp", pName, pid()); - Skin.m_pTask = std::make_shared(this, Storage(), aUrl, Skin.m_aPath, IStorage::TYPE_SAVE, CTimeout{0, 0, 0}, false); + Skin.m_pTask = std::make_shared(this, Storage(), aUrl, Skin.m_aPath, IStorage::TYPE_SAVE, CTimeout{0, 0, 0}, HTTPLOG::NONE); m_pClient->Engine()->AddJob(Skin.m_pTask); m_aDownloadSkins.add(Skin); return -1; diff --git a/src/game/client/components/skins.h b/src/game/client/components/skins.h index 8ec94f750..e94d8aedf 100644 --- a/src/game/client/components/skins.h +++ b/src/game/client/components/skins.h @@ -20,7 +20,7 @@ public: virtual int OnCompletion(int State); public: - CGetPngFile(CSkins *pSkins, IStorage *pStorage, const char *pUrl, const char *pDest, int StorageType = -2, CTimeout Timeout = CTimeout{4000, 500, 5}, bool LogProgress = true); + CGetPngFile(CSkins *pSkins, IStorage *pStorage, const char *pUrl, const char *pDest, int StorageType = -2, CTimeout Timeout = CTimeout{4000, 500, 5}, HTTPLOG LogProgress = HTTPLOG::ALL); CImageInfo m_Info; };