From bd86c4d089e442dbbef55052c9511b77186221de Mon Sep 17 00:00:00 2001 From: Martin Petersson Date: Tue, 15 May 2012 12:35:34 +0200 Subject: QNetworkReplyHttpImplPrivate::migrateBackend If the QNetworkSession change while we are handling a QNetworkRequest we should try to resume this request if possible. In that case we set the offset for where to continue the request. Abort the operation in the http thread. And then post the request again. The offset will then be set using the range header in postRequest() so that the operation is resumed. Task-number: QTBUG-25762 Change-Id: Ib7946905bcc633f8cc3dd7a7ad1ae74579e6bf56 Reviewed-by: Shane Kearns --- src/network/access/qnetworkreplyhttpimpl.cpp | 31 ++-------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 25b73e969f..574a2ed6af 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -1634,7 +1634,6 @@ void QNetworkReplyHttpImplPrivate::_q_cacheLoadReadyRead() lastBytesDownloaded = bytesDownloaded; QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); - //pauseNotificationHandling(); // emit readyRead before downloadProgress incase this will cause events to be // processed and we get into a recursive call (as in QProgressDialog). @@ -1848,12 +1847,10 @@ void QNetworkReplyHttpImplPrivate::finished() if (state == Finished || state == Aborted || state == WaitingForSession) return; - //pauseNotificationHandling(); QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); if (preMigrationDownloaded != Q_INT64_C(-1)) totalSize = totalSize.toLongLong() + preMigrationDownloaded; - // FIXME why should it be 0 if (manager) { #ifndef QT_NO_BEARERMANAGEMENT QNetworkSession *session = managerPrivate->networkSession.data(); @@ -1865,7 +1862,6 @@ void QNetworkReplyHttpImplPrivate::finished() if (migrateBackend()) { // either we are migrating or the request is finished/aborted if (state == Reconnecting || state == WaitingForSession) { - //resumeNotificationHandling(); return; // exit early if we are migrating. } } else { @@ -1877,33 +1873,23 @@ void QNetworkReplyHttpImplPrivate::finished() } #endif } - //resumeNotificationHandling(); state = Finished; q->setFinished(true); - //pendingNotifications.clear(); - - //pauseNotificationHandling(); if (totalSize.isNull() || totalSize == -1) { emit q->downloadProgress(bytesDownloaded, bytesDownloaded); } if (bytesUploaded == -1 && (outgoingData || outgoingDataBuffer)) emit q->uploadProgress(0, 0); - //resumeNotificationHandling(); // if we don't know the total size of or we received everything save the cache if (totalSize.isNull() || totalSize == -1 || bytesDownloaded == totalSize) completeCacheSave(); - // note: might not be a good idea, since users could decide to delete us - // which would delete the backend too... - // maybe we should protect the backend - //pauseNotificationHandling(); emit q->readChannelFinished(); emit q->finished(); - //resumeNotificationHandling(); } void QNetworkReplyHttpImplPrivate::_q_error(QNetworkReplyImpl::NetworkError code, const QString &errorMessage) @@ -1976,27 +1962,14 @@ bool QNetworkReplyHttpImplPrivate::migrateBackend() state = Reconnecting; -// if (backend) { -// delete backend; -// backend = 0; -// } - cookedHeaders.clear(); rawHeaders.clear(); preMigrationDownloaded = bytesDownloaded; -// backend = manager->d_func()->findBackend(operation, request); - -// if (backend) { -// backend->setParent(q); -// backend->reply = this; -// backend->setResumeOffset(bytesDownloaded); -// } + setResumeOffset(bytesDownloaded); - // FIXME - Q_ASSERT(0); - // What probably needs to be done is an abort and then re-send? + emit q->abortHttpRequest(); QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); -- cgit v1.2.3