summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2009-12-05 02:33:52 +0200
committerJared Adams <jaxad0127@gmail.com>2009-12-04 18:56:18 -0700
commit1eb02f83a5d3895e4e18db30ea10d88da94ba4c0 (patch)
treeee1696d4055dd6945e714b8896ed13a187946546 /src
parent91af32bac65b20a446f2e49f023d3d526729e8ea (diff)
downloadmana-1eb02f83a5d3895e4e18db30ea10d88da94ba4c0.tar.gz
mana-1eb02f83a5d3895e4e18db30ea10d88da94ba4c0.tar.bz2
mana-1eb02f83a5d3895e4e18db30ea10d88da94ba4c0.tar.xz
mana-1eb02f83a5d3895e4e18db30ea10d88da94ba4c0.zip
Fixing multi thread crash.
Diffstat (limited to 'src')
-rw-r--r--src/gui/serverdialog.cpp4
-rw-r--r--src/gui/updatewindow.cpp4
-rw-r--r--src/net/download.cpp31
3 files changed, 35 insertions, 4 deletions
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index 9c1494d0..ec2b0cf4 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -171,6 +171,10 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir):
ServerDialog::~ServerDialog()
{
+ if (mDownload)
+ {
+ mDownload->cancel();
+ }
delete mServersListModel;
}
diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp
index 14ebe6b1..801bd161 100644
--- a/src/gui/updatewindow.cpp
+++ b/src/gui/updatewindow.cpp
@@ -115,6 +115,10 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost,
UpdaterWindow::~UpdaterWindow()
{
+ if (mDownload)
+ {
+ mDownload->cancel();
+ }
free(mMemoryBuffer);
}
diff --git a/src/net/download.cpp b/src/net/download.cpp
index 2d626270..51034e0c 100644
--- a/src/net/download.cpp
+++ b/src/net/download.cpp
@@ -136,7 +136,13 @@ bool Download::start()
void Download::cancel()
{
logger->log("Canceling download: %s\n", mUrl.c_str());
+
mOptions.cancel = true;
+ if (mThread && SDL_GetThreadID(mThread) != 0)
+ {
+ SDL_WaitThread(mThread, NULL);
+ mThread = NULL;
+ }
}
char *Download::getError()
@@ -167,20 +173,30 @@ int Download::downloadThread(void *ptr)
CURLcode res;
std::string outFilename;
+ if (!d)
+ {
+ return 0;
+ }
if (!d->mOptions.memoryWrite)
{
outFilename = d->mFileName + ".part";
}
- while (attempts < 3 && !complete)
+ while (attempts < 3 && !complete && !d->mOptions.cancel)
{
FILE *file = NULL;
d->mUpdateFunction(d->mPtr, DOWNLOAD_STATUS_STARTING, 0, 0);
+ if (d->mOptions.cancel)
+ {
+ d->mThread = NULL;
+ return 0;
+ }
+
d->mCurl = curl_easy_init();
- if (d->mCurl)
+ if (d->mCurl && !d->mOptions.cancel)
{
logger->log("Downloading: %s", d->mUrl.c_str());
@@ -211,7 +227,7 @@ int Download::downloadThread(void *ptr)
curl_easy_setopt(d->mCurl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(d->mCurl, CURLOPT_CONNECTTIMEOUT, 15);
- if ((res = curl_easy_perform(d->mCurl)) != 0)
+ if ((res = curl_easy_perform(d->mCurl)) != 0 && !d->mOptions.cancel)
{
switch (res)
{
@@ -285,6 +301,11 @@ int Download::downloadThread(void *ptr)
complete = true;
}
}
+ if (d->mOptions.cancel)
+ {
+ d->mThread = NULL;
+ return 0;
+ }
attempts++;
}
@@ -292,7 +313,8 @@ int Download::downloadThread(void *ptr)
{
// Nothing to do...
}
- else if (!complete || attempts >= 3) {
+ else if (!complete || attempts >= 3)
+ {
d->mUpdateFunction(d->mPtr, DOWNLOAD_STATUS_ERROR, 0, 0);
}
else
@@ -300,6 +322,7 @@ int Download::downloadThread(void *ptr)
d->mUpdateFunction(d->mPtr, DOWNLOAD_STATUS_COMPLETE, 0, 0);
}
+ d->mThread = NULL;
return 0;
}