Skip to content

Commit

Permalink
QNAM: Prepare protocol handlers for local socket
Browse files Browse the repository at this point in the history
+ a small stretch into adjacent functions, because some are used from
the protocol handler(s).

Task-number: QTBUG-102855
Change-Id: Ie394378fef2b1723e69286fd870fc34b7306734a
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
Morten242 committed May 2, 2024
1 parent 45bf8ee commit 8a261fa
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/network/access/qabstractprotocolhandler_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ QT_BEGIN_NAMESPACE

class QHttpNetworkConnectionChannel;
class QHttpNetworkReply;
class QAbstractSocket;
class QIODevice;
class QHttpNetworkConnection;

class QAbstractProtocolHandler {
Expand All @@ -39,7 +39,7 @@ class QAbstractProtocolHandler {
protected:
QHttpNetworkConnectionChannel *m_channel;
QHttpNetworkReply *m_reply;
QAbstractSocket *m_socket;
QIODevice *m_socket;
QHttpNetworkConnection *m_connection;
};

Expand Down
22 changes: 11 additions & 11 deletions src/network/access/qhttpnetworkconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <qauthenticator.h>
#include <qcoreapplication.h>
#include <private/qdecompresshelper_p.h>
#include <private/qsocketabstraction_p.h>

#include <qbuffer.h>
#include <qpair.h>
Expand Down Expand Up @@ -319,7 +320,7 @@ void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair)



