summaryrefslogtreecommitdiffstats
path: root/src/libs/installer/downloadfiletask.cpp
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@theqtcompany.com>2015-07-01 17:31:11 +0200
committerKarsten Heimrich <karsten.heimrich@theqtcompany.com>2015-07-09 07:58:58 +0000
commita1a11cf402e3c3a54b4d3af4095a6f579f755df8 (patch)
treed2522d347fb5a31e305fabc4edc8aa5c80e7b263 /src/libs/installer/downloadfiletask.cpp
parentf3c92c9e1cabb9bb1314882e66e3c348242a4211 (diff)
Fix canceling the download done by an external call.
Fix canceling the download on blocking connections without events, it will not trigger the Downloader::testCanceled(). Change-Id: Ia74c70cb1ab98189872d39feb1b9ab47f3ccbd22 Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
Diffstat (limited to 'src/libs/installer/downloadfiletask.cpp')
-rw-r--r--src/libs/installer/downloadfiletask.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/libs/installer/downloadfiletask.cpp b/src/libs/installer/downloadfiletask.cpp
index 6bc1a1c8f..b35284b49 100644
--- a/src/libs/installer/downloadfiletask.cpp
+++ b/src/libs/installer/downloadfiletask.cpp
@@ -43,7 +43,6 @@
#include <QNetworkProxyFactory>
#include <QSslError>
#include <QTemporaryFile>
-#include <QTimer>
namespace QInstaller {
@@ -56,6 +55,7 @@ AuthenticationRequiredException::AuthenticationRequiredException(Type type, cons
Downloader::Downloader()
: m_finished(0)
{
+ connect(&m_timer, &QTimer::timeout, this, &Downloader::onTimeout);
connect(&m_nam, &QNetworkAccessManager::finished, this, &Downloader::onFinished);
}
@@ -88,6 +88,8 @@ void Downloader::download(QFutureInterface<FileTaskResult> &fi, const QList<File
void Downloader::doDownload()
{
+ m_timer.start(1000); // Use a timer to check for canceled downloads.
+
foreach (const FileTaskItem &item, m_items) {
if (!startDownload(item))
break;
@@ -323,6 +325,28 @@ void Downloader::onProxyAuthenticationRequired(const QNetworkProxy &proxy, QAuth
}
+/*!
+ \internal
+
+ Canceling from the outside will not get noticed if we are waiting on a connection that
+ does not create any events. QNam will drop after 45 seconds, though the user might have
+ canceled the download before. In that case we block until the QNam timeout is reached,
+ worst case resulting in deadlock while the application is shutting down at the same time.
+*/
+void Downloader::onTimeout()
+{
+ if (testCanceled()) {
+ // Inject exception, we can't use QFuturInterface::reportException() as the exception
+ // store is "frozen" once cancel was called. On the other hand, client code could use
+ // QFutureWatcherBase::isCanceled() or QFuture::isCanceled() to check for canceled futures.
+ m_futureInterface->exceptionStore()
+ .setException(TaskException(tr("Network transfers canceled.")));
+ m_futureInterface->reportFinished();
+ emit finished();
+ }
+}
+
+
// -- private
bool Downloader::testCanceled()