From c65e0fc36a9ce931999768ed838d1a2f1dd87794 Mon Sep 17 00:00:00 2001 From: a Date: Fri, 16 Aug 2024 14:34:55 +0300 Subject: [PATCH] fix a bug in `Steam_HTTP::SendHTTPRequest()` where the ID of the triggered call-result from online requests was completely unrelated to the original request, resulting in timeout --- dll/dll/steam_http.h | 2 +- dll/steam_http.cpp | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/dll/dll/steam_http.h b/dll/dll/steam_http.h index 4634a5784..0ead950de 100644 --- a/dll/dll/steam_http.h +++ b/dll/dll/steam_http.h @@ -67,7 +67,7 @@ public ISteamHTTP std::vector requests{}; Steam_Http_Request *get_request(HTTPRequestHandle hRequest); - void online_http_request(Steam_Http_Request *request, SteamAPICall_t *pCallHandle); + void online_http_request(Steam_Http_Request *request, SteamAPICall_t call_res_id); public: Steam_HTTP(class Settings *settings, class Networking *network, class SteamCallResults *callback_results, class SteamCallBacks *callbacks); diff --git a/dll/steam_http.cpp b/dll/steam_http.cpp index 86035e670..08a801948 100644 --- a/dll/steam_http.cpp +++ b/dll/steam_http.cpp @@ -189,12 +189,12 @@ static int curl_debug_trace( } -void Steam_HTTP::online_http_request(Steam_Http_Request *request, SteamAPICall_t *pCallHandle) +void Steam_HTTP::online_http_request(Steam_Http_Request *request, SteamAPICall_t call_res_id) { PRINT_DEBUG("attempting to download from url: '%s', target filepath: '%s'", request->url.c_str(), request->target_filepath.c_str()); - const auto send_callresult = [&]() -> void { + const auto send_callresult = [=]() -> void { struct HTTPRequestCompleted_t data{}; data.m_hRequest = request->handle; data.m_ulContextValue = request->context_value; @@ -202,16 +202,13 @@ void Steam_HTTP::online_http_request(Steam_Http_Request *request, SteamAPICall_t if (request->response.empty() && !settings->force_steamhttp_success) { data.m_bRequestSuccessful = false; data.m_eStatusCode = k_EHTTPStatusCode404NotFound; - } else { data.m_bRequestSuccessful = true; data.m_eStatusCode = k_EHTTPStatusCode200OK; } - auto callres = callback_results->addCallResult(data.k_iCallback, &data, sizeof(data), 0.1); - if (pCallHandle) *pCallHandle = callres; - - callbacks->addCBResult(data.k_iCallback, &data, sizeof(data), 0.1); + callback_results->addCallResult(call_res_id, data.k_iCallback, &data, sizeof(data)); + callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); }; std::size_t filename_part = request->target_filepath.find_last_of("\\/"); @@ -378,7 +375,10 @@ bool Steam_HTTP::SendHTTPRequest( HTTPRequestHandle hRequest, SteamAPICall_t *pC if (request->response.empty() && request->target_filepath.size() && !settings->disable_networking && settings->download_steamhttp_requests) { - std::thread(&Steam_HTTP::online_http_request, this, request, pCallHandle).detach(); + auto call_res_id = callback_results->reserveCallResult(); + if (pCallHandle) *pCallHandle = call_res_id; + + std::thread(&Steam_HTTP::online_http_request, this, request, call_res_id).detach(); } else { struct HTTPRequestCompleted_t data{}; data.m_hRequest = request->handle; @@ -387,7 +387,6 @@ bool Steam_HTTP::SendHTTPRequest( HTTPRequestHandle hRequest, SteamAPICall_t *pC if (request->response.empty() && !settings->force_steamhttp_success) { data.m_bRequestSuccessful = false; data.m_eStatusCode = k_EHTTPStatusCode404NotFound; - } else { data.m_bRequestSuccessful = true; data.m_eStatusCode = k_EHTTPStatusCode200OK;