]> git.sur5r.net Git - minitube/commitdiff
Fix retry
authorFlavio <flavio@odisseo.local>
Mon, 28 Jan 2013 09:32:02 +0000 (10:32 +0100)
committerFlavio <flavio@odisseo.local>
Mon, 28 Jan 2013 09:32:02 +0000 (10:32 +0100)
src/networkaccess.cpp
src/networkaccess.h

index e779de8559cf6b238201a20ccb39f9ef866baba3..4ed98b7688eb37b1fb50b11991d806617a05a382 100644 (file)
@@ -14,8 +14,11 @@ const QString USER_AGENT = QString(Constants::NAME)
 
 const QString USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11";
 
-NetworkReply::NetworkReply(QNetworkReply *networkReply) : QObject(networkReply) {
-    this->networkReply = networkReply;
+NetworkReply::NetworkReply(QNetworkReply *networkReply) :
+    QObject(networkReply),
+    networkReply(networkReply),
+    retryCount(0) {
+
     setupReply();
 
     readTimeoutTimer = new QTimer(this);
@@ -48,7 +51,7 @@ void NetworkReply::finished() {
             setupReply();
             readTimeoutTimer->start();
             return;
-        } else qWarning("Redirection not supported");
+        } else qWarning() << "Redirection not supported" << networkReply->url().toEncoded();
     }
 
     if (receivers(SIGNAL(data(QByteArray))) > 0)
@@ -92,10 +95,16 @@ void NetworkReply::readTimeout() {
         return;
     }
 
+    if (retryCount > 3) {
+        emit error(networkReply);
+        return;
+    }
     QNetworkReply *retryReply = The::http()->request(networkReply->url(), networkReply->operation());
     setParent(retryReply);
     networkReply = retryReply;
     setupReply();
+    retryCount++;
+    readTimeoutTimer->start();
 }
 
 /* --- NetworkAccess --- */
index c9a5c18c7571814ba5ce48b9e11b5483e56a8c84..a595ac725a411fe828a5e38eb220c5eb1c7f43cd 100644 (file)
@@ -14,22 +14,24 @@ class NetworkReply : public QObject {
 
 public:
     NetworkReply(QNetworkReply* networkReply);
-
-public slots:
-    void finished();
-    void requestError(QNetworkReply::NetworkError);
-    void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
-    void readTimeout();
+    QNetworkReply* getNetworkReply() { return networkReply; }
 
 signals:
     void data(QByteArray);
     void error(QNetworkReply*);
     void finished(QNetworkReply*);
 
+private slots:
+    void finished();
+    void requestError(QNetworkReply::NetworkError);
+    void downloadProgress(qint64 bytesReceived, qint64 bytesTotal);
+    void readTimeout();
+
 private:
     void setupReply();
     QNetworkReply *networkReply;
     QTimer *readTimeoutTimer;
+    int retryCount;
 
 };