QNAM HTTP: Implement abort() and close()
authorMarkus Goetz <Markus.Goetz@nokia.com>
Wed, 13 Apr 2011 12:33:11 +0000 (14:33 +0200)
committerMarkus Goetz <Markus.Goetz@nokia.com>
Tue, 3 May 2011 14:47:07 +0000 (16:47 +0200)
src/network/access/qnetworkreplyhttpimpl.cpp

index 7e6f2d4..359fb56 100644 (file)
@@ -250,15 +250,40 @@ QNetworkReplyHttpImpl::~QNetworkReplyHttpImpl()
 void QNetworkReplyHttpImpl::close()
 {
     Q_D(QNetworkReplyHttpImpl);
+
+    if (d->state == QNetworkReplyHttpImplPrivate::Aborted ||
+        d->state == QNetworkReplyHttpImplPrivate::Finished)
+        return;
+
+    // According to the documentation close only stops the download
+    // by closing we can ignore the download part and continue uploading.
     QNetworkReply::close();
-    // FIXME
+
+    // call finished which will emit signals
+    // FIXME shouldn't this be emitted Queued?
+    d->error(OperationCanceledError, tr("Operation canceled"));
+    d->finished();
 }
 
 void QNetworkReplyHttpImpl::abort()
 {
     Q_D(QNetworkReplyHttpImpl);
-    QNetworkReply::close();
     // FIXME
+    if (d->state == QNetworkReplyHttpImplPrivate::Finished || d->state == QNetworkReplyHttpImplPrivate::Aborted)
+        return;
+
+    QNetworkReply::close();
+
+    if (d->state != QNetworkReplyHttpImplPrivate::Finished) {
+        // call finished which will emit signals
+        // FIXME shouldn't this be emitted Queued?
+        d->error(OperationCanceledError, tr("Operation canceled"));
+        d->finished();
+    }
+
+    d->state = QNetworkReplyHttpImplPrivate::Aborted;
+
+    emit abortHttpRequest();
 }
 
 qint64 QNetworkReplyHttpImpl::bytesAvailable() const
@@ -935,6 +960,10 @@ void QNetworkReplyHttpImplPrivate::replyDownloadData(QByteArray d)
 
     qDebug() << "QNetworkReplyHttpImplPrivate::replyDownloadData" << d.size();
 
+    // If we're closed just ignore this data
+    if (!q->isOpen())
+        return;
+
     int pendingSignals = (int)pendingDownloadDataEmissions->fetchAndAddAcquire(-1) - 1;
 
     if (pendingSignals > 0) {
@@ -959,10 +988,6 @@ void QNetworkReplyHttpImplPrivate::replyDownloadData(QByteArray d)
     //writeDownstreamData(pendingDownloadDataCopy);
     // instead we do:
 
-    // We could be closed
-    if (!q->isOpen())
-        return;
-
     if (cacheEnabled && !cacheSaveDevice) {
         initCacheSaveDevice();
     }
@@ -1126,6 +1151,10 @@ void QNetworkReplyHttpImplPrivate::replyDownloadProgressSlot(qint64 bytesReceive
 {
     Q_Q(QNetworkReplyHttpImpl);
 
+    // If we're closed just ignore this data
+    if (!q->isOpen())
+        return;
+
     // we can be sure here that there is a download buffer
 
     int pendingSignals = (int)pendingDownloadProgressEmissions->fetchAndAddAcquire(-1) - 1;