diff --git a/include/network/network_downloader.hpp b/include/network/network_downloader.hpp index 4b98b979..5914f567 100644 --- a/include/network/network_downloader.hpp +++ b/include/network/network_downloader.hpp @@ -9,6 +9,7 @@ struct NetworkStream { static constexpr u64 BLOCK_SIZE = 0x40000; // 256 KiB static constexpr u64 MAX_CACHE_BLOCKS = 12 * 1000 * 1000 / BLOCK_SIZE; + static constexpr int RETRY_CNT_MAX = 1; u64 block_num = 0; std::string url; @@ -23,6 +24,7 @@ struct NetworkStream { volatile bool suspend_request = false; volatile bool quit_request = false; volatile bool error = false; + volatile int retry_cnt_left = RETRY_CNT_MAX; volatile u64 read_head = 0; const char * volatile network_waiting_status = NULL; bool disable_interrupt = false; diff --git a/include/network/network_io.hpp b/include/network/network_io.hpp index e1a33a90..f446290b 100644 --- a/include/network/network_io.hpp +++ b/include/network/network_io.hpp @@ -39,6 +39,7 @@ private : void deinit(); // will be called for each instance when the app exits public : CURL* curl = NULL; + char *curl_errbuf; // should not be used from outside network_io.cpp std::map sessions; std::vector *buffer; diff --git a/source/network/network_downloader.cpp b/source/network/network_downloader.cpp index 36479bc6..5cc1c412 100644 --- a/source/network/network_downloader.cpp +++ b/source/network/network_downloader.cpp @@ -268,10 +268,13 @@ void NetworkStreamDownloader::downloader_thread() { } if (cur_stream->ready && result.data.size() != expected_len) { Util_log_save(LOG_THREAD_STR, "size discrepancy : " + std::to_string(expected_len) + " -> " + std::to_string(result.data.size())); - cur_stream->error = true; + if (cur_stream->retry_cnt_left) { + cur_stream->retry_cnt_left--; + } else cur_stream->error = true; result.finalize(); continue; } + cur_stream->retry_cnt_left = NetworkStream::RETRY_CNT_MAX; cur_stream->set_data(block_reading, result.data); cur_stream->ready = true; } else { diff --git a/source/network/network_io.cpp b/source/network/network_io.cpp index fbec45a9..6041f3af 100644 --- a/source/network/network_io.cpp +++ b/source/network/network_io.cpp @@ -564,6 +564,8 @@ static NetworkResult access_http_internal(NetworkSessionList &session_list, cons curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_receive_data_callback_func); curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, curl_receive_headers_callback_func); curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, curl_set_socket_options); + session_list.curl_errbuf = (char *) malloc(CURL_ERROR_SIZE); + curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, session_list.curl_errbuf); // curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout); } curl_easy_setopt(curl, CURLOPT_WRITEDATA, &res.data); @@ -587,7 +589,7 @@ static NetworkResult access_http_internal(NetworkSessionList &session_list, cons curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &redirected_url); res.redirected_url = redirected_url; if (res.redirected_url != url) Util_log_save("curl", "redir : " + res.redirected_url); - } else Util_log_save("curl", "deep fail"); + } else Util_log_save("curl", std::string("deep fail : ") + curl_easy_strerror(curl_code) + " / " + session_list.curl_errbuf); curl_slist_free_all(request_headers_list); }