void QHttpNetworkConnectionPrivate::emitReplyError(QAbstractSocket *socket,
void QHttpNetworkConnectionPrivate::emitReplyError(QIODevice *socket,
QHttpNetworkReply *reply,
QNetworkReply::NetworkError errorCode)
{
Expand Down Expand Up @@ -384,7 +385,7 @@ void QHttpNetworkConnectionPrivate::copyCredentials(int fromChannel, QAuthentica


// handles the authentication for one channel and eventually re-starts the other channels
bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket *socket, QHttpNetworkReply *reply,
bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QIODevice *socket, QHttpNetworkReply *reply,
bool isProxy, bool &resend)
{
Q_ASSERT(socket);
Expand Down Expand Up @@ -486,7 +487,7 @@ bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket
}

// Used by the HTTP1 code-path
QUrl QHttpNetworkConnectionPrivate::parseRedirectResponse(QAbstractSocket *socket,
QUrl QHttpNetworkConnectionPrivate::parseRedirectResponse(QIODevice *socket,
QHttpNetworkReply *reply)
{
ParseRedirectResult result = parseRedirectResponse(reply);
Expand Down Expand Up @@ -740,7 +741,7 @@ QHttpNetworkReply* QHttpNetworkConnectionPrivate::predictNextRequestsReply() con
}

// this is called from _q_startNextRequest and when a request has been sent down a socket from the channel
void QHttpNetworkConnectionPrivate::fillPipeline(QAbstractSocket *socket)
void QHttpNetworkConnectionPrivate::fillPipeline(QIODevice *socket)
{
// return fast if there is nothing to pipeline
if (highPriorityQueue.isEmpty() && lowPriorityQueue.isEmpty())
Expand Down Expand Up @@ -768,7 +769,7 @@ void QHttpNetworkConnectionPrivate::fillPipeline(QAbstractSocket *socket)
return;

// check if socket is connected
if (socket->state() != QAbstractSocket::ConnectedState)
if (QSocketAbstraction::socketState(socket) != QAbstractSocket::ConnectedState)
return;

// check for resendCurrent
Expand Down Expand Up @@ -862,16 +863,15 @@ bool QHttpNetworkConnectionPrivate::fillPipeline(QList<HttpMessagePair> &queue,
}


QString QHttpNetworkConnectionPrivate::errorDetail(QNetworkReply::NetworkError errorCode, QAbstractSocket *socket, const QString &extraDetail)
QString QHttpNetworkConnectionPrivate::errorDetail(QNetworkReply::NetworkError errorCode, QIODevice *socket, const QString &extraDetail)
{
QString errorString;
switch (errorCode) {
case QNetworkReply::HostNotFoundError:
if (socket)
errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(socket->peerName());
else
errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(hostName);
case QNetworkReply::HostNotFoundError: {
const QString peerName = socket ? QSocketAbstraction::socketPeerName(socket) : hostName;
errorString = QCoreApplication::translate("QHttp", "Host %1 not found").arg(peerName);
break;
}
case QNetworkReply::ConnectionRefusedError:
errorString = QCoreApplication::translate("QHttp", "Connection refused");
break;
Expand Down
10 changes: 5 additions & 5 deletions src/network/access/qhttpnetworkconnection_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class QHttpNetworkConnectionPrivate : public QObjectPrivate
QHttpNetworkRequest predictNextRequest() const;
QHttpNetworkReply* predictNextRequestsReply() const;

void fillPipeline(QAbstractSocket *socket);
void fillPipeline(QIODevice *socket);
bool fillPipeline(QList<HttpMessagePair> &queue, QHttpNetworkConnectionChannel &channel);

// read more HTTP body after the next event loop spin
Expand All @@ -197,7 +197,7 @@ class QHttpNetworkConnectionPrivate : public QObjectPrivate

void createAuthorization(QIODevice *socket, QHttpNetworkRequest &request);

QString errorDetail(QNetworkReply::NetworkError errorCode, QAbstractSocket *socket,
QString errorDetail(QNetworkReply::NetworkError errorCode, QIODevice *socket,
const QString &extraDetail = QString());

void removeReply(QHttpNetworkReply *reply);
Expand All @@ -219,15 +219,15 @@ class QHttpNetworkConnectionPrivate : public QObjectPrivate
qint64 uncompressedBytesAvailableNextBlock(const QHttpNetworkReply &reply) const;


void emitReplyError(QAbstractSocket *socket, QHttpNetworkReply *reply, QNetworkReply::NetworkError errorCode);
bool handleAuthenticateChallenge(QAbstractSocket *socket, QHttpNetworkReply *reply, bool isProxy, bool &resend);
void emitReplyError(QIODevice *socket, QHttpNetworkReply *reply, QNetworkReply::NetworkError errorCode);
bool handleAuthenticateChallenge(QIODevice *socket, QHttpNetworkReply *reply, bool isProxy, bool &resend);
struct ParseRedirectResult {
QUrl redirectUrl;
QNetworkReply::NetworkError errorCode;
};
static ParseRedirectResult parseRedirectResponse(QHttpNetworkReply *reply);
// Used by the HTTP1 code-path
QUrl parseRedirectResponse(QAbstractSocket *socket, QHttpNetworkReply *reply);
QUrl parseRedirectResponse(QIODevice *socket, QHttpNetworkReply *reply);

#ifndef QT_NO_NETWORKPROXY
QNetworkProxy networkProxy;
Expand Down
12 changes: 6 additions & 6 deletions src/network/access/qhttpprotocolhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <private/qhttpprotocolhandler_p.h>
#include <private/qnoncontiguousbytedevice_p.h>
#include <private/qhttpnetworkconnectionchannel_p.h>
#include <private/qsocketabstraction_p.h>

QT_BEGIN_NAMESPACE

Expand Down Expand Up @@ -34,10 +35,8 @@ void QHttpProtocolHandler::_q_receiveReply()
return;
}

QAbstractSocket::SocketState socketState = m_socket->state();

// connection might be closed to signal the end of data
if (socketState == QAbstractSocket::UnconnectedState) {
if (QSocketAbstraction::socketState(m_socket) == QAbstractSocket::UnconnectedState) {
if (m_socket->bytesAvailable() <= 0) {
if (m_reply->d_func()->state == QHttpNetworkReplyPrivate::ReadingDataState) {
// finish this reply. this case happens when the server did not send a content length
Expand Down Expand Up @@ -115,7 +114,7 @@ void QHttpProtocolHandler::_q_receiveReply()
}
case QHttpNetworkReplyPrivate::ReadingDataState: {
QHttpNetworkReplyPrivate *replyPrivate = m_reply->d_func();
if (m_socket->state() == QAbstractSocket::ConnectedState &&
if (QSocketAbstraction::socketState(m_socket) == QAbstractSocket::ConnectedState &&
replyPrivate->downstreamLimited && !replyPrivate->responseData.isEmpty() && replyPrivate->shouldEmitSignals()) {
// (only do the following when still connected, not when we have already been disconnected and there is still data)
// We already have some HTTP body data. We don't read more from the socket until
Expand Down Expand Up @@ -193,15 +192,16 @@ void QHttpProtocolHandler::_q_receiveReply()

void QHttpProtocolHandler::_q_readyRead()
{
if (m_socket->state() == QAbstractSocket::ConnectedState && m_socket->bytesAvailable() == 0) {
if (QSocketAbstraction::socketState(m_socket) == QAbstractSocket::ConnectedState
&& m_socket->bytesAvailable() == 0) {
// We got a readyRead but no bytes are available..
// This happens for the Unbuffered QTcpSocket
// Also check if socket is in ConnectedState since
// this function may also be invoked via the event loop.
char c;
qint64 ret = m_socket->peek(&c, 1);
if (ret < 0) {
m_channel->_q_error(m_socket->error());
m_channel->_q_error(QSocketAbstraction::socketError(m_socket));
// We still need to handle the reply so it emits its signals etc.
if (m_reply)
_q_receiveReply();
Expand Down

0 comments on commit 8a261fa

Please sign in to comment.