mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-17 05:44:00 +02:00
Fix unknown HTTP response body size being reported as 0 in some cases
Namely, when libcurl dies or when progress is checked before the request is started, although this should never happen.
This commit is contained in:
@@ -371,11 +371,11 @@ namespace http
|
|||||||
{
|
{
|
||||||
#ifdef REQUEST_USE_CURL_OFFSET_T
|
#ifdef REQUEST_USE_CURL_OFFSET_T
|
||||||
curl_off_t total, done;
|
curl_off_t total, done;
|
||||||
HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &total));
|
HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &total)); // stores -1 if unknown
|
||||||
HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_SIZE_DOWNLOAD_T, &done));
|
HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_SIZE_DOWNLOAD_T, &done));
|
||||||
#else
|
#else
|
||||||
double total, done;
|
double total, done;
|
||||||
HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &total));
|
HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &total)); // stores -1 if unknown
|
||||||
HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_SIZE_DOWNLOAD, &done));
|
HandleCURLcode(curl_easy_getinfo(handle->curlEasy, CURLINFO_SIZE_DOWNLOAD, &done));
|
||||||
#endif
|
#endif
|
||||||
handle->bytesTotal = int(total);
|
handle->bytesTotal = int(total);
|
||||||
@@ -383,7 +383,7 @@ namespace http
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
handle->bytesTotal = 0;
|
handle->bytesTotal = -1;
|
||||||
handle->bytesDone = 0;
|
handle->bytesDone = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -37,7 +37,7 @@ namespace http
|
|||||||
State state = ready;
|
State state = ready;
|
||||||
std::mutex stateMx;
|
std::mutex stateMx;
|
||||||
std::condition_variable stateCv;
|
std::condition_variable stateCv;
|
||||||
std::atomic<int> bytesTotal = 0;
|
std::atomic<int> bytesTotal = -1;
|
||||||
std::atomic<int> bytesDone = 0;
|
std::atomic<int> bytesDone = 0;
|
||||||
int statusCode = 0;
|
int statusCode = 0;
|
||||||
ByteString responseData;
|
ByteString responseData;
|
||||||
|
@@ -42,7 +42,14 @@ private:
|
|||||||
{
|
{
|
||||||
int total, done;
|
int total, done;
|
||||||
std::tie(total, done) = request->CheckProgress();
|
std::tie(total, done) = request->CheckProgress();
|
||||||
notifyProgress(total ? done * 100 / total : 0);
|
if (total == -1)
|
||||||
|
{
|
||||||
|
notifyProgress(-1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
notifyProgress(total ? done * 100 / total : 0);
|
||||||
|
}
|
||||||
Platform::Millisleep(1);
|
Platform::Millisleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user