summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorMartin Petersson <Martin.Petersson@nokia.com>2012-05-16 11:24:02 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-05-21 10:59:03 (GMT)
commit185ccc152cbb4a8df9c8fe016a26156c3f6995d7 (patch)
treee29e47d9e7fe455a5aaca88669fdd0f7953496f8 /src/network
parent2a296280f609c60639061ce37369c48d0d65fbe0 (diff)
downloadQt-185ccc152cbb4a8df9c8fe016a26156c3f6995d7.zip
Qt-185ccc152cbb4a8df9c8fe016a26156c3f6995d7.tar.gz
Qt-185ccc152cbb4a8df9c8fe016a26156c3f6995d7.tar.bz2
QNetworkAccessManager: Read all from socket on remote host close
When we get a remoteHostClosed we should try to read everything from the socket before we close the channel. cherry-picked from commit 27bc9945a84c6f6d8e0d2a33183c3a6e9b2978d8 Change-Id: Ia1b64dbd991265ce0ce4c4d21f4df323133e2b07 Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
Diffstat (limited to 'src/network')
-rw-r--r--src/network/access/qhttpnetworkconnectionchannel.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp
index 3540942..52dfc65 100644
--- a/src/network/access/qhttpnetworkconnectionchannel.cpp
+++ b/src/network/access/qhttpnetworkconnectionchannel.cpp
@@ -1073,6 +1073,32 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket
return;
}
// ok, we got a disconnect even though we did not expect it
+ // Try to read everything from the socket before we emit the error.
+ if (socket->bytesAvailable()) {
+ // Read everything from the socket into the reply buffer.
+ // we can ignore the readbuffersize as the data is already
+ // in memory and we will not recieve more data on the socket.
+ reply->setReadBufferSize(0);
+ _q_receiveReply();
+#ifndef QT_NO_SSL
+ if (ssl) {
+ // QT_NO_OPENSSL. The QSslSocket can still have encrypted bytes in the plainsocket.
+ // So we need to check this if the socket is a QSslSocket. When the socket is flushed
+ // it will force a decrypt of the encrypted data in the plainsocket.
+ QSslSocket *sslSocket = static_cast<QSslSocket*>(socket);
+ qint64 beforeFlush = sslSocket->encryptedBytesAvailable();
+ while (sslSocket->encryptedBytesAvailable()) {
+ sslSocket->flush();
+ _q_receiveReply();
+ qint64 afterFlush = sslSocket->encryptedBytesAvailable();
+ if (afterFlush == beforeFlush)
+ break;
+ beforeFlush = afterFlush;
+ }
+ }
+#endif
+ }
+
errorCode = QNetworkReply::RemoteHostClosedError;
} else {
errorCode = QNetworkReply::RemoteHostClosedError;