diff options
author | Alexey Edelev <[email protected]> | 2025-08-13 13:27:04 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <[email protected]> | 2025-08-15 16:49:10 +0000 |
commit | 8f5f1331b18e534808f58edaded276d7b068032a (patch) | |
tree | c8b2e70ca8eb121c1d815542a914f8c406b1d80b | |
parent | 69565bb20878887d8fae66126cb73bf81624b3ff (diff) |
Move the socket error handling to the common place6.9
Instead of connecting each and every Http2Handler to the socket error,
use QGrpcHttp2ChannelPrivate::handleSocketError to iterate over
alive Http2Handler and send errors right from this handler. This saves
some memory and time on handling errorOccurred signal.
Pick-to: 6.8
Change-Id: I907e24425aafe3dccca19100d02fe7adffb1fdaa
Reviewed-by: Dennis Oberst <[email protected]>
(cherry picked from commit 7da4e6886a80d9c389fc889b4ebffed3b0f0bac8)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
(cherry picked from commit 71542c2b0f9262a54eb08ffec96d11d42a75d244)
-rw-r--r-- | src/grpc/qgrpchttp2channel.cpp | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/src/grpc/qgrpchttp2channel.cpp b/src/grpc/qgrpchttp2channel.cpp index abd3088b..5dd43ce9 100644 --- a/src/grpc/qgrpchttp2channel.cpp +++ b/src/grpc/qgrpchttp2channel.cpp @@ -351,24 +351,6 @@ public: private: enum ConnectionState { Connecting = 0, Connected, SettingsReceived, Error }; - template <typename T> - void connectErrorHandler(T *socket, Http2Handler *handler) - { - connect(socket, &T::errorOccurred, handler, [this, handler](auto error) { - if (m_isInsideSocketErrorOccurred) { - qCCritical(lcChannel, - "[%p] Socket errorOccurred signal triggered while " - "already handling an error", - this); - return; - } - m_isInsideSocketErrorOccurred = true; - auto reset = qScopeGuard([this]() { m_isInsideSocketErrorOccurred = false; }); - emit handler->finish({ StatusCode::Unavailable, - tr("Network error occurred: %1").arg(error) }); - }); - } - void ensureSchemeIsValid(QLatin1String expected); bool createHttp2Stream(Http2Handler *handler); @@ -1018,17 +1000,6 @@ void QGrpcHttp2ChannelPrivate::processOperation(QGrpcOperationContext *operation } auto *handler = new Http2Handler(this, operationContext, endStream); - -#if QT_CONFIG(localserver) - if (m_isLocalSocket) { - connectErrorHandler<QLocalSocket>(static_cast<QLocalSocket *>(m_socket.get()), handler); - } else -#endif - { - connectErrorHandler<QAbstractSocket>(static_cast<QAbstractSocket *>(m_socket.get()), - handler); - } - if (m_connection && !createHttp2Stream(handler)) return; @@ -1093,6 +1064,20 @@ void QGrpcHttp2ChannelPrivate::createHttp2Connection() void QGrpcHttp2ChannelPrivate::handleSocketError(const QByteArray &errorCode) { + for_each_non_expired_handler([this, &errorCode](Http2Handler *handler) { + if (m_isInsideSocketErrorOccurred) { + qCCritical(lcChannel, + "[%p] Socket errorOccurred signal triggered while " + "already handling an error", + this); + return; + } + m_isInsideSocketErrorOccurred = true; + auto reset = qScopeGuard([this]() { m_isInsideSocketErrorOccurred = false; }); + emit handler->finish({ StatusCode::Unavailable, + tr("Network error occurred: %1").arg(errorCode) }); + }); + qCDebug(lcChannel, "[%p] Socket error occurred (code=%s, details=%s, hostUri=%s)", this, errorCode.constData(), qPrintable(m_socket->errorString()), qPrintable(hostUri.toString())); |