diff options
author | Kai Koehne <kai.koehne@theqtcompany.com> | 2015-07-10 16:10:44 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@theqtcompany.com> | 2015-09-14 09:38:24 +0000 |
commit | a8bc96e9e5d18908d266e3dc614c00f25a0c2013 (patch) | |
tree | 867538774043a6e76640a9aa68775f9dee997b37 /src/network/ssl/qsslsocket_winrt.cpp | |
parent | b1738d63298ef1850995d13e9f7c8bcc6156edc1 (diff) |
QAbstractSocket: Consolidate error reporting
Introduce the methods setError(), setErrorAndEmit() to consistently
set the internal error state.
Change-Id: I4ff951d100cf5e9f9a7e27135bb52188cde99853
Reviewed-by: Alex Trotsenko <alex1973tr@gmail.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/network/ssl/qsslsocket_winrt.cpp')
-rw-r--r-- | src/network/ssl/qsslsocket_winrt.cpp | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/src/network/ssl/qsslsocket_winrt.cpp b/src/network/ssl/qsslsocket_winrt.cpp index aba3ea8170..b03f234d49 100644 --- a/src/network/ssl/qsslsocket_winrt.cpp +++ b/src/network/ssl/qsslsocket_winrt.cpp @@ -251,9 +251,8 @@ void QSslSocketBackendPrivate::startClientEncryption() case QSsl::TlsV1_2OrLater: // TlsV1_0OrLater, TlsV1_1OrLater and TlsV1_2OrLater are disabled on WinRT // because there is no good way to map them to the native API. - q->setErrorString(QStringLiteral("unsupported protocol")); - q->setSocketError(QAbstractSocket::SslInvalidUserDataError); - emit q->error(QAbstractSocket::SslInvalidUserDataError); + setErrorAndEmit(QAbstractSocket::SslInvalidUserDataError, + QStringLiteral("unsupported protocol")); return; default: protectionLevel = SocketProtectionLevel_Tls12; // default to highest @@ -347,13 +346,10 @@ QSsl::SslProtocol QSslSocketBackendPrivate::sessionProtocol() const void QSslSocketBackendPrivate::continueHandshake() { - Q_Q(QSslSocket); - IStreamSocket *socket = reinterpret_cast<IStreamSocket *>(plainSocket->socketDescriptor()); if (qintptr(socket) == -1) { - q->setErrorString(QStringLiteral("At attempt was made to continue the handshake on an invalid socket.")); - q->setSocketError(QAbstractSocket::SslInternalError); - emit q->error(QAbstractSocket::SslInternalError); + setErrorAndEmit(QAbstractSocket::SslInternalError, + QStringLiteral("At attempt was made to continue the handshake on an invalid socket.")); return; } @@ -372,9 +368,7 @@ void QSslSocketBackendPrivate::continueHandshake() Q_ASSERT_SUCCEEDED(hr); } if (FAILED(hr)) { - q->setErrorString(qt_error_string(hr)); - q->setSocketError(QAbstractSocket::SslInvalidUserDataError); - emit q->error(QAbstractSocket::SslInvalidUserDataError); + setErrorAndEmit(QAbstractSocket::SslInvalidUserDataError, qt_error_string(hr)); return; } @@ -440,10 +434,8 @@ void QSslSocketBackendPrivate::continueHandshake() ComPtr<IAsyncAction> op; hr = socket->UpgradeToSslAsync(protectionLevel, hostName.Get(), &op); if (FAILED(hr)) { - q->setErrorString(QSslSocket::tr("Error creating SSL session: %1") - .arg(qt_error_string(hr))); - q->setSocketError(QAbstractSocket::SslInternalError); - emit q->error(QAbstractSocket::SslInternalError); + setErrorAndEmit(QAbstractSocket::SslInternalError, + QSslSocket::tr("Error creating SSL session: %1").arg(qt_error_string(hr))); return; } @@ -467,9 +459,7 @@ HRESULT QSslSocketBackendPrivate::onSslUpgrade(IAsyncAction *action, AsyncStatus QSet<QSslError> errors; switch (hr) { case SEC_E_INVALID_TOKEN: // Occurs when the server doesn't support the requested protocol - q->setErrorString(qt_error_string(hr)); - q->setSocketError(QAbstractSocket::SslHandshakeFailedError); - emit q->error(QAbstractSocket::SslHandshakeFailedError); + setErrorAndEmit(QAbstractSocket::SslHandshakeFailedError, qt_error_string(hr)); q->disconnectFromHost(); return S_OK; default: @@ -628,9 +618,7 @@ HRESULT QSslSocketBackendPrivate::onSslUpgrade(IAsyncAction *action, AsyncStatus if (!sslErrors.isEmpty()) { emit q->sslErrors(sslErrors); - q->setErrorString(sslErrors.first().errorString()); - q->setSocketError(QAbstractSocket::SslHandshakeFailedError); - emit q->error(QAbstractSocket::SslHandshakeFailedError); + setErrorAndEmit(QAbstractSocket::SslHandshakeFailedError, sslErrors.first().errorString()); // Disconnect if there are any non-ignorable errors foreach (const QSslError &error, sslErrors) { |