From 7ba7dddffd3a4807af67db7ec089afc5b9a1831a Mon Sep 17 00:00:00 2001 From: Martin Petersson Date: Wed, 9 May 2012 13:53:46 +0200 Subject: [PATCH] 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. Change-Id: Iaa87d79ea16d69735f6ba3e8b3b4a0f86fbd5f73 Reviewed-by: Shane Kearns Reviewed-by: Prasanth Ullattil Reviewed-by: Richard J. Moore --- .../access/qhttpnetworkconnectionchannel.cpp | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 6e33836..006f533 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -1111,6 +1111,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(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; -- 2.7.4