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:
|
||||
void prepareInitialRequest(QGrpcOperationContext *operationContext,
|
||||
QGrpcHttp2ChannelPrivate *channel);
|
||||
[[nodiscard]] QGrpcHttp2ChannelPrivate *channelPriv() const;
|
||||
[[nodiscard]] QGrpcHttp2Channel *channel() const;
|
||||
|
||||
HPack::HttpHeader m_initialHeaders;
|
||||
std::weak_ptr<QGrpcOperationContext> m_operation;
|
||||
|
|
@ -412,9 +414,8 @@ void Http2Handler::attachStream(QHttp2Stream *stream_)
|
|||
auto *channelOpPtr = operation();
|
||||
m_stream = stream_;
|
||||
|
||||
auto *parentChannel = qobject_cast<QGrpcHttp2ChannelPrivate *>(parent());
|
||||
QObject::connect(m_stream.get(), &QHttp2Stream::headersReceived, channelOpPtr,
|
||||
[channelOpPtr, parentChannel, this](const HPack::HttpHeader &headers,
|
||||
[channelOpPtr, this](const HPack::HttpHeader &headers,
|
||||
bool endStream) {
|
||||
auto md = channelOpPtr->serverMetadata();
|
||||
QtGrpc::StatusCode statusCode = StatusCode::Ok;
|
||||
|
|
@ -436,25 +437,24 @@ void Http2Handler::attachStream(QHttp2Stream *stream_)
|
|||
emit channelOpPtr->finished(
|
||||
QGrpcStatus{ statusCode,statusMessage });
|
||||
}
|
||||
parentChannel->deleteHandler(this);
|
||||
channelPriv()->deleteHandler(this);
|
||||
}
|
||||
});
|
||||
|
||||
Q_ASSERT(parentChannel != nullptr);
|
||||
QObject::connect(
|
||||
m_stream.get(), &QHttp2Stream::errorOccurred, parentChannel,
|
||||
[parentChannel, this](quint32 http2ErrorCode, const QString &errorString) {
|
||||
m_stream.get(), &QHttp2Stream::errorOccurred, channelPriv(),
|
||||
[this](quint32 http2ErrorCode, const QString &errorString) {
|
||||
if (!m_operation.expired()) {
|
||||
auto channelOp = m_operation.lock();
|
||||
emit channelOp->finished(QGrpcStatus{ http2ErrorToStatusCode(http2ErrorCode),
|
||||
errorString });
|
||||
}
|
||||
parentChannel->deleteHandler(this);
|
||||
channelPriv()->deleteHandler(this);
|
||||
},
|
||||
Qt::SingleShotConnection);
|
||||
|
||||
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) {
|
||||
m_expectedData.container.append(data);
|
||||
|
||||
|
|
@ -479,7 +479,7 @@ void Http2Handler::attachStream(QHttp2Stream *stream_)
|
|||
if (endStream) {
|
||||
m_handlerState = Finished;
|
||||
emit channelOpPtr->finished({});
|
||||
parentChannel->deleteHandler(this);
|
||||
channelPriv()->deleteHandler(this);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -488,10 +488,10 @@ void Http2Handler::attachStream(QHttp2Stream *stream_)
|
|||
&Http2Handler::processQueue);
|
||||
|
||||
std::optional<std::chrono::milliseconds> deadline;
|
||||
if (channelOpPtr->callOptions().deadlineTimeout())
|
||||
deadline = channelOpPtr->callOptions().deadlineTimeout();
|
||||
else if (parentChannel->q_ptr->channelOptions().deadlineTimeout())
|
||||
deadline = parentChannel->q_ptr->channelOptions().deadlineTimeout();
|
||||
if (auto dt = channelOpPtr->callOptions().deadlineTimeout())
|
||||
deadline = dt;
|
||||
else if (auto chdt = channel()->channelOptions().deadlineTimeout())
|
||||
deadline = chdt;
|
||||
if (deadline) {
|
||||
// We have an active stream and a deadline. It's time to start the timer.
|
||||
QObject::connect(&m_deadlineTimer, &QTimer::timeout, this, &Http2Handler::deadlineTimeout);
|
||||
|
|
@ -559,6 +559,15 @@ void Http2Handler::prepareInitialRequest(QGrpcOperationContext *operationContext
|
|||
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
|
||||
// or from the user in client/bidirectional streaming RPCs.
|
||||
void Http2Handler::writeMessage(QByteArrayView data)
|
||||
|
|
|
|||
Loading…
Reference in New Issue