mirror of
https://github.com/minetest/minetest.git
synced 2024-11-05 07:13:46 +01:00
Use unique_ptrs for CurlFetchThread::m_all_ongoing
This commit is contained in:
parent
d0bcdff5ce
commit
cfb1b879e0
@ -457,7 +457,7 @@ protected:
|
|||||||
size_t m_parallel_limit;
|
size_t m_parallel_limit;
|
||||||
|
|
||||||
// Variables exclusively used within thread
|
// Variables exclusively used within thread
|
||||||
std::vector<HTTPFetchOngoing*> m_all_ongoing;
|
std::vector<std::unique_ptr<HTTPFetchOngoing>> m_all_ongoing;
|
||||||
std::list<HTTPFetchRequest> m_queued_fetches;
|
std::list<HTTPFetchRequest> m_queued_fetches;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -513,11 +513,8 @@ protected:
|
|||||||
u64 caller = req.fetch_request.caller;
|
u64 caller = req.fetch_request.caller;
|
||||||
|
|
||||||
// Abort all ongoing fetches for the caller
|
// Abort all ongoing fetches for the caller
|
||||||
for (std::vector<HTTPFetchOngoing*>::iterator
|
for (auto it = m_all_ongoing.begin(); it != m_all_ongoing.end();) {
|
||||||
it = m_all_ongoing.begin();
|
|
||||||
it != m_all_ongoing.end();) {
|
|
||||||
if ((*it)->getRequest().caller == caller) {
|
if ((*it)->getRequest().caller == caller) {
|
||||||
delete (*it);
|
|
||||||
it = m_all_ongoing.erase(it);
|
it = m_all_ongoing.erase(it);
|
||||||
} else {
|
} else {
|
||||||
++it;
|
++it;
|
||||||
@ -552,17 +549,14 @@ protected:
|
|||||||
|
|
||||||
// Create ongoing fetch data and make a cURL handle
|
// Create ongoing fetch data and make a cURL handle
|
||||||
// Set cURL options based on HTTPFetchRequest
|
// Set cURL options based on HTTPFetchRequest
|
||||||
HTTPFetchOngoing *ongoing =
|
auto ongoing = std::make_unique<HTTPFetchOngoing>(request, pool);
|
||||||
new HTTPFetchOngoing(request, pool);
|
|
||||||
|
|
||||||
// Initiate the connection (curl_multi_add_handle)
|
// Initiate the connection (curl_multi_add_handle)
|
||||||
CURLcode res = ongoing->start(m_multi);
|
CURLcode res = ongoing->start(m_multi);
|
||||||
if (res == CURLE_OK) {
|
if (res == CURLE_OK) {
|
||||||
m_all_ongoing.push_back(ongoing);
|
m_all_ongoing.push_back(std::move(ongoing));
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
httpfetch_deliver_result(*ongoing->complete(res));
|
httpfetch_deliver_result(*ongoing->complete(res));
|
||||||
delete ongoing;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -581,9 +575,8 @@ protected:
|
|||||||
}
|
}
|
||||||
if (msg->msg == CURLMSG_DONE && found) {
|
if (msg->msg == CURLMSG_DONE && found) {
|
||||||
// m_all_ongoing[i] succeeded or failed.
|
// m_all_ongoing[i] succeeded or failed.
|
||||||
HTTPFetchOngoing *ongoing = m_all_ongoing[i];
|
HTTPFetchOngoing &ongoing = *m_all_ongoing[i];
|
||||||
httpfetch_deliver_result(*ongoing->complete(msg->data.result));
|
httpfetch_deliver_result(*ongoing.complete(msg->data.result));
|
||||||
delete ongoing;
|
|
||||||
m_all_ongoing.erase(m_all_ongoing.begin() + i);
|
m_all_ongoing.erase(m_all_ongoing.begin() + i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -726,9 +719,6 @@ protected:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call curl_multi_remove_handle and cleanup easy handles
|
// Call curl_multi_remove_handle and cleanup easy handles
|
||||||
for (HTTPFetchOngoing *i : m_all_ongoing) {
|
|
||||||
delete i;
|
|
||||||
}
|
|
||||||
m_all_ongoing.clear();
|
m_all_ongoing.clear();
|
||||||
|
|
||||||
m_queued_fetches.clear();
|
m_queued_fetches.clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user