mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge pull request #7962 from Robyt3/Http-Various-Fixes
Quit client faster by aborting HTTP requests earlier, other HTTP fixes
This commit is contained in:
commit
8870eb94aa
|
@ -3048,7 +3048,7 @@ void CClient::Run()
|
|||
}
|
||||
|
||||
m_Fifo.Shutdown();
|
||||
|
||||
m_Http.Shutdown();
|
||||
GameClient()->OnShutdown();
|
||||
Disconnect();
|
||||
|
||||
|
|
|
@ -207,7 +207,7 @@ void CChooseMaster::CJob::Run()
|
|||
pGet->Wait();
|
||||
|
||||
auto Time = std::chrono::duration_cast<std::chrono::milliseconds>(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);
|
||||
|
|
|
@ -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<unsigned int> Result)
|
||||
void CHttpRequest::OnCompletionInternal(unsigned int Result)
|
||||
{
|
||||
EHttpState State;
|
||||
if(Result.has_value())
|
||||
const CURLcode Code = static_cast<CURLcode>(Result);
|
||||
if(Code != CURLE_OK)
|
||||
{
|
||||
CURLcode Code = static_cast<CURLcode>(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)
|
||||
|
|
|
@ -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<unsigned int> Result); // unsigned int == CURLcode
|
||||
void OnCompletionInternal(unsigned int Result); // unsigned int == CURLcode
|
||||
|
||||
// Abort the request if `OnData()` returns something other than
|
||||
// `DataSize`.
|
||||
|
|
Loading…
Reference in a new issue