diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index c3f774511..c00621686 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -3048,7 +3048,7 @@ void CClient::Run() } m_Fifo.Shutdown(); - + m_Http.Shutdown(); GameClient()->OnShutdown(); Disconnect(); diff --git a/src/engine/client/serverbrowser_http.cpp b/src/engine/client/serverbrowser_http.cpp index 793c1f8e1..eb3f35277 100644 --- a/src/engine/client/serverbrowser_http.cpp +++ b/src/engine/client/serverbrowser_http.cpp @@ -207,7 +207,7 @@ void CChooseMaster::CJob::Run() pGet->Wait(); auto Time = std::chrono::duration_cast(time_get_nanoseconds() - StartTime); - if(pHead->State() == EHttpState::ABORTED) + if(pGet->State() == EHttpState::ABORTED) { dbg_msg("serverbrowse_http", "master chooser aborted"); return; @@ -345,7 +345,7 @@ void CServerBrowserHttp::Update() } else if(m_State == STATE_REFRESHING) { - if(m_pGetServers->State() == EHttpState::QUEUED || m_pGetServers->State() == EHttpState::RUNNING) + if(!m_pGetServers->Done()) { return; } @@ -354,7 +354,7 @@ void CServerBrowserHttp::Update() std::swap(m_pGetServers, pGetServers); bool Success = true; - json_value *pJson = pGetServers->ResultJson(); + json_value *pJson = pGetServers->State() == EHttpState::DONE ? pGetServers->ResultJson() : nullptr; Success = Success && pJson; Success = Success && !Parse(pJson, &m_vServers, &m_vLegacyServers); json_value_free(pJson); diff --git a/src/engine/shared/http.cpp b/src/engine/shared/http.cpp index f71071217..e47962773 100644 --- a/src/engine/shared/http.cpp +++ b/src/engine/shared/http.cpp @@ -257,33 +257,25 @@ int CHttpRequest::ProgressCallback(void *pUser, double DlTotal, double DlCurr, d return pTask->m_Abort ? -1 : 0; } -void CHttpRequest::OnCompletionInternal(std::optional Result) +void CHttpRequest::OnCompletionInternal(unsigned int Result) { EHttpState State; - if(Result.has_value()) + const CURLcode Code = static_cast(Result); + if(Code != CURLE_OK) { - CURLcode Code = static_cast(Result.value()); - if(Code != CURLE_OK) + if(g_Config.m_DbgCurl || m_LogProgress >= HTTPLOG::FAILURE) { - if(g_Config.m_DbgCurl || m_LogProgress >= HTTPLOG::FAILURE) - { - log_error("http", "%s failed. libcurl error (%u): %s", m_aUrl, Code, m_aErr); - } - State = (Code == CURLE_ABORTED_BY_CALLBACK) ? EHttpState::ABORTED : EHttpState::ERROR; - } - else - { - if(g_Config.m_DbgCurl || m_LogProgress >= HTTPLOG::ALL) - { - log_info("http", "task done: %s", m_aUrl); - } - State = EHttpState::DONE; + log_error("http", "%s failed. libcurl error (%u): %s", m_aUrl, Code, m_aErr); } + State = (Code == CURLE_ABORTED_BY_CALLBACK) ? EHttpState::ABORTED : EHttpState::ERROR; } else { - log_error("http", "%s failed. internal error: %s", m_aUrl, m_aErr); - State = EHttpState::ERROR; + if(g_Config.m_DbgCurl || m_LogProgress >= HTTPLOG::ALL) + { + log_info("http", "task done: %s", m_aUrl); + } + State = EHttpState::DONE; } if(State == EHttpState::DONE) @@ -543,7 +535,7 @@ void CHttp::RunLoop() for(auto &pRequest : m_PendingRequests) { str_copy(pRequest->m_aErr, "Shutting down"); - pRequest->OnCompletionInternal(std::nullopt); + pRequest->OnCompletionInternal(CURLE_ABORTED_BY_CALLBACK); } for(auto &ReqPair : m_RunningRequests) @@ -556,7 +548,7 @@ void CHttp::RunLoop() } str_copy(pRequest->m_aErr, "Shutting down"); - pRequest->OnCompletionInternal(std::nullopt); + pRequest->OnCompletionInternal(CURLE_ABORTED_BY_CALLBACK); } if(Cleanup) diff --git a/src/engine/shared/http.h b/src/engine/shared/http.h index a6157fef3..27875f09a 100644 --- a/src/engine/shared/http.h +++ b/src/engine/shared/http.h @@ -118,7 +118,7 @@ class CHttpRequest : public IHttpRequest // Abort the request with an error if `BeforeInit()` returns false. bool BeforeInit(); bool ConfigureHandle(void *pHandle); // void * == CURL * - void OnCompletionInternal(std::optional Result); // unsigned int == CURLcode + void OnCompletionInternal(unsigned int Result); // unsigned int == CURLcode // Abort the request if `OnData()` returns something other than // `DataSize`.