diff options
author | Ville Pernu <ville.pernu@nokia.com> | 2010-11-24 10:59:36 (GMT) |
---|---|---|
committer | Ville Pernu <ville.pernu@nokia.com> | 2010-11-24 10:59:36 (GMT) |
commit | cbf7a7782f465846455a5fd5df339ebde31a5521 (patch) | |
tree | a7f77e45bc7832b53c838c136b1eb5f73d0134cf | |
parent | 4e9b721af573e7d1a16b35778059b374520cf055 (diff) | |
download | Qt-cbf7a7782f465846455a5fd5df339ebde31a5521.zip Qt-cbf7a7782f465846455a5fd5df339ebde31a5521.tar.gz Qt-cbf7a7782f465846455a5fd5df339ebde31a5521.tar.bz2 |
Fix a missing error-signal when a server is shut down while downloading
QT-3494: During download, if a QAbstractSocket::RemoteHostClosedError occurs, the
error handling is deferred to _q_disconnected() slot. However, the error
message is not saved for the function, and thus the _q_disconnected only
emits a finished-signal.
Solution: Store an unhandled error into a private member. It is handled and
reset by the _q_disconnected (or more specifically, allDone-function).
-rw-r--r-- | src/network/access/qhttpnetworkconnectionchannel.cpp | 18 | ||||
-rw-r--r-- | src/network/access/qhttpnetworkconnectionchannel_p.h | 1 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 02daa50..39f4811 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -66,6 +66,7 @@ QHttpNetworkConnectionChannel::QHttpNetworkConnectionChannel() , bytesTotal(0) , resendCurrent(false) , lastStatus(0) + , unhandledError(QNetworkReply::NoError) , pendingEncrypt(false) , reconnectAttempts(2) , authMethod(QAuthenticatorPrivate::None) @@ -643,7 +644,21 @@ void QHttpNetworkConnectionChannel::allDone() // slot connected to it. The socket will not fire readyRead signal, if we are already // in the slot connected to readyRead if (emitFinished) - QMetaObject::invokeMethod(reply, "finished", Qt::QueuedConnection); + { + // Check whether _q_error was invoked previously and if it left a socket + // error unhandled. + if(unhandledError != QNetworkReply::NoError) { + QString errorString = connection->d_func()->errorDetail(unhandledError, socket, socket->errorString()); + qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError"); + QMetaObject::invokeMethod(reply, "finishedWithError", + Qt::QueuedConnection, + Q_ARG(QNetworkReply::NetworkError, unhandledError), + Q_ARG(QString, errorString)); + unhandledError = QNetworkReply::NoError; // Reset the value + } else { + QMetaObject::invokeMethod(reply, "finished", Qt::QueuedConnection); + } + } // reset the reconnection attempts after we receive a complete reply. // in case of failures, each channel will attempt two reconnects before emitting error. reconnectAttempts = 2; @@ -965,6 +980,7 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket errorCode = QNetworkReply::RemoteHostClosedError; } } else { + unhandledError = QNetworkReply::RemoteHostClosedError; return; } break; diff --git a/src/network/access/qhttpnetworkconnectionchannel_p.h b/src/network/access/qhttpnetworkconnectionchannel_p.h index 442086a..33cef5a 100644 --- a/src/network/access/qhttpnetworkconnectionchannel_p.h +++ b/src/network/access/qhttpnetworkconnectionchannel_p.h @@ -105,6 +105,7 @@ public: qint64 bytesTotal; bool resendCurrent; int lastStatus; // last status received on this channel + QNetworkReply::NetworkError unhandledError; // Stored code of an unhandled error. bool pendingEncrypt; // for https (send after encrypted) int reconnectAttempts; // maximum 2 reconnection attempts QAuthenticatorPrivate::Method authMethod; |