mirror of https://github.com/qt/qtgrpc.git
Remove unnecessary QObject:: namespace to improve readability
Removed redundant 'QObject::' namespace to streamline code and enhance readability, especially in lambda handlers. Due to our formatting, all lambda handlers will be unnecessarily aligned to the very right side. Given that connections and lambda handlers are very common in this codebase this improves the readability of those lambda handlers. Pick-to: 6.10 6.9 6.8 Change-Id: I178a838c7702382b4b3845c729d7c11eeeb1c8d1 Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>
This commit is contained in:
parent
7e06d79d6d
commit
eb703a45a1
|
|
@ -368,22 +368,19 @@ private:
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void connectErrorHandler(T *socket, Http2Handler *handler)
|
void connectErrorHandler(T *socket, Http2Handler *handler)
|
||||||
{
|
{
|
||||||
QObject::connect(socket, &T::errorOccurred, handler,
|
connect(socket, &T::errorOccurred, handler, [this, handler](auto error) {
|
||||||
[this, handler](auto error) {
|
if (m_isInsideSocketErrorOccurred) {
|
||||||
if (m_isInsideSocketErrorOccurred) {
|
qCCritical(lcChannel,
|
||||||
qCCritical(lcChannel,
|
"[%p] Socket errorOccurred signal triggered while "
|
||||||
"[%p] Socket errorOccurred signal triggered while "
|
"already handling an error",
|
||||||
"already handling an error",
|
this);
|
||||||
this);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
m_isInsideSocketErrorOccurred = true;
|
||||||
m_isInsideSocketErrorOccurred = true;
|
auto reset = qScopeGuard([this]() { m_isInsideSocketErrorOccurred = false; });
|
||||||
auto reset = qScopeGuard([this]() {
|
emit handler->finish({ StatusCode::Unavailable,
|
||||||
m_isInsideSocketErrorOccurred = false;
|
tr("Network error occurred: %1").arg(error) });
|
||||||
});
|
});
|
||||||
emit handler->finish({ StatusCode::Unavailable,
|
|
||||||
tr("Network error occurred: %1").arg(error) });
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ensureSchemeIsValid(QLatin1String expected);
|
void ensureSchemeIsValid(QLatin1String expected);
|
||||||
|
|
@ -459,18 +456,15 @@ Http2Handler::Http2Handler(QGrpcHttp2ChannelPrivate *parent, QGrpcOperationConte
|
||||||
// If the context (lifetime bound to the user) is destroyed, this handler
|
// If the context (lifetime bound to the user) is destroyed, this handler
|
||||||
// can no longer perform any meaningful work. We allow it to be deleted;
|
// can no longer perform any meaningful work. We allow it to be deleted;
|
||||||
// QHttp2Stream will handle any outstanding cancellations appropriately.
|
// QHttp2Stream will handle any outstanding cancellations appropriately.
|
||||||
QObject::connect(context, &QGrpcOperationContext::destroyed, this,
|
connect(context, &QGrpcOperationContext::destroyed, this, &Http2Handler::deleteLater);
|
||||||
&Http2Handler::deleteLater);
|
connect(context, &QGrpcOperationContext::cancelRequested, this, &Http2Handler::cancel);
|
||||||
QObject::connect(context, &QGrpcOperationContext::cancelRequested, this,
|
connect(context, &QGrpcOperationContext::writesDoneRequested, this, &Http2Handler::writesDone);
|
||||||
&Http2Handler::cancel);
|
|
||||||
QObject::connect(context, &QGrpcOperationContext::writesDoneRequested, this,
|
|
||||||
&Http2Handler::writesDone);
|
|
||||||
if (!m_endStreamAtFirstData) {
|
if (!m_endStreamAtFirstData) {
|
||||||
QObject::connect(context, &QGrpcOperationContext::writeMessageRequested, this,
|
connect(context, &QGrpcOperationContext::writeMessageRequested, this,
|
||||||
&Http2Handler::writeMessage);
|
&Http2Handler::writeMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject::connect(context, &QGrpcOperationContext::finished, &m_deadlineTimer, &QTimer::stop);
|
connect(context, &QGrpcOperationContext::finished, &m_deadlineTimer, &QTimer::stop);
|
||||||
m_deadlineTimer.setSingleShot(true);
|
m_deadlineTimer.setSingleShot(true);
|
||||||
|
|
||||||
writeMessage(context->argument());
|
writeMessage(context->argument());
|
||||||
|
|
@ -495,79 +489,76 @@ void Http2Handler::attachStream(QHttp2Stream *stream_)
|
||||||
|
|
||||||
m_stream = stream_;
|
m_stream = stream_;
|
||||||
|
|
||||||
QObject::connect(m_stream.get(), &QHttp2Stream::headersReceived, this,
|
connect(m_stream.get(), &QHttp2Stream::headersReceived, this,
|
||||||
[this](const HPack::HttpHeader &headers, bool endStream) mutable {
|
[this](const HPack::HttpHeader &headers, bool endStream) mutable {
|
||||||
if (m_state >= State::Cancelled) {
|
if (m_state >= State::Cancelled) {
|
||||||
// In case we are Cancelled or Finished, a
|
// In case we are Cancelled or Finished, a
|
||||||
// finished has been emitted already and the
|
// finished has been emitted already and the
|
||||||
// Handler should get deleted here.
|
// Handler should get deleted here.
|
||||||
qCDebug(lcStream, "[%p] Ignoring headers - already closed (state=%s)",
|
qCDebug(lcStream, "[%p] Ignoring headers - already closed (state=%s)", this,
|
||||||
this, QDebug::toBytes(m_state).constData());
|
QDebug::toBytes(m_state).constData());
|
||||||
deleteLater();
|
deleteLater();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HeaderPhase phase = HeaderPhase::Invalid;
|
HeaderPhase phase = HeaderPhase::Invalid;
|
||||||
if (m_state == State::RequestHeadersSent && endStream)
|
if (m_state == State::RequestHeadersSent && endStream)
|
||||||
phase = HeaderPhase::TrailersOnly;
|
phase = HeaderPhase::TrailersOnly;
|
||||||
else if (m_state == State::RequestHeadersSent && !endStream)
|
else if (m_state == State::RequestHeadersSent && !endStream)
|
||||||
phase = HeaderPhase::Initial;
|
phase = HeaderPhase::Initial;
|
||||||
else if (m_state == State::Active && endStream) {
|
else if (m_state == State::Active && endStream) {
|
||||||
phase = HeaderPhase::Trailers;
|
phase = HeaderPhase::Trailers;
|
||||||
} else {
|
} else {
|
||||||
qCWarning(lcStream,
|
qCWarning(lcStream,
|
||||||
"[%p] Received unexcpected %s HEADERS (state=%s, "
|
"[%p] Received unexcpected %s HEADERS (state=%s, "
|
||||||
"endStream=%d)",
|
"endStream=%d)",
|
||||||
this, QDebug::toBytes(phase).constData(),
|
this, QDebug::toBytes(phase).constData(),
|
||||||
QDebug::toBytes(m_state).constData(), endStream);
|
QDebug::toBytes(m_state).constData(), endStream);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_state = State::Active;
|
m_state = State::Active;
|
||||||
handleHeaders(headers, phase);
|
handleHeaders(headers, phase);
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(
|
connect(
|
||||||
m_stream.get(), &QHttp2Stream::errorOccurred, this,
|
m_stream.get(), &QHttp2Stream::errorOccurred, this,
|
||||||
[this](quint32 http2ErrorCode, const QString &errorString) {
|
[this](quint32 http2ErrorCode, const QString &errorString) {
|
||||||
finish({ http2ErrorToStatusCode(http2ErrorCode), errorString });
|
finish({ http2ErrorToStatusCode(http2ErrorCode), errorString });
|
||||||
},
|
},
|
||||||
Qt::SingleShotConnection);
|
Qt::SingleShotConnection);
|
||||||
|
|
||||||
QObject::connect(m_stream.get(), &QHttp2Stream::dataReceived, m_context.get(),
|
connect(m_stream.get(), &QHttp2Stream::dataReceived, m_context.get(),
|
||||||
[this](const QByteArray &data, bool endStream) {
|
[this](const QByteArray &data, bool endStream) {
|
||||||
if (m_state == State::Cancelled)
|
if (m_state == State::Cancelled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_expectedData.container.append(data);
|
m_expectedData.container.append(data);
|
||||||
|
|
||||||
if (!m_expectedData.updateExpectedSize())
|
if (!m_expectedData.updateExpectedSize())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (m_expectedData.container.size() >= m_expectedData.expectedSize) {
|
while (m_expectedData.container.size() >= m_expectedData.expectedSize) {
|
||||||
qCDebug(lcStream,
|
qCDebug(lcStream,
|
||||||
"[%p] About to process message (receivedSize=%" PRIdQSIZETYPE ", "
|
"[%p] About to process message (receivedSize=%" PRIdQSIZETYPE ", "
|
||||||
"expectedSize=%" PRIdQSIZETYPE ", containerSize=%" PRIdQSIZETYPE ")",
|
"expectedSize=%" PRIdQSIZETYPE ", containerSize=%" PRIdQSIZETYPE ")",
|
||||||
this, data.size(), m_expectedData.expectedSize,
|
this, data.size(), m_expectedData.expectedSize,
|
||||||
m_expectedData.container.size());
|
m_expectedData.container.size());
|
||||||
const auto len = m_expectedData.expectedSize
|
const auto len = m_expectedData.expectedSize - GrpcMessageSizeHeaderSize;
|
||||||
- GrpcMessageSizeHeaderSize;
|
const auto msg = m_expectedData.container.mid(GrpcMessageSizeHeaderSize, len);
|
||||||
const auto msg = m_expectedData.container
|
emit m_context->messageReceived(msg);
|
||||||
.mid(GrpcMessageSizeHeaderSize, len);
|
|
||||||
emit m_context->messageReceived(msg);
|
|
||||||
|
|
||||||
m_expectedData.container.remove(0, m_expectedData.expectedSize);
|
m_expectedData.container.remove(0, m_expectedData.expectedSize);
|
||||||
m_expectedData.expectedSize = 0;
|
m_expectedData.expectedSize = 0;
|
||||||
if (!m_expectedData.updateExpectedSize())
|
if (!m_expectedData.updateExpectedSize())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endStream)
|
if (endStream)
|
||||||
finish({});
|
finish({});
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(m_stream.get(), &QHttp2Stream::uploadFinished, this,
|
connect(m_stream.get(), &QHttp2Stream::uploadFinished, this, &Http2Handler::processQueue);
|
||||||
&Http2Handler::processQueue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Builds HTTP/2 headers for the initial gRPC request.
|
// Builds HTTP/2 headers for the initial gRPC request.
|
||||||
|
|
@ -961,10 +952,10 @@ QGrpcHttp2ChannelPrivate::QGrpcHttp2ChannelPrivate(const QUrl &uri, QGrpcHttp2Ch
|
||||||
localSocket->setSocketOptions(QLocalSocket::AbstractNamespaceOption);
|
localSocket->setSocketOptions(QLocalSocket::AbstractNamespaceOption);
|
||||||
m_isLocalSocket = true;
|
m_isLocalSocket = true;
|
||||||
|
|
||||||
QObject::connect(localSocket, &QLocalSocket::connected, this,
|
connect(localSocket, &QLocalSocket::connected, this,
|
||||||
&QGrpcHttp2ChannelPrivate::createHttp2Connection);
|
&QGrpcHttp2ChannelPrivate::createHttp2Connection);
|
||||||
QObject::connect(localSocket, &QLocalSocket::errorOccurred, this,
|
connect(localSocket, &QLocalSocket::errorOccurred, this,
|
||||||
&QGrpcHttp2ChannelPrivate::handleLocalSocketError);
|
&QGrpcHttp2ChannelPrivate::handleLocalSocketError);
|
||||||
|
|
||||||
m_reconnectFunction = [localSocket, this] {
|
m_reconnectFunction = [localSocket, this] {
|
||||||
const auto name = hostUri.host() + hostUri.path();
|
const auto name = hostUri.host() + hostUri.path();
|
||||||
|
|
@ -995,10 +986,10 @@ QGrpcHttp2ChannelPrivate::QGrpcHttp2ChannelPrivate(const QUrl &uri, QGrpcHttp2Ch
|
||||||
sslSocket->setSslConfiguration(defautlSslConfig);
|
sslSocket->setSslConfiguration(defautlSslConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject::connect(sslSocket, &QSslSocket::encrypted, this,
|
connect(sslSocket, &QSslSocket::encrypted, this,
|
||||||
&QGrpcHttp2ChannelPrivate::createHttp2Connection);
|
&QGrpcHttp2ChannelPrivate::createHttp2Connection);
|
||||||
QObject::connect(sslSocket, &QAbstractSocket::errorOccurred, this,
|
connect(sslSocket, &QAbstractSocket::errorOccurred, this,
|
||||||
&QGrpcHttp2ChannelPrivate::handleAbstractSocketError);
|
&QGrpcHttp2ChannelPrivate::handleAbstractSocketError);
|
||||||
|
|
||||||
m_reconnectFunction = [sslSocket, this] {
|
m_reconnectFunction = [sslSocket, this] {
|
||||||
qCDebug(lcChannel, "[%p] Connecting to SSL endpoint at: %s:%d", this,
|
qCDebug(lcChannel, "[%p] Connecting to SSL endpoint at: %s:%d", this,
|
||||||
|
|
@ -1016,10 +1007,10 @@ QGrpcHttp2ChannelPrivate::QGrpcHttp2ChannelPrivate(const QUrl &uri, QGrpcHttp2Ch
|
||||||
nonDefaultPort = hostUri.port() != 80;
|
nonDefaultPort = hostUri.port() != 80;
|
||||||
}
|
}
|
||||||
|
|
||||||
QObject::connect(httpSocket, &QAbstractSocket::connected, this,
|
connect(httpSocket, &QAbstractSocket::connected, this,
|
||||||
&QGrpcHttp2ChannelPrivate::createHttp2Connection);
|
&QGrpcHttp2ChannelPrivate::createHttp2Connection);
|
||||||
QObject::connect(httpSocket, &QAbstractSocket::errorOccurred, this,
|
connect(httpSocket, &QAbstractSocket::errorOccurred, this,
|
||||||
&QGrpcHttp2ChannelPrivate::handleAbstractSocketError);
|
&QGrpcHttp2ChannelPrivate::handleAbstractSocketError);
|
||||||
|
|
||||||
m_reconnectFunction = [httpSocket, this] {
|
m_reconnectFunction = [httpSocket, this] {
|
||||||
qCDebug(lcChannel, "[%p] Connecting to TCP endpoint at: %s:%d", this,
|
qCDebug(lcChannel, "[%p] Connecting to TCP endpoint at: %s:%d", this,
|
||||||
|
|
@ -1109,14 +1100,14 @@ void QGrpcHttp2ChannelPrivate::createHttp2Connection()
|
||||||
m_connection = QHttp2Connection::createDirectConnection(m_socket.get(), {});
|
m_connection = QHttp2Connection::createDirectConnection(m_socket.get(), {});
|
||||||
|
|
||||||
Q_ASSERT_X(m_connection, "QGrpcHttp2ChannelPrivate", "Unable to create the HTTP/2 connection");
|
Q_ASSERT_X(m_connection, "QGrpcHttp2ChannelPrivate", "Unable to create the HTTP/2 connection");
|
||||||
QObject::connect(m_socket.get(), &QAbstractSocket::readyRead, m_connection,
|
connect(m_socket.get(), &QAbstractSocket::readyRead, m_connection,
|
||||||
&QHttp2Connection::handleReadyRead);
|
&QHttp2Connection::handleReadyRead);
|
||||||
|
|
||||||
m_state = ConnectionState::Connected;
|
m_state = ConnectionState::Connected;
|
||||||
qCDebug(lcChannel, "[%p] Created new HTTP/2 connection to %s", this,
|
qCDebug(lcChannel, "[%p] Created new HTTP/2 connection to %s", this,
|
||||||
qPrintable(hostUri.toString()));
|
qPrintable(hostUri.toString()));
|
||||||
|
|
||||||
QObject::connect(m_connection, &QHttp2Connection::settingsFrameReceived, this, [this] {
|
connect(m_connection, &QHttp2Connection::settingsFrameReceived, this, [this] {
|
||||||
if (m_state == ConnectionState::SettingsReceived) {
|
if (m_state == ConnectionState::SettingsReceived) {
|
||||||
qCWarning(lcChannel,
|
qCWarning(lcChannel,
|
||||||
"[%p] Unexpected SETTINGS frame received multiple times in this session.",
|
"[%p] Unexpected SETTINGS frame received multiple times in this session.",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue