QNAM: Fix previous HTTP upload CPU fix
My previous fix for CPU load issues between HTTP thread and user thread was fragile if the upload QIODevice emitted readyRead() multiple times. [ChangeLog][QtNetwork][QNetworkAccessManager] Fix behavior of upload QIODevice that generate data on readyRead() for HTTP PUT/POST Change-Id: Idb1c2d5a382a704d8cc08fe03c55c883bfc95aa7 Reviewed-by: Christian Kamm <kamm@incasoftware.de> Reviewed-by: Richard J. Moore <rich@kde.org>
This commit is contained in:
parent
5c2d7b1635
commit
097b641c3e
@ -428,6 +428,7 @@ QNetworkReplyHttpImplPrivate::QNetworkReplyHttpImplPrivate()
|
||||
, synchronous(false)
|
||||
, state(Idle)
|
||||
, statusCode(0)
|
||||
, uploadDeviceChoking(false)
|
||||
, outgoingData(0)
|
||||
, bytesUploaded(-1)
|
||||
, cacheLoadDevice(0)
|
||||
@ -1291,9 +1292,12 @@ void QNetworkReplyHttpImplPrivate::wantUploadDataSlot(qint64 maxSize)
|
||||
char *data = const_cast<char*>(uploadByteDevice->readPointer(maxSize, currentUploadDataLength));
|
||||
|
||||
if (currentUploadDataLength == 0) {
|
||||
uploadDeviceChoking = true;
|
||||
// No bytes from upload byte device. There will be bytes later, it will emit readyRead()
|
||||
// and our uploadByteDeviceReadyReadSlot() is called.
|
||||
return;
|
||||
} else {
|
||||
uploadDeviceChoking = false;
|
||||
}
|
||||
|
||||
// Let's make a copy of this data
|
||||
@ -1306,7 +1310,12 @@ void QNetworkReplyHttpImplPrivate::wantUploadDataSlot(qint64 maxSize)
|
||||
void QNetworkReplyHttpImplPrivate::uploadByteDeviceReadyReadSlot()
|
||||
{
|
||||
// Start the flow between this thread and the HTTP thread again by triggering a upload.
|
||||
wantUploadDataSlot(1024);
|
||||
// However only do this when we were choking before, else the state in
|
||||
// QNonContiguousByteDeviceThreadForwardImpl gets messed up.
|
||||
if (uploadDeviceChoking) {
|
||||
uploadDeviceChoking = false;
|
||||
wantUploadDataSlot(1024);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -212,6 +212,7 @@ public:
|
||||
// upload
|
||||
QNonContiguousByteDevice* createUploadByteDevice();
|
||||
QSharedPointer<QNonContiguousByteDevice> uploadByteDevice;
|
||||
bool uploadDeviceChoking; // if we couldn't readPointer() any data at the moment
|
||||
QIODevice *outgoingData;
|
||||
QSharedPointer<QRingBuffer> outgoingDataBuffer;
|
||||
void emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal); // dup?
|
||||
|
@ -7883,6 +7883,8 @@ protected slots:
|
||||
//qDebug() << Q_FUNC_INFO;
|
||||
bandwidthQuota = 8*1024; // fill quota
|
||||
emit readyRead();
|
||||
// Emitting readyRead() several times triggers a bug ("QIODevice::read: Called with maxSize < 0") we fix with this commit
|
||||
emit readyRead();
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user