mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-09-01 20:12:50 +02:00
Make curl_multi_wakeup/curl_multi_poll usage optional
Thus dropping the minimum required libcurl version to at least 7.64, possibly further. We have compatibility macros all the way to 7.55 so yeah. Also fix RequestManagerImpl::~RequestManagerImpl not doing a wakeup after setting running = false. This meant that in the worst case the worker would wake up 1000ms later and only then notice running = false and exit, making the game take overall longer to exit.
This commit is contained in:
@@ -14,6 +14,9 @@
|
|||||||
#if defined(CURL_AT_LEAST_VERSION) && CURL_AT_LEAST_VERSION(7, 61, 0)
|
#if defined(CURL_AT_LEAST_VERSION) && CURL_AT_LEAST_VERSION(7, 61, 0)
|
||||||
# define REQUEST_USE_CURL_TLSV13CL
|
# define REQUEST_USE_CURL_TLSV13CL
|
||||||
#endif
|
#endif
|
||||||
|
#if defined(CURL_AT_LEAST_VERSION) && CURL_AT_LEAST_VERSION(7, 68, 0)
|
||||||
|
# define REQUEST_USE_CURL_MULTI_POLL
|
||||||
|
#endif
|
||||||
|
|
||||||
constexpr long curlMaxHostConnections = 1;
|
constexpr long curlMaxHostConnections = 1;
|
||||||
constexpr long curlMaxConcurrentStreams = httpMaxConcurrentStreams;
|
constexpr long curlMaxConcurrentStreams = httpMaxConcurrentStreams;
|
||||||
@@ -137,6 +140,32 @@ namespace http
|
|||||||
|
|
||||||
bool curlGlobalInit = false;
|
bool curlGlobalInit = false;
|
||||||
CURLM *curlMulti = NULL;
|
CURLM *curlMulti = NULL;
|
||||||
|
|
||||||
|
void Wake()
|
||||||
|
{
|
||||||
|
#ifdef REQUEST_USE_CURL_MULTI_POLL
|
||||||
|
curl_multi_wakeup(curlMulti);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void Wait()
|
||||||
|
{
|
||||||
|
int dontcare;
|
||||||
|
#ifdef REQUEST_USE_CURL_MULTI_POLL
|
||||||
|
HandleCURLMcode(curl_multi_poll(curlMulti, NULL, 0, 100000, &dontcare));
|
||||||
|
#else
|
||||||
|
constexpr auto TickMs = 100;
|
||||||
|
if (requestHandles.size())
|
||||||
|
{
|
||||||
|
HandleCURLMcode(curl_multi_wait(curlMulti, NULL, 0, TickMs, &dontcare));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(TickMs));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
RequestManagerImpl::RequestManagerImpl(ByteString newProxy, ByteString newCafile, ByteString newCapath, bool newDisableNetwork) :
|
RequestManagerImpl::RequestManagerImpl(ByteString newProxy, ByteString newCafile, ByteString newCapath, bool newDisableNetwork) :
|
||||||
@@ -153,6 +182,7 @@ namespace http
|
|||||||
std::lock_guard lk(sharedStateMx);
|
std::lock_guard lk(sharedStateMx);
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
Wake();
|
||||||
worker.join();
|
worker.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,8 +205,8 @@ namespace http
|
|||||||
void RequestManagerImpl::WorkerPerform()
|
void RequestManagerImpl::WorkerPerform()
|
||||||
{
|
{
|
||||||
auto manager = static_cast<RequestManagerImpl *>(this);
|
auto manager = static_cast<RequestManagerImpl *>(this);
|
||||||
|
manager->Wait();
|
||||||
int dontcare;
|
int dontcare;
|
||||||
HandleCURLMcode(curl_multi_poll(manager->curlMulti, NULL, 0, 1000, &dontcare));
|
|
||||||
HandleCURLMcode(curl_multi_perform(manager->curlMulti, &dontcare));
|
HandleCURLMcode(curl_multi_perform(manager->curlMulti, &dontcare));
|
||||||
while (auto msg = curl_multi_info_read(manager->curlMulti, &dontcare))
|
while (auto msg = curl_multi_info_read(manager->curlMulti, &dontcare))
|
||||||
{
|
{
|
||||||
@@ -313,7 +343,7 @@ namespace http
|
|||||||
std::lock_guard lk(manager->sharedStateMx);
|
std::lock_guard lk(manager->sharedStateMx);
|
||||||
manager->requestHandlesToRegister.push_back(request.handle);
|
manager->requestHandlesToRegister.push_back(request.handle);
|
||||||
}
|
}
|
||||||
curl_multi_wakeup(manager->curlMulti);
|
manager->Wake();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestManager::UnregisterRequestImpl(Request &request)
|
void RequestManager::UnregisterRequestImpl(Request &request)
|
||||||
@@ -323,7 +353,7 @@ namespace http
|
|||||||
std::lock_guard lk(manager->sharedStateMx);
|
std::lock_guard lk(manager->sharedStateMx);
|
||||||
manager->requestHandlesToUnregister.push_back(request.handle);
|
manager->requestHandlesToUnregister.push_back(request.handle);
|
||||||
}
|
}
|
||||||
curl_multi_wakeup(manager->curlMulti);
|
manager->Wake();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestManagerImpl::RegisterRequestHandle(std::shared_ptr<RequestHandle> requestHandle)
|
void RequestManagerImpl::RegisterRequestHandle(std::shared_ptr<RequestHandle> requestHandle)
|
||||||
|
Reference in New Issue
Block a user