From a3be7715910434cd8ef9d626b8c9c518e2d5fc40 Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 6 May 2016 22:35:59 +0900 Subject: Make sure the QNetworkReply object is aborted at any failure and even silent destruction of the job --- jobs/basejob.cpp | 9 +++++++-- jobs/basejob.h | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp index e24db012..bcfd5875 100644 --- a/jobs/basejob.cpp +++ b/jobs/basejob.cpp @@ -54,7 +54,11 @@ BaseJob::BaseJob(ConnectionData* connection, JobHttpType type, bool needsToken) BaseJob::~BaseJob() { if( d->reply ) + { + if( d->reply->isRunning() ) + d->reply->abort(); d->reply->deleteLater(); + } delete d; } @@ -115,6 +119,8 @@ void BaseJob::fail(int errorCode, QString errorString) { setError( errorCode ); setErrorText( errorString ); + if( d->reply->isRunning() ) + d->reply->abort(); emitResult(); } @@ -149,8 +155,7 @@ void BaseJob::gotReply() void BaseJob::timeout() { qDebug() << "Timeout!"; - if( d->reply->isRunning() ) - d->reply->abort(); + fail( TimeoutError, "The job has timed out" ); } void BaseJob::sslErrors(const QList& errors) diff --git a/jobs/basejob.h b/jobs/basejob.h index f343c769..f1ad66d1 100644 --- a/jobs/basejob.h +++ b/jobs/basejob.h @@ -45,7 +45,8 @@ namespace QMatrixClient void start() override; - enum ErrorCode { NetworkError = KJob::UserDefinedError, JsonParseError, UserDefinedError }; + enum ErrorCode { NetworkError = KJob::UserDefinedError, + JsonParseError, TimeoutError, UserDefinedError }; signals: /** -- cgit v1.2.3