mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-09 17:48:19 +00:00
Format and bump fake curl
This commit is contained in:
parent
d847b0f60c
commit
1f224344ec
|
@ -1 +1 @@
|
|||
Subproject commit 59d64dbb36ade02607ad20a7f3a45605ab1de80d
|
||||
Subproject commit 4d796ea119b52c8901286e14ab96faf7353a5d59
|
|
@ -3,7 +3,9 @@
|
|||
|
||||
#include "kernel.h"
|
||||
|
||||
class IHttpRequest {};
|
||||
class IHttpRequest
|
||||
{
|
||||
};
|
||||
|
||||
class IHttp : public IInterface
|
||||
{
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
#include <engine/storage.h>
|
||||
#include <game/version.h>
|
||||
|
||||
#include <thread>
|
||||
#include <limits>
|
||||
#include <thread>
|
||||
|
||||
#if !defined(CONF_FAMILY_WINDOWS)
|
||||
#include <csignal>
|
||||
|
@ -282,7 +282,8 @@ void CHttpRequest::OnCompletionInternal(std::optional<unsigned int> Result)
|
|||
State = HTTP_DONE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
dbg_msg("http", "%s failed. internal error: %s", m_aUrl, m_aErr);
|
||||
State = HTTP_ERROR;
|
||||
}
|
||||
|
@ -346,9 +347,11 @@ void CHttpRequest::Wait()
|
|||
using namespace std::chrono_literals;
|
||||
|
||||
// This is so uncommon that polling just might work
|
||||
for(;;) {
|
||||
for(;;)
|
||||
{
|
||||
int State = m_State.load(std::memory_order_seq_cst);
|
||||
if(State != HTTP_QUEUED && State != HTTP_RUNNING) {
|
||||
if(State != HTTP_QUEUED && State != HTTP_RUNNING)
|
||||
{
|
||||
return;
|
||||
}
|
||||
std::this_thread::sleep_for(10ms);
|
||||
|
@ -437,24 +440,29 @@ void CHttp::RunLoop()
|
|||
dbg_msg("http", "running");
|
||||
Lock.unlock();
|
||||
|
||||
while(m_State == RUNNING) {
|
||||
while(m_State == RUNNING)
|
||||
{
|
||||
static int NextTimeout = std::numeric_limits<int>::max();
|
||||
int Events = 0;
|
||||
CURLMcode mc = curl_multi_poll(m_pMultiH, NULL, 0, NextTimeout, &Events);
|
||||
|
||||
// We may have been woken up for a shutdown
|
||||
if(m_Shutdown) {
|
||||
if(m_Shutdown)
|
||||
{
|
||||
auto Now = std::chrono::steady_clock::now();
|
||||
if(!m_ShutdownTime.has_value()) {
|
||||
if(!m_ShutdownTime.has_value())
|
||||
{
|
||||
m_ShutdownTime = Now + m_ShutdownDelay;
|
||||
NextTimeout = m_ShutdownDelay.count();
|
||||
}
|
||||
else if(m_ShutdownTime < Now || m_RunningRequests.empty()) {
|
||||
else if(m_ShutdownTime < Now || m_RunningRequests.empty())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(mc != CURLM_OK) {
|
||||
if(mc != CURLM_OK)
|
||||
{
|
||||
Lock.lock();
|
||||
dbg_msg("http", "Failed multi wait: %s", curl_multi_strerror(mc));
|
||||
m_State = ERROR;
|
||||
|
@ -462,7 +470,8 @@ void CHttp::RunLoop()
|
|||
}
|
||||
|
||||
mc = curl_multi_perform(m_pMultiH, &Events);
|
||||
if(mc != CURLM_OK) {
|
||||
if(mc != CURLM_OK)
|
||||
{
|
||||
Lock.lock();
|
||||
dbg_msg("http", "Failed multi perform: %s", curl_multi_strerror(mc));
|
||||
m_State = ERROR;
|
||||
|
@ -470,8 +479,10 @@ void CHttp::RunLoop()
|
|||
}
|
||||
|
||||
struct CURLMsg *m;
|
||||
while((m = curl_multi_info_read(m_pMultiH, &Events))) {
|
||||
if(m->msg == CURLMSG_DONE) {
|
||||
while((m = curl_multi_info_read(m_pMultiH, &Events)))
|
||||
{
|
||||
if(m->msg == CURLMSG_DONE)
|
||||
{
|
||||
auto RequestIt = m_RunningRequests.find(m->easy_handle);
|
||||
dbg_assert(RequestIt != m_RunningRequests.end(), "Running handle not added to map");
|
||||
auto pRequest = std::move(RequestIt->second);
|
||||
|
@ -488,7 +499,8 @@ void CHttp::RunLoop()
|
|||
std::swap(m_PendingRequests, NewRequests);
|
||||
Lock.unlock();
|
||||
|
||||
while(!NewRequests.empty()) {
|
||||
while(!NewRequests.empty())
|
||||
{
|
||||
auto &pRequest = NewRequests.front();
|
||||
dbg_msg("http", "task: %s %s", CHttpRequest::GetRequestType(pRequest->m_Type), pRequest->m_aUrl);
|
||||
|
||||
|
@ -518,7 +530,8 @@ void CHttp::RunLoop()
|
|||
}
|
||||
|
||||
// Only happens if m_State == ERROR, thus we already hold the lock
|
||||
if(!NewRequests.empty()) {
|
||||
if(!NewRequests.empty())
|
||||
{
|
||||
m_PendingRequests.insert(m_PendingRequests.end(), std::make_move_iterator(NewRequests.begin()), std::make_move_iterator(NewRequests.end()));
|
||||
break;
|
||||
}
|
||||
|
@ -528,14 +541,17 @@ void CHttp::RunLoop()
|
|||
Lock.lock();
|
||||
|
||||
bool Cleanup = m_State != ERROR;
|
||||
for(auto &pRequest : m_PendingRequests) {
|
||||
for(auto &pRequest : m_PendingRequests)
|
||||
{
|
||||
str_copy(pRequest->m_aErr, "Shutting down");
|
||||
pRequest->OnCompletionInternal(std::nullopt);
|
||||
}
|
||||
|
||||
for(auto &ReqPair : m_RunningRequests) {
|
||||
for(auto &ReqPair : m_RunningRequests)
|
||||
{
|
||||
auto &[pHandle, pRequest] = ReqPair;
|
||||
if(Cleanup) {
|
||||
if(Cleanup)
|
||||
{
|
||||
curl_multi_remove_handle(m_pMultiH, pHandle);
|
||||
curl_easy_cleanup(pHandle);
|
||||
}
|
||||
|
@ -544,7 +560,8 @@ void CHttp::RunLoop()
|
|||
pRequest->OnCompletionInternal(std::nullopt);
|
||||
}
|
||||
|
||||
if(Cleanup) {
|
||||
if(Cleanup)
|
||||
{
|
||||
curl_multi_cleanup(m_pMultiH);
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
|
|
@ -7,9 +7,9 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
|
||||
#include <engine/http.h>
|
||||
|
@ -185,7 +185,11 @@ public:
|
|||
double Size() const { return m_Size.load(std::memory_order_relaxed); }
|
||||
int Progress() const { return m_Progress.load(std::memory_order_relaxed); }
|
||||
int State() const { return m_State; }
|
||||
bool Done() const { int State = m_State; return State != HTTP_QUEUED && State != HTTP_DONE; }
|
||||
bool Done() const
|
||||
{
|
||||
int State = m_State;
|
||||
return State != HTTP_QUEUED && State != HTTP_DONE;
|
||||
}
|
||||
void Abort() { m_Abort = true; }
|
||||
|
||||
void Wait();
|
||||
|
@ -237,7 +241,8 @@ bool HttpHasIpresolveBug();
|
|||
// In an ideal world this would be a kernel interface
|
||||
class CHttp : public IHttp
|
||||
{
|
||||
enum EState {
|
||||
enum EState
|
||||
{
|
||||
UNINITIALIZED,
|
||||
RUNNING,
|
||||
STOPPING,
|
||||
|
|
|
@ -530,6 +530,7 @@ protected:
|
|||
class CCommunityIconLoadJob : public IJob, public CAbstractCommunityIconJob
|
||||
{
|
||||
CImageInfo m_ImageInfo;
|
||||
|
||||
protected:
|
||||
void Run() override;
|
||||
|
||||
|
|
|
@ -252,7 +252,10 @@ public:
|
|||
return m_pUpdater;
|
||||
}
|
||||
#endif
|
||||
class IHttp *Http() { return m_pHttp; }
|
||||
class IHttp *Http()
|
||||
{
|
||||
return m_pHttp;
|
||||
}
|
||||
|
||||
int NetobjNumCorrections()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue