| 76 | } |
| 77 | |
| 78 | void HTTPDownloader::LockedPollRequests(std::unique_lock<std::mutex>& lock) |
| 79 | { |
| 80 | if (m_pending_http_requests.empty()) |
| 81 | return; |
| 82 | |
| 83 | InternalPollRequests(); |
| 84 | |
| 85 | const Common::Timer::Value current_time = Common::Timer::GetCurrentValue(); |
| 86 | u32 active_requests = 0; |
| 87 | u32 unstarted_requests = 0; |
| 88 | |
| 89 | for (size_t index = 0; index < m_pending_http_requests.size();) |
| 90 | { |
| 91 | Request* req = m_pending_http_requests[index]; |
| 92 | if (req->state == Request::State::Pending) |
| 93 | { |
| 94 | unstarted_requests++; |
| 95 | index++; |
| 96 | continue; |
| 97 | } |
| 98 | |
| 99 | if ((req->state == Request::State::Started || req->state == Request::State::Receiving) && |
| 100 | current_time >= req->start_time && Common::Timer::ConvertValueToSeconds(current_time - req->start_time) >= m_timeout) |
| 101 | { |
| 102 | // request timed out |
| 103 | Console.Error("Request for '%s' timed out", req->url.c_str()); |
| 104 | |
| 105 | req->state.store(Request::State::Cancelled); |
| 106 | m_pending_http_requests.erase(m_pending_http_requests.begin() + index); |
| 107 | lock.unlock(); |
| 108 | |
| 109 | req->callback(HTTP_STATUS_TIMEOUT, std::string(), Request::Data()); |
| 110 | |
| 111 | CloseRequest(req); |
| 112 | |
| 113 | lock.lock(); |
| 114 | continue; |
| 115 | } |
| 116 | else if ((req->state == Request::State::Started || req->state == Request::State::Receiving) && req->progress && |
| 117 | req->progress->IsCancelled()) |
| 118 | { |
| 119 | // request timed out |
| 120 | Console.Error("Request for '%s' cancelled", req->url.c_str()); |
| 121 | |
| 122 | req->state.store(Request::State::Cancelled); |
| 123 | m_pending_http_requests.erase(m_pending_http_requests.begin() + index); |
| 124 | lock.unlock(); |
| 125 | |
| 126 | req->callback(HTTP_STATUS_CANCELLED, std::string(), Request::Data()); |
| 127 | |
| 128 | CloseRequest(req); |
| 129 | |
| 130 | lock.lock(); |
| 131 | continue; |
| 132 | } |
| 133 | |
| 134 | if (req->state != Request::State::Complete) |
| 135 | { |
nothing calls this directly
no test coverage detected