diff --git a/src/grpc/qgrpchttp2channel.cpp b/src/grpc/qgrpchttp2channel.cpp index b5a7dcf9..ebf34f55 100644 --- a/src/grpc/qgrpchttp2channel.cpp +++ b/src/grpc/qgrpchttp2channel.cpp @@ -371,7 +371,18 @@ private: bool createHttp2Stream(Http2Handler *handler); void createHttp2Connection(); - void handleSocketError(); + +#if QT_CONFIG(localserver) + void handleLocalSocketError(QLocalSocket::LocalSocketError error) + { + handleSocketError(QDebug::toBytes(error)); + } +#endif + void handleAbstractSocketError(QAbstractSocket::SocketError error) + { + handleSocketError(QDebug::toBytes(error)); + } + void handleSocketError(const QByteArray &errorCode); template T *initSocket() @@ -532,7 +543,6 @@ void Http2Handler::attachStream(QHttp2Stream *stream_) QObject::connect(m_stream.get(), &QHttp2Stream::uploadFinished, this, &Http2Handler::processQueue); - } // Builds HTTP/2 headers for the initial gRPC request. @@ -899,13 +909,8 @@ QGrpcHttp2ChannelPrivate::QGrpcHttp2ChannelPrivate(const QUrl &uri, QGrpcHttp2Ch QObject::connect(localSocket, &QLocalSocket::connected, this, &QGrpcHttp2ChannelPrivate::createHttp2Connection); QObject::connect(localSocket, &QLocalSocket::errorOccurred, this, - [this](QLocalSocket::LocalSocketError error) { - qGrpcDebug() - << "Error occurred(" << error << "):" - << static_cast(m_socket.get())->errorString() - << hostUri; - handleSocketError(); - }); + &QGrpcHttp2ChannelPrivate::handleLocalSocketError); + m_reconnectFunction = [localSocket, this] { localSocket->connectToServer(hostUri.host() + hostUri.path()); }; @@ -936,13 +941,8 @@ QGrpcHttp2ChannelPrivate::QGrpcHttp2ChannelPrivate(const QUrl &uri, QGrpcHttp2Ch QObject::connect(sslSocket, &QSslSocket::encrypted, this, &QGrpcHttp2ChannelPrivate::createHttp2Connection); QObject::connect(sslSocket, &QAbstractSocket::errorOccurred, this, - [this](QAbstractSocket::SocketError error) { - qDebug() - << "Error occurred(" << error << "):" - << static_cast(m_socket.get())->errorString() - << hostUri; - handleSocketError(); - }); + &QGrpcHttp2ChannelPrivate::handleAbstractSocketError); + m_reconnectFunction = [sslSocket, this] { sslSocket->connectToHostEncrypted(hostUri.host(), static_cast(hostUri.port())); }; @@ -960,13 +960,8 @@ QGrpcHttp2ChannelPrivate::QGrpcHttp2ChannelPrivate(const QUrl &uri, QGrpcHttp2Ch QObject::connect(httpSocket, &QAbstractSocket::connected, this, &QGrpcHttp2ChannelPrivate::createHttp2Connection); QObject::connect(httpSocket, &QAbstractSocket::errorOccurred, this, - [this](QAbstractSocket::SocketError error) { - qGrpcDebug() - << "Error occurred(" << error << "):" - << static_cast(m_socket.get())->errorString() - << hostUri; - handleSocketError(); - }); + &QGrpcHttp2ChannelPrivate::handleAbstractSocketError); + m_reconnectFunction = [httpSocket, this] { httpSocket->connectToHost(hostUri.host(), static_cast(hostUri.port())); }; @@ -1065,8 +1060,9 @@ void QGrpcHttp2ChannelPrivate::createHttp2Connection() for_each_non_expired_handler([this](Http2Handler *handler) { createHttp2Stream(handler); }); } -void QGrpcHttp2ChannelPrivate::handleSocketError() +void QGrpcHttp2ChannelPrivate::handleSocketError(const QByteArray &errorCode) { + qGrpcDebug() << "Error occurred(" << errorCode << "):" << m_socket->errorString() << hostUri; delete m_connection; m_connection = nullptr; m_state = ConnectionState::Error;