mirror of https://github.com/qt/qtgrpc.git
Http2Handler: provide channel() and channelPriv() accessors
For consistency. No null checking is needed as the channel will always
destroy all children before destroying itself.
Pick-to: 6.9 6.8
Change-Id: I4638cd906dc6c66d2559048bd147216518655110
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
(cherry picked from commit f8196f8050)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
a3c69b53fb
commit
b5e89d251e
|
|
@ -273,6 +273,8 @@ public:
|
||||||
private:
|
private:
|
||||||
void prepareInitialRequest(QGrpcOperationContext *operationContext,
|
void prepareInitialRequest(QGrpcOperationContext *operationContext,
|
||||||
QGrpcHttp2ChannelPrivate *channel);
|
QGrpcHttp2ChannelPrivate *channel);
|
||||||
|
[[nodiscard]] QGrpcHttp2ChannelPrivate *channelPriv() const;
|
||||||
|
[[nodiscard]] QGrpcHttp2Channel *channel() const;
|
||||||
|
|
||||||
HPack::HttpHeader m_initialHeaders;
|
HPack::HttpHeader m_initialHeaders;
|
||||||
std::weak_ptr<QGrpcOperationContext> m_operation;
|
std::weak_ptr<QGrpcOperationContext> m_operation;
|
||||||
|
|
@ -412,9 +414,8 @@ void Http2Handler::attachStream(QHttp2Stream *stream_)
|
||||||
auto *channelOpPtr = operation();
|
auto *channelOpPtr = operation();
|
||||||
m_stream = stream_;
|
m_stream = stream_;
|
||||||
|
|
||||||
auto *parentChannel = qobject_cast<QGrpcHttp2ChannelPrivate *>(parent());
|
|
||||||
QObject::connect(m_stream.get(), &QHttp2Stream::headersReceived, channelOpPtr,
|
QObject::connect(m_stream.get(), &QHttp2Stream::headersReceived, channelOpPtr,
|
||||||
[channelOpPtr, parentChannel, this](const HPack::HttpHeader &headers,
|
[channelOpPtr, this](const HPack::HttpHeader &headers,
|
||||||
bool endStream) {
|
bool endStream) {
|
||||||
auto md = channelOpPtr->serverMetadata();
|
auto md = channelOpPtr->serverMetadata();
|
||||||
QtGrpc::StatusCode statusCode = StatusCode::Ok;
|
QtGrpc::StatusCode statusCode = StatusCode::Ok;
|
||||||
|
|
@ -436,25 +437,24 @@ void Http2Handler::attachStream(QHttp2Stream *stream_)
|
||||||
emit channelOpPtr->finished(
|
emit channelOpPtr->finished(
|
||||||
QGrpcStatus{ statusCode,statusMessage });
|
QGrpcStatus{ statusCode,statusMessage });
|
||||||
}
|
}
|
||||||
parentChannel->deleteHandler(this);
|
channelPriv()->deleteHandler(this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Q_ASSERT(parentChannel != nullptr);
|
|
||||||
QObject::connect(
|
QObject::connect(
|
||||||
m_stream.get(), &QHttp2Stream::errorOccurred, parentChannel,
|
m_stream.get(), &QHttp2Stream::errorOccurred, channelPriv(),
|
||||||
[parentChannel, this](quint32 http2ErrorCode, const QString &errorString) {
|
[this](quint32 http2ErrorCode, const QString &errorString) {
|
||||||
if (!m_operation.expired()) {
|
if (!m_operation.expired()) {
|
||||||
auto channelOp = m_operation.lock();
|
auto channelOp = m_operation.lock();
|
||||||
emit channelOp->finished(QGrpcStatus{ http2ErrorToStatusCode(http2ErrorCode),
|
emit channelOp->finished(QGrpcStatus{ http2ErrorToStatusCode(http2ErrorCode),
|
||||||
errorString });
|
errorString });
|
||||||
}
|
}
|
||||||
parentChannel->deleteHandler(this);
|
channelPriv()->deleteHandler(this);
|
||||||
},
|
},
|
||||||
Qt::SingleShotConnection);
|
Qt::SingleShotConnection);
|
||||||
|
|
||||||
QObject::connect(m_stream.get(), &QHttp2Stream::dataReceived, channelOpPtr,
|
QObject::connect(m_stream.get(), &QHttp2Stream::dataReceived, channelOpPtr,
|
||||||
[channelOpPtr, parentChannel, this](const QByteArray &data, bool endStream) {
|
[channelOpPtr, this](const QByteArray &data, bool endStream) {
|
||||||
if (m_handlerState != Cancelled) {
|
if (m_handlerState != Cancelled) {
|
||||||
m_expectedData.container.append(data);
|
m_expectedData.container.append(data);
|
||||||
|
|
||||||
|
|
@ -479,7 +479,7 @@ void Http2Handler::attachStream(QHttp2Stream *stream_)
|
||||||
if (endStream) {
|
if (endStream) {
|
||||||
m_handlerState = Finished;
|
m_handlerState = Finished;
|
||||||
emit channelOpPtr->finished({});
|
emit channelOpPtr->finished({});
|
||||||
parentChannel->deleteHandler(this);
|
channelPriv()->deleteHandler(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -488,10 +488,10 @@ void Http2Handler::attachStream(QHttp2Stream *stream_)
|
||||||
&Http2Handler::processQueue);
|
&Http2Handler::processQueue);
|
||||||
|
|
||||||
std::optional<std::chrono::milliseconds> deadline;
|
std::optional<std::chrono::milliseconds> deadline;
|
||||||
if (channelOpPtr->callOptions().deadlineTimeout())
|
if (auto dt = channelOpPtr->callOptions().deadlineTimeout())
|
||||||
deadline = channelOpPtr->callOptions().deadlineTimeout();
|
deadline = dt;
|
||||||
else if (parentChannel->q_ptr->channelOptions().deadlineTimeout())
|
else if (auto chdt = channel()->channelOptions().deadlineTimeout())
|
||||||
deadline = parentChannel->q_ptr->channelOptions().deadlineTimeout();
|
deadline = chdt;
|
||||||
if (deadline) {
|
if (deadline) {
|
||||||
// We have an active stream and a deadline. It's time to start the timer.
|
// We have an active stream and a deadline. It's time to start the timer.
|
||||||
QObject::connect(&m_deadlineTimer, &QTimer::timeout, this, &Http2Handler::deadlineTimeout);
|
QObject::connect(&m_deadlineTimer, &QTimer::timeout, this, &Http2Handler::deadlineTimeout);
|
||||||
|
|
@ -559,6 +559,15 @@ void Http2Handler::prepareInitialRequest(QGrpcOperationContext *operationContext
|
||||||
writeMessage(operationContext->argument());
|
writeMessage(operationContext->argument());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QGrpcHttp2ChannelPrivate *Http2Handler::channelPriv() const
|
||||||
|
{
|
||||||
|
return qobject_cast<QGrpcHttp2ChannelPrivate *>(this->parent());
|
||||||
|
}
|
||||||
|
QGrpcHttp2Channel *Http2Handler::channel() const
|
||||||
|
{
|
||||||
|
return channelPriv()->q_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
// Slot to enqueue a writeMessage request, either from the initial message
|
// Slot to enqueue a writeMessage request, either from the initial message
|
||||||
// or from the user in client/bidirectional streaming RPCs.
|
// or from the user in client/bidirectional streaming RPCs.
|
||||||
void Http2Handler::writeMessage(QByteArrayView data)
|
void Http2Handler::writeMessage(QByteArrayView data)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue