summaryrefslogtreecommitdiffstats
path: root/src/network/access/qnetworkreplyimpl.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/access/qnetworkreplyimpl.cpp')
-rw-r--r--src/network/access/qnetworkreplyimpl.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp
index 265ebe9..d1dbdc9 100644
--- a/src/network/access/qnetworkreplyimpl.cpp
+++ b/src/network/access/qnetworkreplyimpl.cpp
@@ -56,6 +56,7 @@ inline QNetworkReplyImplPrivate::QNetworkReplyImplPrivate()
: backend(0), outgoingData(0), outgoingDataBuffer(0),
copyDevice(0), networkCache(0),
cacheEnabled(false), cacheSaveDevice(0),
+ notificationHandlingPaused(false),
bytesDownloaded(0), lastBytesDownloaded(-1), bytesUploaded(-1),
state(Idle)
{
@@ -126,9 +127,11 @@ void QNetworkReplyImplPrivate::_q_copyReadyRead()
lastBytesDownloaded = bytesDownloaded;
QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader);
+ pauseNotificationHandling();
emit q->downloadProgress(bytesDownloaded,
totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong());
emit q->readyRead();
+ resumeNotificationHandling();
}
void QNetworkReplyImplPrivate::_q_copyReadChannelFinished()
@@ -262,6 +265,9 @@ void QNetworkReplyImplPrivate::backendNotify(InternalNotifications notification)
void QNetworkReplyImplPrivate::handleNotifications()
{
+ if (notificationHandlingPaused)
+ return;
+
NotificationQueue current = pendingNotifications;
pendingNotifications.clear();
@@ -292,6 +298,22 @@ void QNetworkReplyImplPrivate::handleNotifications()
}
}
+// Do not handle the notifications while we are emitting downloadProgress
+// or readyRead
+void QNetworkReplyImplPrivate::pauseNotificationHandling()
+{
+ notificationHandlingPaused = true;
+}
+
+// Resume notification handling
+void QNetworkReplyImplPrivate::resumeNotificationHandling()
+{
+ Q_Q(QNetworkReplyImpl);
+ notificationHandlingPaused = false;
+ if (pendingNotifications.size() >= 1)
+ QCoreApplication::postEvent(q, new QEvent(QEvent::NetworkReplyUpdated));
+}
+
void QNetworkReplyImplPrivate::createCache()
{
// check if we can save and if we're allowed to
@@ -347,7 +369,9 @@ void QNetworkReplyImplPrivate::emitUploadProgress(qint64 bytesSent, qint64 bytes
{
Q_Q(QNetworkReplyImpl);
bytesUploaded = bytesSent;
+ pauseNotificationHandling();
emit q->uploadProgress(bytesSent, bytesTotal);
+ resumeNotificationHandling();
}
@@ -398,12 +422,14 @@ void QNetworkReplyImplPrivate::appendDownstreamData(const QByteArray &data)
QPointer<QNetworkReplyImpl> qq = q;
QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader);
+ pauseNotificationHandling();
emit q->downloadProgress(bytesDownloaded,
totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong());
emit q->readyRead();
// hopefully we haven't been deleted here
if (!qq.isNull()) {
+ resumeNotificationHandling();
// do we still have room in the buffer?
if (nextDownstreamBlockSize() > 0)
backendNotify(QNetworkReplyImplPrivate::NotifyDownstreamReadyWrite);
@@ -441,6 +467,7 @@ void QNetworkReplyImplPrivate::finished()
state = Finished;
pendingNotifications.clear();
+ pauseNotificationHandling();
QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader);
if (totalSize.isNull() || totalSize == -1) {
emit q->downloadProgress(bytesDownloaded, bytesDownloaded);
@@ -448,14 +475,17 @@ void QNetworkReplyImplPrivate::finished()
if (bytesUploaded == -1 && (outgoingData || outgoingDataBuffer))
emit q->uploadProgress(0, 0);
+ resumeNotificationHandling();
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 QNetworkReplyImplPrivate::error(QNetworkReplyImpl::NetworkError code, const QString &errorMessage)