diff options
author | Markus Goetz <markus@woboq.com> | 2021-06-07 16:56:59 +0200 |
---|---|---|
committer | Markus Goetz <markus@woboq.com> | 2021-07-20 22:08:39 +0200 |
commit | e1b010ff47ae81067802d9240ea990d6d9187484 (patch) | |
tree | 612acc4acf7585aec439262326442b1a993ad168 /src/network | |
parent | 5e688a72046972b871347ff4d8dd141cdf9f2cef (diff) |
QNetworkReply: Add two new signals
These signals allow monitoring where in the HTTP1/HTTP2
flow a request is currently in.
Fixes: QTBUG-71698
Fixes: QTBUG-18766
Change-Id: Icc2fe435afc9f680fa7a76c32731e25fcdfeb4b4
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/access/qhttp2protocolhandler.cpp | 2 | ||||
-rw-r--r-- | src/network/access/qhttpnetworkconnection.cpp | 9 | ||||
-rw-r--r-- | src/network/access/qhttpnetworkconnection_p.h | 1 | ||||
-rw-r--r-- | src/network/access/qhttpnetworkconnectionchannel.cpp | 7 | ||||
-rw-r--r-- | src/network/access/qhttpnetworkreply_p.h | 2 | ||||
-rw-r--r-- | src/network/access/qhttpprotocolhandler.cpp | 2 | ||||
-rw-r--r-- | src/network/access/qhttpthreaddelegate.cpp | 2 | ||||
-rw-r--r-- | src/network/access/qhttpthreaddelegate_p.h | 2 | ||||
-rw-r--r-- | src/network/access/qnetworkreply.cpp | 21 | ||||
-rw-r--r-- | src/network/access/qnetworkreply.h | 2 | ||||
-rw-r--r-- | src/network/access/qnetworkreplyhttpimpl.cpp | 4 |
11 files changed, 54 insertions, 0 deletions
diff --git a/src/network/access/qhttp2protocolhandler.cpp b/src/network/access/qhttp2protocolhandler.cpp index 8f4c5ba6e6..b892a6b2a2 100644 --- a/src/network/access/qhttp2protocolhandler.cpp +++ b/src/network/access/qhttp2protocolhandler.cpp @@ -1369,6 +1369,8 @@ quint32 QHttp2ProtocolHandler::createNewStream(const HttpMessagePair &message, b } } + QMetaObject::invokeMethod(reply, "requestSent", Qt::QueuedConnection); + activeStreams.insert(newStreamID, newStream); return newStreamID; diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 13ad4e12e6..86637d24a7 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -749,6 +749,15 @@ QHttpNetworkRequest QHttpNetworkConnectionPrivate::predictNextRequest() const return QHttpNetworkRequest(); } +QHttpNetworkReply* QHttpNetworkConnectionPrivate::predictNextRequestsReply() const +{ + if (!highPriorityQueue.isEmpty()) + return highPriorityQueue.last().second; + if (!lowPriorityQueue.isEmpty()) + return lowPriorityQueue.last().second; + return nullptr; +} + // this is called from _q_startNextRequest and when a request has been sent down a socket from the channel void QHttpNetworkConnectionPrivate::fillPipeline(QAbstractSocket *socket) { diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h index 1c090776f6..f0d67d6594 100644 --- a/src/network/access/qhttpnetworkconnection_p.h +++ b/src/network/access/qhttpnetworkconnection_p.h @@ -214,6 +214,7 @@ public: void prepareRequest(HttpMessagePair &request); void updateChannel(int i, const HttpMessagePair &messagePair); QHttpNetworkRequest predictNextRequest() const; + QHttpNetworkReply* predictNextRequestsReply() const; void fillPipeline(QAbstractSocket *socket); bool fillPipeline(QList<HttpMessagePair> &queue, QHttpNetworkConnectionChannel &channel); diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 5d6495b5d3..458b729548 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -356,6 +356,13 @@ bool QHttpNetworkConnectionChannel::ensureConnection() QString connectHost = connection->d_func()->hostName; quint16 connectPort = connection->d_func()->port; + QHttpNetworkReply *potentialReply = connection->d_func()->predictNextRequestsReply(); + if (potentialReply) { + QMetaObject::invokeMethod(potentialReply, "socketConnecting", Qt::QueuedConnection); + } else if (h2RequestsToSend.count() > 0) { + QMetaObject::invokeMethod(h2RequestsToSend.values().at(0).second, "socketConnecting", Qt::QueuedConnection); + } + #ifndef QT_NO_NETWORKPROXY // HTTPS always use transparent proxy. if (connection->d_func()->networkProxy.type() != QNetworkProxy::NoProxy && !ssl) { diff --git a/src/network/access/qhttpnetworkreply_p.h b/src/network/access/qhttpnetworkreply_p.h index 78b34ff43b..5c062259ad 100644 --- a/src/network/access/qhttpnetworkreply_p.h +++ b/src/network/access/qhttpnetworkreply_p.h @@ -170,6 +170,8 @@ Q_SIGNALS: #endif Q_SIGNALS: + void socketConnecting(); + void requestSent(); void readyRead(); void finished(); void finishedWithError(QNetworkReply::NetworkError errorCode, const QString &detail = QString()); diff --git a/src/network/access/qhttpprotocolhandler.cpp b/src/network/access/qhttpprotocolhandler.cpp index f7f68ca65b..578dcfa1b0 100644 --- a/src/network/access/qhttpprotocolhandler.cpp +++ b/src/network/access/qhttpprotocolhandler.cpp @@ -319,6 +319,8 @@ bool QHttpProtocolHandler::sendRequest() #else m_header = QHttpNetworkRequestPrivate::header(m_channel->request, false); #endif + QMetaObject::invokeMethod(m_reply, "requestSent", Qt::QueuedConnection); + // flushing is dangerous (QSslSocket calls transmit which might read or error) // m_socket->flush(); QNonContiguousByteDevice* uploadByteDevice = m_channel->request.uploadByteDevice(); diff --git a/src/network/access/qhttpthreaddelegate.cpp b/src/network/access/qhttpthreaddelegate.cpp index 48e7953616..8db56222d2 100644 --- a/src/network/access/qhttpthreaddelegate.cpp +++ b/src/network/access/qhttpthreaddelegate.cpp @@ -377,6 +377,8 @@ void QHttpThreadDelegate::startRequest() // Don't care about ignored SSL errors for now in the synchronous HTTP case. } else if (!synchronous) { + connect(httpReply,SIGNAL(socketConnecting()), this, SIGNAL(socketConnecting())); + connect(httpReply,SIGNAL(requestSent()), this, SIGNAL(requestSent())); connect(httpReply,SIGNAL(headerChanged()), this, SLOT(headerChangedSlot())); connect(httpReply,SIGNAL(finished()), this, SLOT(finishedSlot())); connect(httpReply,SIGNAL(finishedWithError(QNetworkReply::NetworkError,QString)), diff --git a/src/network/access/qhttpthreaddelegate_p.h b/src/network/access/qhttpthreaddelegate_p.h index 5c3857b515..f919b403f9 100644 --- a/src/network/access/qhttpthreaddelegate_p.h +++ b/src/network/access/qhttpthreaddelegate_p.h @@ -143,6 +143,8 @@ signals: void sslConfigurationChanged(const QSslConfiguration &); void preSharedKeyAuthenticationRequired(QSslPreSharedKeyAuthenticator *); #endif + void socketConnecting(); + void requestSent(); void downloadMetaData(const QList<QPair<QByteArray,QByteArray> > &, int, const QString &, bool, QSharedPointer<char>, qint64, qint64, bool, bool); void downloadProgress(qint64, qint64); diff --git a/src/network/access/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp index c69bcc951e..09356e59cd 100644 --- a/src/network/access/qnetworkreply.cpp +++ b/src/network/access/qnetworkreply.cpp @@ -322,6 +322,27 @@ QNetworkReplyPrivate::QNetworkReplyPrivate() */ /*! + \fn void QNetworkReply::socketConnecting() + \since 6.3 + + This signal is emitted 0 or more times, when the socket + is connecting, before sending the request. Useful for + custom progress or timeout handling. + + \sa metaDataChanged(), requestSent() +*/ + +/*! + \fn void QNetworkReply::requestSent() + \since 6.3 + + This signal is emitted 1 or more times when the request was + sent. Useful for custom progress or timeout handling. + + \sa metaDataChanged(), socketConnecting() +*/ + +/*! \fn void QNetworkReply::metaDataChanged() \omit FIXME: Update name? \endomit diff --git a/src/network/access/qnetworkreply.h b/src/network/access/qnetworkreply.h index 2587696715..0cd01f6d4b 100644 --- a/src/network/access/qnetworkreply.h +++ b/src/network/access/qnetworkreply.h @@ -154,6 +154,8 @@ public Q_SLOTS: virtual void ignoreSslErrors(); Q_SIGNALS: + void socketConnecting(); + void requestSent(); void metaDataChanged(); void finished(); void errorOccurred(QNetworkReply::NetworkError); diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index e43b9dcb67..69597b1ec8 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -869,6 +869,10 @@ void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpReq QObject::connect(delegate, SIGNAL(downloadFinished()), q, SLOT(replyFinished()), Qt::QueuedConnection); + QObject::connect(delegate, &QHttpThreadDelegate::socketConnecting, + q, &QNetworkReply::socketConnecting, Qt::QueuedConnection); + QObject::connect(delegate, &QHttpThreadDelegate::requestSent, + q, &QNetworkReply::requestSent, Qt::QueuedConnection); connect(delegate, &QHttpThreadDelegate::downloadMetaData, this, &QNetworkReplyHttpImplPrivate::replyDownloadMetaData, Qt::QueuedConnection); QObject::connect(delegate, SIGNAL(downloadProgress(qint64,qint64)), |