HTTPDownloader: Don't poll requests when cancelling

Confusing to the caller...
pull/3745/head
Stenzek 4 months ago
parent 5b446d702a
commit 2091cb101c
No known key found for this signature in database

@ -328,12 +328,11 @@ void HTTPDownloader::CancelRequestsForOwner(const void* owner)
{
std::unique_lock lock(m_pending_http_request_lock);
bool has_pending_requests = false;
// one request might start another, so loop multiple times until we match none
bool had_matching_requests;
do
{
has_pending_requests = false;
LockedPollRequests(lock);
had_matching_requests = false;
for (size_t index = 0; index < m_pending_http_requests.size();)
{
@ -344,18 +343,11 @@ void HTTPDownloader::CancelRequestsForOwner(const void* owner)
continue;
}
// Should never be cancelled at this point.
const Request::State req_state = req->state.load(std::memory_order_acquire);
DebugAssert(req_state != Request::State::Cancelled);
// can't cancel a request in pending stage
if (req_state == Request::State::Pending)
{
has_pending_requests = true;
index++;
continue;
}
else if (req_state == Request::State::Started || req_state == Request::State::Receiving)
{
// request timed out
// Cancel even completed requests.
ERROR_LOG("Request for '{}' cancelled", req->url);
req->state.store(Request::State::Cancelled, std::memory_order_release);
@ -365,15 +357,17 @@ void HTTPDownloader::CancelRequestsForOwner(const void* owner)
req->error.SetStringView("Request was cancelled.");
req->callback(HTTP_STATUS_CANCELLED, req->error, req->content_type, req->data);
// If pending, we can delete it immediately since it won't be processed by the worker thread.
// Otherwise, we need to close it so the worker thread can clean up properly.
if (req_state == Request::State::Pending)
delete req;
else
CloseRequest(req);
lock.lock();
continue;
}
index++;
had_matching_requests = true;
}
} while (has_pending_requests);
} while (had_matching_requests);
}
std::string HTTPDownloader::GetExtensionForContentType(const std::string& content_type)

Loading…
Cancel
Save