[Pkg-owncloud-commits] [owncloud-client] 10/70: Add a timeout when using the QNAM propagation

Sandro Knauß hefee-guest at moszumanska.debian.org
Sat May 17 20:01:24 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 88cb0471979aa7a3bf4e87d2a309660d0ef7367a
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Wed Apr 30 17:54:14 2014 +0200

    Add a timeout when using the QNAM propagation
---
 src/mirall/networkjobs.h       |  5 +++--
 src/mirall/propagator_qnam.cpp | 49 +++++++++++++++++++++++++++++++++---------
 src/mirall/propagator_qnam.h   | 11 ++++++++++
 3 files changed, 53 insertions(+), 12 deletions(-)

diff --git a/src/mirall/networkjobs.h b/src/mirall/networkjobs.h
index b605a03..d109277 100644
--- a/src/mirall/networkjobs.h
+++ b/src/mirall/networkjobs.h
@@ -63,8 +63,6 @@ public:
     void setReply(QNetworkReply *reply);
     QNetworkReply* reply() const { return _reply; }
 
-    void setTimeout(qint64 msec);
-    void resetTimeout();
 
     void setIgnoreCredentialFailure(bool ignore);
     bool ignoreCredentialFailure() const { return _ignoreCredentialFailure; }
@@ -72,6 +70,9 @@ public:
     QString responseTimestamp();
     quint64 duration();
 
+public slots:
+    void setTimeout(qint64 msec);
+    void resetTimeout();
 signals:
     void networkError(QNetworkReply *reply);
 protected:
diff --git a/src/mirall/propagator_qnam.cpp b/src/mirall/propagator_qnam.cpp
index b79ec20..5cfadf8 100644
--- a/src/mirall/propagator_qnam.cpp
+++ b/src/mirall/propagator_qnam.cpp
@@ -26,6 +26,29 @@
 
 namespace Mirall {
 
+static uint chunkSize() {
+    static uint chunkSize;
+    if (!chunkSize) {
+        chunkSize = qgetenv("OWNCLOUD_CHUNK_SIZE").toUInt();
+        if (chunkSize == 0) {
+            chunkSize = 10*1024*1024; // default to 10 MiB
+        }
+    }
+    return chunkSize;
+}
+
+static qint64 httpTimeout() {
+    static uint timeout;
+    if (!timeout) {
+        timeout = qgetenv("OWNCLOUD_TIMEOUT").toUInt();
+        if (timeout == 0) {
+            timeout = 30; // default to 30 secs
+        }
+    }
+    return timeout;
+}
+
+
 /**
  * Fiven an error from the network, map to a SyncFileItem::Status error
  */
@@ -61,19 +84,14 @@ void PUTFileJob::start() {
     }
 
     connect(reply(), SIGNAL(uploadProgress(qint64,qint64)), this, SIGNAL(uploadProgress(qint64,qint64)));
+    connect(reply(), SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(resetTimeout()));
 
     AbstractNetworkJob::start();
 }
 
-static uint chunkSize() {
-    static uint chunkSize;
-    if (!chunkSize) {
-        chunkSize = qgetenv("OWNCLOUD_CHUNK_SIZE").toUInt();
-        if (chunkSize == 0) {
-            chunkSize = 10*1024*1024; // default to 10 MiB
-        }
-    }
-    return chunkSize;
+void PUTFileJob::slotTimeout() {
+    _errorString =  tr("Connection Timeout");
+    reply()->abort();
 }
 
 void PropagateUploadFileQNAM::start()
@@ -215,6 +233,7 @@ void PropagateUploadFileQNAM::startNextChunk()
         device->open(QIODevice::ReadOnly);
 
     _job = new PUTFileJob(AccountManager::instance()->account(), _propagator->_remoteFolder + path, device, headers);
+    _job->setTimeout(httpTimeout() * 1000);
     connect(_job, SIGNAL(finishedSignal()), this, SLOT(slotPutFinished()));
     connect(_job, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(slotUploadProgress(qint64,qint64)));
     _job->start();
@@ -240,7 +259,7 @@ void PropagateUploadFileQNAM::slotPutFinished()
                "It is restored and your edit is in the conflict file."))) {
             return;
         }
-        QString errorString = job->reply()->errorString();
+        QString errorString = job->errorString();
 
         QByteArray replyContent = job->reply()->readAll();
         qDebug() << replyContent; // display the XML error in the debug
@@ -418,6 +437,7 @@ void GETFileJob::slotReadyRead()
             return;
         }
     }
+    resetTimeout();
 }
 
 
@@ -493,6 +513,7 @@ void PropagateDownloadFileQNAM::start()
     _job = new GETFileJob(AccountManager::instance()->account(),
                           _propagator->_remoteFolder + _item._file,
                           &_tmpFile, headers, expectedEtagForResume);
+    _job->setTimeout(httpTimeout() * 1000);
     connect(_job, SIGNAL(finishedSignal()), this, SLOT(slotGetFinished()));
     connect(_job, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(slotDownloadProgress(qint64,qint64)));
     _propagator->_activeJobs ++;
@@ -611,5 +632,13 @@ void PropagateDownloadFileQNAM::abort()
         _job->reply()->abort();
 }
 
+void GETFileJob::slotTimeout()
+{
+    _errorString =  tr("Connection Timeout");
+    _errorStatus = SyncFileItem::FatalError;
+    reply()->abort();
+}
+
+
 
 }
diff --git a/src/mirall/propagator_qnam.h b/src/mirall/propagator_qnam.h
index 4936d2d..40e15d9 100644
--- a/src/mirall/propagator_qnam.h
+++ b/src/mirall/propagator_qnam.h
@@ -53,6 +53,7 @@ class PUTFileJob : public AbstractNetworkJob {
     Q_OBJECT
     QIODevice* _device;
     QMap<QByteArray, QByteArray> _headers;
+    QString _errorString;
 
 public:
     // Takes ownership of the device
@@ -67,6 +68,13 @@ public:
         return true;
     }
 
+    QString errorString() {
+        return _errorString.isEmpty() ? reply()->errorString() : _errorString;
+    };
+
+    virtual void slotTimeout();
+
+
 signals:
     void finishedSignal();
     void uploadProgress(qint64,qint64);
@@ -124,6 +132,9 @@ public:
 
     SyncFileItem::Status errorStatus() { return _errorStatus; }
 
+    virtual void slotTimeout();
+
+
 signals:
     void finishedSignal();
     void downloadProgress(qint64,qint64);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list