diff --git a/src/network/access/qabstractprotocolhandler_p.h b/src/network/access/qabstractprotocolhandler_p.h index ad82aae66e8..da5eaeeb74c 100644 --- a/src/network/access/qabstractprotocolhandler_p.h +++ b/src/network/access/qabstractprotocolhandler_p.h @@ -23,7 +23,7 @@ QT_BEGIN_NAMESPACE class QHttpNetworkConnectionChannel; class QHttpNetworkReply; -class QAbstractSocket; +class QIODevice; class QHttpNetworkConnection; class QAbstractProtocolHandler { @@ -39,7 +39,7 @@ class QAbstractProtocolHandler { protected: QHttpNetworkConnectionChannel *m_channel; QHttpNetworkReply *m_reply; - QAbstractSocket *m_socket; + QIODevice *m_socket; QHttpNetworkConnection *m_connection; }; diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 1897380e0eb..419491a7111 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -319,7 +320,7 @@ void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair) -void QHttpNetworkConnectionPrivate::emitReplyError(QAbstractSocket *socket, +void QHttpNetworkConnectionPrivate::emitReplyError(QIODevice *socket, QHttpNetworkReply *reply, QNetworkReply::NetworkError errorCode) { @@ -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); @@ -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); @@ -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()) @@ -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 @@ -862,16 +863,15 @@ bool QHttpNetworkConnectionPrivate::fillPipeline(QList &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; diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h index 36234a24bac..c2d062fb16d 100644 --- a/src/network/access/qhttpnetworkconnection_p.h +++ b/src/network/access/qhttpnetworkconnection_p.h @@ -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 &queue, QHttpNetworkConnectionChannel &channel); // read more HTTP body after the next event loop spin @@ -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); @@ -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; diff --git a/src/network/access/qhttpprotocolhandler.cpp b/src/network/access/qhttpprotocolhandler.cpp index 28eab038904..fb584eb9ccf 100644 --- a/src/network/access/qhttpprotocolhandler.cpp +++ b/src/network/access/qhttpprotocolhandler.cpp @@ -5,6 +5,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -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 @@ -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 @@ -193,7 +192,8 @@ 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 @@ -201,7 +201,7 @@ void QHttpProtocolHandler::_q_readyRead() 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();