mirror of https://github.com/PCSX2/pcsx2.git
Achievements: Use retryable client error status code
This commit is contained in:
parent
5e48e0d8c0
commit
e9a4d9702c
|
@ -118,7 +118,7 @@ void HTTPDownloader::LockedPollRequests(std::unique_lock<std::mutex>& lock)
|
||||||
m_pending_http_requests.erase(m_pending_http_requests.begin() + index);
|
m_pending_http_requests.erase(m_pending_http_requests.begin() + index);
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
|
|
||||||
req->callback(-1, req->content_type, Request::Data());
|
req->callback(HTTP_STATUS_TIMEOUT, req->content_type, Request::Data());
|
||||||
|
|
||||||
CloseRequest(req);
|
CloseRequest(req);
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,10 @@ namespace Common
|
||||||
public:
|
public:
|
||||||
enum : s32
|
enum : s32
|
||||||
{
|
{
|
||||||
HTTP_OK = 200
|
HTTP_STATUS_CANCELLED = -3,
|
||||||
|
HTTP_STATUS_TIMEOUT = -2,
|
||||||
|
HTTP_STATUS_ERROR = -1,
|
||||||
|
HTTP_STATUS_OK = 200
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Request
|
struct Request
|
||||||
|
|
|
@ -107,7 +107,7 @@ void CALLBACK HTTPDownloaderWinHttp::HTTPStatusCallback(HINTERNET hRequest, DWOR
|
||||||
{
|
{
|
||||||
const WINHTTP_ASYNC_RESULT* res = reinterpret_cast<const WINHTTP_ASYNC_RESULT*>(lpvStatusInformation);
|
const WINHTTP_ASYNC_RESULT* res = reinterpret_cast<const WINHTTP_ASYNC_RESULT*>(lpvStatusInformation);
|
||||||
Console.Error("WinHttp async function %p returned error %u", res->dwResult, res->dwError);
|
Console.Error("WinHttp async function %p returned error %u", res->dwResult, res->dwError);
|
||||||
req->status_code = -1;
|
req->status_code = HTTP_STATUS_ERROR;
|
||||||
req->state.store(Request::State::Complete);
|
req->state.store(Request::State::Complete);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ void CALLBACK HTTPDownloaderWinHttp::HTTPStatusCallback(HINTERNET hRequest, DWOR
|
||||||
if (!WinHttpReceiveResponse(hRequest, nullptr))
|
if (!WinHttpReceiveResponse(hRequest, nullptr))
|
||||||
{
|
{
|
||||||
Console.Error("WinHttpReceiveResponse() failed: %u", GetLastError());
|
Console.Error("WinHttpReceiveResponse() failed: %u", GetLastError());
|
||||||
req->status_code = -1;
|
req->status_code = HTTP_STATUS_ERROR;
|
||||||
req->state.store(Request::State::Complete);
|
req->state.store(Request::State::Complete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ void CALLBACK HTTPDownloaderWinHttp::HTTPStatusCallback(HINTERNET hRequest, DWOR
|
||||||
WINHTTP_HEADER_NAME_BY_INDEX, &req->status_code, &buffer_size, WINHTTP_NO_HEADER_INDEX))
|
WINHTTP_HEADER_NAME_BY_INDEX, &req->status_code, &buffer_size, WINHTTP_NO_HEADER_INDEX))
|
||||||
{
|
{
|
||||||
Console.Error("WinHttpQueryHeaders() for status code failed: %u", GetLastError());
|
Console.Error("WinHttpQueryHeaders() for status code failed: %u", GetLastError());
|
||||||
req->status_code = -1;
|
req->status_code = HTTP_STATUS_ERROR;
|
||||||
req->state.store(Request::State::Complete);
|
req->state.store(Request::State::Complete);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ void CALLBACK HTTPDownloaderWinHttp::HTTPStatusCallback(HINTERNET hRequest, DWOR
|
||||||
if (!WinHttpQueryDataAvailable(hRequest, nullptr) && GetLastError() != ERROR_IO_PENDING)
|
if (!WinHttpQueryDataAvailable(hRequest, nullptr) && GetLastError() != ERROR_IO_PENDING)
|
||||||
{
|
{
|
||||||
Console.Error("WinHttpQueryDataAvailable() failed: %u", GetLastError());
|
Console.Error("WinHttpQueryDataAvailable() failed: %u", GetLastError());
|
||||||
req->status_code = -1;
|
req->status_code = HTTP_STATUS_ERROR;
|
||||||
req->state.store(Request::State::Complete);
|
req->state.store(Request::State::Complete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ void CALLBACK HTTPDownloaderWinHttp::HTTPStatusCallback(HINTERNET hRequest, DWOR
|
||||||
GetLastError() != ERROR_IO_PENDING)
|
GetLastError() != ERROR_IO_PENDING)
|
||||||
{
|
{
|
||||||
Console.Error("WinHttpReadData() failed: %u", GetLastError());
|
Console.Error("WinHttpReadData() failed: %u", GetLastError());
|
||||||
req->status_code = -1;
|
req->status_code = HTTP_STATUS_ERROR;
|
||||||
req->state.store(Request::State::Complete);
|
req->state.store(Request::State::Complete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ void CALLBACK HTTPDownloaderWinHttp::HTTPStatusCallback(HINTERNET hRequest, DWOR
|
||||||
if (!WinHttpQueryDataAvailable(hRequest, nullptr) && GetLastError() != ERROR_IO_PENDING)
|
if (!WinHttpQueryDataAvailable(hRequest, nullptr) && GetLastError() != ERROR_IO_PENDING)
|
||||||
{
|
{
|
||||||
Console.Error("WinHttpQueryDataAvailable() failed: %u", GetLastError());
|
Console.Error("WinHttpQueryDataAvailable() failed: %u", GetLastError());
|
||||||
req->status_code = -1;
|
req->status_code = HTTP_STATUS_ERROR;
|
||||||
req->state.store(Request::State::Complete);
|
req->state.store(Request::State::Complete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ bool HTTPDownloaderWinHttp::StartRequest(HTTPDownloader::Request* request)
|
||||||
if (!WinHttpCrackUrl(url_wide.c_str(), static_cast<DWORD>(url_wide.size()), 0, &uc))
|
if (!WinHttpCrackUrl(url_wide.c_str(), static_cast<DWORD>(url_wide.size()), 0, &uc))
|
||||||
{
|
{
|
||||||
Console.Error("WinHttpCrackUrl() failed: %u", GetLastError());
|
Console.Error("WinHttpCrackUrl() failed: %u", GetLastError());
|
||||||
req->callback(-1, req->content_type, Request::Data());
|
req->callback(HTTP_STATUS_ERROR, req->content_type, Request::Data());
|
||||||
delete req;
|
delete req;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -269,7 +269,7 @@ bool HTTPDownloaderWinHttp::StartRequest(HTTPDownloader::Request* request)
|
||||||
if (!req->hConnection)
|
if (!req->hConnection)
|
||||||
{
|
{
|
||||||
Console.Error("Failed to start HTTP request for '%s': %u", req->url.c_str(), GetLastError());
|
Console.Error("Failed to start HTTP request for '%s': %u", req->url.c_str(), GetLastError());
|
||||||
req->callback(-1, req->content_type, Request::Data());
|
req->callback(HTTP_STATUS_ERROR, req->content_type, Request::Data());
|
||||||
delete req;
|
delete req;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -302,7 +302,7 @@ bool HTTPDownloaderWinHttp::StartRequest(HTTPDownloader::Request* request)
|
||||||
if (!result && GetLastError() != ERROR_IO_PENDING)
|
if (!result && GetLastError() != ERROR_IO_PENDING)
|
||||||
{
|
{
|
||||||
Console.Error("WinHttpSendRequest() failed: %u", GetLastError());
|
Console.Error("WinHttpSendRequest() failed: %u", GetLastError());
|
||||||
req->status_code = -1;
|
req->status_code = HTTP_STATUS_ERROR;
|
||||||
req->state.store(Request::State::Complete);
|
req->state.store(Request::State::Complete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -353,7 +353,7 @@ std::string Achievements::GetGameHash()
|
||||||
void Achievements::DownloadImage(std::string url, std::string cache_filename)
|
void Achievements::DownloadImage(std::string url, std::string cache_filename)
|
||||||
{
|
{
|
||||||
auto callback = [cache_filename](s32 status_code, std::string content_type, Common::HTTPDownloader::Request::Data data) {
|
auto callback = [cache_filename](s32 status_code, std::string content_type, Common::HTTPDownloader::Request::Data data) {
|
||||||
if (status_code != Common::HTTPDownloader::HTTP_OK)
|
if (status_code != Common::HTTPDownloader::HTTP_STATUS_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!FileSystem::WriteBinaryFile(cache_filename.c_str(), data.data(), data.size()))
|
if (!FileSystem::WriteBinaryFile(cache_filename.c_str(), data.data(), data.size()))
|
||||||
|
@ -652,7 +652,10 @@ void Achievements::ClientServerCall(
|
||||||
Common::HTTPDownloader::Request::Callback hd_callback = [callback, callback_data](s32 status_code, std::string content_type,
|
Common::HTTPDownloader::Request::Callback hd_callback = [callback, callback_data](s32 status_code, std::string content_type,
|
||||||
Common::HTTPDownloader::Request::Data data) {
|
Common::HTTPDownloader::Request::Data data) {
|
||||||
rc_api_server_response_t rr;
|
rc_api_server_response_t rr;
|
||||||
rr.http_status_code = status_code;
|
rr.http_status_code = (status_code <= 0) ? (status_code == Common::HTTPDownloader::HTTP_STATUS_CANCELLED ?
|
||||||
|
RC_API_SERVER_RESPONSE_CLIENT_ERROR :
|
||||||
|
RC_API_SERVER_RESPONSE_RETRYABLE_CLIENT_ERROR) :
|
||||||
|
status_code;
|
||||||
rr.body_length = data.size();
|
rr.body_length = data.size();
|
||||||
rr.body = reinterpret_cast<const char*>(data.data());
|
rr.body = reinterpret_cast<const char*>(data.data());
|
||||||
|
|
||||||
|
|
|
@ -1319,7 +1319,7 @@ bool GameList::DownloadCovers(const std::vector<std::string>& url_templates, boo
|
||||||
downloader->CreateRequest(
|
downloader->CreateRequest(
|
||||||
std::move(url), [use_serial, &save_callback, entry_path = std::move(entry_path), filename = std::move(filename)](
|
std::move(url), [use_serial, &save_callback, entry_path = std::move(entry_path), filename = std::move(filename)](
|
||||||
s32 status_code, const std::string& content_type, Common::HTTPDownloader::Request::Data data) {
|
s32 status_code, const std::string& content_type, Common::HTTPDownloader::Request::Data data) {
|
||||||
if (status_code != Common::HTTPDownloader::HTTP_OK || data.empty())
|
if (status_code != Common::HTTPDownloader::HTTP_STATUS_OK || data.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::unique_lock lock(s_mutex);
|
std::unique_lock lock(s_mutex);
|
||||||
|
|
Loading…
Reference in New Issue