diff options
author | Martin Petersson <Martin.Petersson@nokia.com> | 2012-05-09 13:53:46 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-16 04:24:32 +0200 |
commit | 7ba7dddffd3a4807af67db7ec089afc5b9a1831a (patch) | |
tree | 8a9f393aa44a97a337bb90ac7c8118ed14eecefc /src/network | |
parent | cfb44c6528b2518274bf157388832d1d610ce0e4 (diff) |
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 <shane.kearns@accenture.com>
Reviewed-by: Prasanth Ullattil <prasanth.ullattil@nokia.com>
Reviewed-by: Richard J. Moore <rich@kde.org>
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/access/qhttpnetworkconnectionchannel.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 6e33836feb..006f533a69 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<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; |