summaryrefslogtreecommitdiff
path: root/src/net/download.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-05-02 17:07:20 +0300
committerAndrei Karas <akaras@inbox.ru>2017-05-02 17:07:20 +0300
commit79d27e4b7b4a86d8ca33456871de05f86d4d14c8 (patch)
tree076fb7e15c6fd8623a09a8e3ffdccb5bb897b831 /src/net/download.cpp
parent436443304ddd09d98b30602dbbb670cc856e239e (diff)
downloadmv-79d27e4b7b4a86d8ca33456871de05f86d4d14c8.tar.gz
mv-79d27e4b7b4a86d8ca33456871de05f86d4d14c8.tar.bz2
mv-79d27e4b7b4a86d8ca33456871de05f86d4d14c8.tar.xz
mv-79d27e4b7b4a86d8ca33456871de05f86d4d14c8.zip
Add temination flag for background download threads.
This probably will fix random crash in tests after start and exit.
Diffstat (limited to 'src/net/download.cpp')
-rw-r--r--src/net/download.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/net/download.cpp b/src/net/download.cpp
index feb92265c..6a1f4cc83 100644
--- a/src/net/download.cpp
+++ b/src/net/download.cpp
@@ -37,6 +37,8 @@
const char *DOWNLOAD_ERROR_MESSAGE_THREAD
= "Could not create download thread!";
+extern volatile bool isTerminate;
+
enum
{
OPTIONS_NONE = 0,
@@ -270,11 +272,14 @@ int Download::downloadThread(void *ptr)
d->mUrlQueue.pop();
logger->log_r("selected url: %s", d->mUrl.c_str());
- while (attempts < 3 && !complete && !d->mOptions.cancel)
+ while (attempts < 3 &&
+ !complete &&
+ !d->mOptions.cancel &&
+ isTerminate == false)
{
d->mUpdateFunction(d->mPtr, DownloadStatus::Starting, 0, 0);
- if (d->mOptions.cancel)
+ if (d->mOptions.cancel || isTerminate == true)
{
// need terminate thread?
d->mThread = nullptr;
@@ -282,7 +287,7 @@ int Download::downloadThread(void *ptr)
}
d->mCurl = curl_easy_init();
- if (d->mCurl && !d->mOptions.cancel)
+ if (d->mCurl && !d->mOptions.cancel && isTerminate == false)
{
FILE *file = nullptr;
@@ -337,8 +342,9 @@ int Download::downloadThread(void *ptr)
secureCurl(d->mCurl);
}
- if ((res = curl_easy_perform(d->mCurl)) != 0
- && !d->mOptions.cancel)
+ if ((res = curl_easy_perform(d->mCurl)) != 0 &&
+ !d->mOptions.cancel &&
+ isTerminate == false)
{
PRAGMA45(GCC diagnostic push)
PRAGMA45(GCC diagnostic ignored "-Wswitch-enum")
@@ -364,7 +370,7 @@ int Download::downloadThread(void *ptr)
continue;
}
- if (d->mOptions.cancel)
+ if (d->mOptions.cancel || isTerminate == true)
break;
// d->mUpdateFunction(d->mPtr, DownloadStatus::Error, 0, 0);
@@ -429,7 +435,7 @@ int Download::downloadThread(void *ptr)
// Any existing file with this name is deleted first,
// otherwise the rename will fail on Windows.
- if (!d->mOptions.cancel)
+ if (!d->mOptions.cancel && isTerminate == false)
{
if (d->mIsXml)
{
@@ -469,7 +475,7 @@ int Download::downloadThread(void *ptr)
d->mCurl = nullptr;
}
- if (d->mOptions.cancel)
+ if (d->mOptions.cancel || isTerminate == true)
{
// need ternibate thread?
d->mThread = nullptr;
@@ -484,7 +490,7 @@ int Download::downloadThread(void *ptr)
d->mThread = nullptr;
- if (d->mOptions.cancel)
+ if (d->mOptions.cancel || isTerminate == true)
{
// Nothing to do...
}