diff options
Diffstat (limited to 'src/network/access')
29 files changed, 316 insertions, 141 deletions
diff --git a/src/network/access/qabstractprotocolhandler.cpp b/src/network/access/qabstractprotocolhandler.cpp index f15dfe6899..6847816ba7 100644 --- a/src/network/access/qabstractprotocolhandler.cpp +++ b/src/network/access/qabstractprotocolhandler.cpp @@ -43,7 +43,7 @@ QT_BEGIN_NAMESPACE QAbstractProtocolHandler::QAbstractProtocolHandler(QHttpNetworkConnectionChannel *channel) - : m_channel(channel), m_reply(0), m_socket(m_channel->socket), m_connection(m_channel->connection) + : m_channel(channel), m_reply(nullptr), m_socket(m_channel->socket), m_connection(m_channel->connection) { Q_ASSERT(m_channel); Q_ASSERT(m_socket); diff --git a/src/network/access/qftp.cpp b/src/network/access/qftp.cpp index cc230a5411..62ae1adbd9 100644 --- a/src/network/access/qftp.cpp +++ b/src/network/access/qftp.cpp @@ -74,7 +74,7 @@ public: CsConnectionRefused }; - QFtpDTP(QFtpPI *p, QObject *parent = 0); + QFtpDTP(QFtpPI *p, QObject *parent = nullptr); void setData(QByteArray *); void setDevice(QIODevice *); @@ -149,7 +149,7 @@ class QFtpPI : public QObject Q_OBJECT public: - QFtpPI(QObject *parent = 0); + QFtpPI(QObject *parent = nullptr); void connectToHost(const QString &host, quint16 port); @@ -229,7 +229,7 @@ class QFtpCommand { public: QFtpCommand(QFtp::Command cmd, const QStringList &raw, const QByteArray &ba); - QFtpCommand(QFtp::Command cmd, const QStringList &raw, QIODevice *dev = 0); + QFtpCommand(QFtp::Command cmd, const QStringList &raw, QIODevice *dev = nullptr); ~QFtpCommand(); int id; @@ -279,7 +279,7 @@ QFtpCommand::~QFtpCommand() *********************************************************************/ QFtpDTP::QFtpDTP(QFtpPI *p, QObject *parent) : QObject(parent), - socket(0), + socket(nullptr), listener(this), pi(p), callWriteData(false) @@ -314,7 +314,7 @@ void QFtpDTP::connectToHost(const QString & host, quint16 port) if (socket) { delete socket; - socket = 0; + socket = nullptr; } socket = new QTcpSocket(this); #ifndef QT_NO_BEARERMANAGEMENT @@ -427,7 +427,7 @@ void QFtpDTP::writeData() } // do we continue uploading? - callWriteData = data.dev != 0; + callWriteData = data.dev != nullptr; } } @@ -779,7 +779,7 @@ void QFtpDTP::setupSocket() void QFtpDTP::clearData() { is_ba = false; - data.dev = 0; + data.dev = nullptr; } /********************************************************************** @@ -792,7 +792,7 @@ QFtpPI::QFtpPI(QObject *parent) : rawCommand(false), transferConnectionExtended(true), dtp(this), - commandSocket(0), + commandSocket(nullptr), state(Begin), abortState(None), currentCmd(QString()), waitForDtpToConnect(false), @@ -2173,10 +2173,10 @@ QFtp::Command QFtp::currentCommand() const QIODevice* QFtp::currentDevice() const { if (d_func()->pending.isEmpty()) - return 0; + return nullptr; QFtpCommand *c = d_func()->pending.first(); if (c->is_ba) - return 0; + return nullptr; return c->data.dev; } diff --git a/src/network/access/qhttpmultipart.cpp b/src/network/access/qhttpmultipart.cpp index c59df9d8b8..d6fefc4314 100644 --- a/src/network/access/qhttpmultipart.cpp +++ b/src/network/access/qhttpmultipart.cpp @@ -111,7 +111,7 @@ QHttpPart::QHttpPart(const QHttpPart &other) : d(other.d) */ QHttpPart::~QHttpPart() { - d = 0; + d = nullptr; } /*! diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 21c6359807..b9a4c874c0 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -382,9 +382,9 @@ void QHttpNetworkConnectionPrivate::emitReplyError(QAbstractSocket *socket, // Clean the channel channels[i].close(); - channels[i].reply = 0; + channels[i].reply = nullptr; if (channels[i].protocolHandler) - channels[i].protocolHandler->setReply(0); + channels[i].protocolHandler->setReply(nullptr); channels[i].request = QHttpNetworkRequest(); if (socket) channels[i].requeueCurrentlyPipelinedRequests(); @@ -408,7 +408,7 @@ void QHttpNetworkConnectionPrivate::copyCredentials(int fromChannel, QAuthentica } // select another channel - QAuthenticator* otherAuth = 0; + QAuthenticator* otherAuth = nullptr; for (int i = 0; i < activeChannelCount; ++i) { if (i == fromChannel) continue; @@ -441,7 +441,7 @@ bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket if (authMethod != QAuthenticatorPrivate::None) { int i = indexOf(socket); //Use a single authenticator for all domains. ### change later to use domain/realm - QAuthenticator* auth = 0; + QAuthenticator* auth = nullptr; if (isProxy) { auth = &channels[i].proxyAuthenticator; channels[i].proxyAuthMethod = authMethod; @@ -496,7 +496,7 @@ bool QHttpNetworkConnectionPrivate::handleAuthenticateChallenge(QAbstractSocket // we need to bail out if authentication is required. if (priv->phase == QAuthenticatorPrivate::Done || !reply->request().withCredentials()) { // Reset authenticator so the next request on that channel does not get messed up - auth = 0; + auth = nullptr; if (isProxy) channels[i].proxyAuthenticator = QAuthenticator(); else @@ -766,7 +766,7 @@ void QHttpNetworkConnectionPrivate::fillPipeline(QAbstractSocket *socket) int i = indexOf(socket); // return fast if there was no reply right now processed - if (channels[i].reply == 0) + if (channels[i].reply == nullptr) return; if (! (defaultPipelineLength - channels[i].alreadyPipelinedRequests.length() >= defaultRePipelineLength)) { @@ -937,9 +937,9 @@ void QHttpNetworkConnectionPrivate::removeReply(QHttpNetworkReply *reply) for (int i = 0; i < activeChannelCount; ++i) { // is the reply associated the currently processing of this channel? if (channels[i].reply == reply) { - channels[i].reply = 0; + channels[i].reply = nullptr; if (channels[i].protocolHandler) - channels[i].protocolHandler->setReply(0); + channels[i].protocolHandler->setReply(nullptr); channels[i].request = QHttpNetworkRequest(); channels[i].resendCurrent = false; diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 39f392a79b..47081b29d2 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -87,11 +87,11 @@ private: static const int reconnectAttemptsDefault = 3; QHttpNetworkConnectionChannel::QHttpNetworkConnectionChannel() - : socket(0) + : socket(nullptr) , ssl(false) , isInitialized(false) , state(IdleState) - , reply(0) + , reply(nullptr) , written(0) , bytesTotal(0) , resendCurrent(false) @@ -102,13 +102,13 @@ QHttpNetworkConnectionChannel::QHttpNetworkConnectionChannel() , proxyAuthMethod(QAuthenticatorPrivate::None) , authenticationCredentialsSent(false) , proxyCredentialsSent(false) - , protocolHandler(0) + , protocolHandler(nullptr) #ifndef QT_NO_SSL , ignoreAllSslErrors(false) #endif , pipeliningSupported(PipeliningSupportUnknown) , networkLayerPreference(QAbstractSocket::AnyIPProtocol) - , connection(0) + , connection(nullptr) { // Inlining this function in the header leads to compiler error on // release-armv5, on at least timebox 9.2 and 10.1. @@ -295,9 +295,9 @@ void QHttpNetworkConnectionChannel::handleUnexpectedEOF() close(); reply->d_func()->errorString = connection->d_func()->errorDetail(QNetworkReply::RemoteHostClosedError, socket); emit reply->finishedWithError(QNetworkReply::RemoteHostClosedError, reply->d_func()->errorString); - reply = 0; + reply = nullptr; if (protocolHandler) - protocolHandler->setReply(0); + protocolHandler->setReply(nullptr); request = QHttpNetworkRequest(); QMetaObject::invokeMethod(connection, "_q_startNextRequest", Qt::QueuedConnection); } else { @@ -526,8 +526,8 @@ void QHttpNetworkConnectionChannel::allDone() // problem. if (!resendCurrent) { request = QHttpNetworkRequest(); - reply = 0; - protocolHandler->setReply(0); + reply = nullptr; + protocolHandler->setReply(nullptr); } // move next from pipeline to current request @@ -1100,9 +1100,9 @@ void QHttpNetworkConnectionChannel::_q_error(QAbstractSocket::SocketError socket if (reply) { reply->d_func()->errorString = errorString; emit reply->finishedWithError(errorCode, errorString); - reply = 0; + reply = nullptr; if (protocolHandler) - protocolHandler->setReply(0); + protocolHandler->setReply(nullptr); } } while (!connection->d_func()->highPriorityQueue.isEmpty() || !connection->d_func()->lowPriorityQueue.isEmpty()); diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index a8b635c45a..af456c3607 100644 --- a/src/network/access/qhttpnetworkreply.cpp +++ b/src/network/access/qhttpnetworkreply.cpp @@ -330,12 +330,12 @@ QHttpNetworkReplyPrivate::QHttpNetworkReplyPrivate(const QUrl &newUrl) currentlyUploadedDataInWindow(0), totallyUploadedData(0), removedContentLength(-1), - connection(0), + connection(nullptr), autoDecompress(false), responseData(), requestIsPrepared(false) ,pipeliningUsed(false), spdyUsed(false), downstreamLimited(false) - ,userProvidedDownloadBuffer(0) + ,userProvidedDownloadBuffer(nullptr) #ifndef QT_NO_COMPRESS - ,inflateStrm(0) + ,inflateStrm(nullptr) #endif { @@ -375,8 +375,8 @@ void QHttpNetworkReplyPrivate::clearHttpLayerInformation() // TODO: Isn't everything HTTP layer related? We don't need to set connection and connectionChannel to 0 at all void QHttpNetworkReplyPrivate::clear() { - connection = 0; - connectionChannel = 0; + connection = nullptr; + connectionChannel = nullptr; autoDecompress = false; clearHttpLayerInformation(); } diff --git a/src/network/access/qhttpnetworkrequest.cpp b/src/network/access/qhttpnetworkrequest.cpp index a3f71b8d2f..5fb8885bdf 100644 --- a/src/network/access/qhttpnetworkrequest.cpp +++ b/src/network/access/qhttpnetworkrequest.cpp @@ -44,7 +44,7 @@ QT_BEGIN_NAMESPACE QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate(QHttpNetworkRequest::Operation op, QHttpNetworkRequest::Priority pri, const QUrl &newUrl) - : QHttpNetworkHeaderPrivate(newUrl), operation(op), priority(pri), uploadByteDevice(0), + : QHttpNetworkHeaderPrivate(newUrl), operation(op), priority(pri), uploadByteDevice(nullptr), autoDecompress(false), pipeliningAllowed(false), spdyAllowed(false), http2Allowed(false), http2Direct(false), withCredentials(true), preConnect(false), redirectCount(0), redirectPolicy(QNetworkRequest::ManualRedirectPolicy) diff --git a/src/network/access/qhttpprotocolhandler.cpp b/src/network/access/qhttpprotocolhandler.cpp index edcbdcbe0e..981effb54f 100644 --- a/src/network/access/qhttpprotocolhandler.cpp +++ b/src/network/access/qhttpprotocolhandler.cpp @@ -233,7 +233,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(m_socket->socketError()); // We still need to handle the reply so it emits its signals etc. if (m_reply) _q_receiveReply(); @@ -278,7 +278,7 @@ bool QHttpProtocolHandler::sendRequest() m_reply->d_func()->state = QHttpNetworkReplyPrivate::AllDoneState; m_channel->allDone(); m_connection->preConnectFinished(); // will only decrease the counter - m_reply = 0; // so we can reuse this channel + m_reply = nullptr; // so we can reuse this channel return true; // we have a working connection and are done } @@ -373,7 +373,7 @@ bool QHttpProtocolHandler::sendRequest() // premature eof happened m_connection->d_func()->emitReplyError(m_socket, m_reply, QNetworkReply::UnknownNetworkError); return false; - } else if (readPointer == 0 || currentReadSize == 0) { + } else if (readPointer == nullptr || currentReadSize == 0) { // nothing to read currently, break the loop break; } else { diff --git a/src/network/access/qhttpthreaddelegate.cpp b/src/network/access/qhttpthreaddelegate.cpp index 63a3c4f204..f3125a3a95 100644 --- a/src/network/access/qhttpthreaddelegate.cpp +++ b/src/network/access/qhttpthreaddelegate.cpp @@ -189,7 +189,7 @@ public: QNetworkAccessCachedHttpConnection(const QString &hostName, quint16 port, bool encrypt, QHttpNetworkConnection::ConnectionType connectionType, QSharedPointer<QNetworkSession> networkSession) - : QHttpNetworkConnection(hostName, port, encrypt, connectionType, /*parent=*/0, + : QHttpNetworkConnection(hostName, port, encrypt, connectionType, /*parent=*/nullptr, std::move(networkSession)) #endif { @@ -241,9 +241,9 @@ QHttpThreadDelegate::QHttpThreadDelegate(QObject *parent) : , removedContentLength(-1) , incomingErrorCode(QNetworkReply::NoError) , downloadBuffer() - , httpConnection(0) - , httpReply(0) - , synchronousRequestLoop(0) + , httpConnection(nullptr) + , httpReply(nullptr) + , synchronousRequestLoop(nullptr) { } @@ -439,7 +439,7 @@ void QHttpThreadDelegate::abortRequest() if (httpReply) { httpReply->abort(); delete httpReply; - httpReply = 0; + httpReply = nullptr; } // Got aborted by the timeout timer @@ -545,7 +545,7 @@ void QHttpThreadDelegate::finishedSlot() QMetaObject::invokeMethod(httpReply, "deleteLater", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection); - httpReply = 0; + httpReply = nullptr; } void QHttpThreadDelegate::synchronousFinishedSlot() @@ -568,7 +568,7 @@ void QHttpThreadDelegate::synchronousFinishedSlot() QMetaObject::invokeMethod(httpReply, "deleteLater", Qt::QueuedConnection); QMetaObject::invokeMethod(synchronousRequestLoop, "quit", Qt::QueuedConnection); - httpReply = 0; + httpReply = nullptr; } void QHttpThreadDelegate::finishedWithErrorSlot(QNetworkReply::NetworkError errorCode, const QString &detail) @@ -590,7 +590,7 @@ void QHttpThreadDelegate::finishedWithErrorSlot(QNetworkReply::NetworkError erro QMetaObject::invokeMethod(httpReply, "deleteLater", Qt::QueuedConnection); QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection); - httpReply = 0; + httpReply = nullptr; } @@ -609,7 +609,7 @@ void QHttpThreadDelegate::synchronousFinishedWithErrorSlot(QNetworkReply::Networ QMetaObject::invokeMethod(httpReply, "deleteLater", Qt::QueuedConnection); QMetaObject::invokeMethod(synchronousRequestLoop, "quit", Qt::QueuedConnection); - httpReply = 0; + httpReply = nullptr; } static void downloadBufferDeleter(char *ptr) diff --git a/src/network/access/qnetworkaccessauthenticationmanager.cpp b/src/network/access/qnetworkaccessauthenticationmanager.cpp index b661cc45b3..0df11684b1 100644 --- a/src/network/access/qnetworkaccessauthenticationmanager.cpp +++ b/src/network/access/qnetworkaccessauthenticationmanager.cpp @@ -71,7 +71,7 @@ public: if (it == end() && !isEmpty()) --it; if (it == end() || !domain.startsWith(it->domain)) - return 0; + return nullptr; return &*it; } diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp index 566e410051..8f42f3690b 100644 --- a/src/network/access/qnetworkaccessbackend.cpp +++ b/src/network/access/qnetworkaccessbackend.cpp @@ -105,7 +105,7 @@ QNetworkAccessBackend *QNetworkAccessManagerPrivate::findBackend(QNetworkAccessM ++it; } } - return 0; + return nullptr; } QStringList QNetworkAccessManagerPrivate::backendSupportedSchemes() const @@ -131,7 +131,7 @@ QNonContiguousByteDevice* QNetworkAccessBackend::createUploadByteDevice() else if (reply->outgoingData) { uploadByteDevice = QNonContiguousByteDeviceFactory::createShared(reply->outgoingData); } else { - return 0; + return nullptr; } // We want signal emissions only for normal asynchronous uploads @@ -151,8 +151,8 @@ void QNetworkAccessBackend::emitReplyUploadProgress(qint64 bytesSent, qint64 byt } QNetworkAccessBackend::QNetworkAccessBackend() - : manager(0) - , reply(0) + : manager(nullptr) + , reply(nullptr) , synchronous(false) { } @@ -223,7 +223,7 @@ QList<QNetworkProxy> QNetworkAccessBackend::proxyList() const QAbstractNetworkCache *QNetworkAccessBackend::networkCache() const { if (!manager) - return 0; + return nullptr; return manager->networkCache; } diff --git a/src/network/access/qnetworkaccesscache.cpp b/src/network/access/qnetworkaccesscache.cpp index b694a2c999..ba092f2618 100644 --- a/src/network/access/qnetworkaccesscache.cpp +++ b/src/network/access/qnetworkaccesscache.cpp @@ -73,7 +73,7 @@ struct QNetworkAccessCache::Node int useCount; Node() - : older(0), newer(0), object(0), useCount(0) + : older(nullptr), newer(nullptr), object(nullptr), useCount(0) { } }; @@ -103,7 +103,7 @@ void QNetworkAccessCache::CacheableObject::setShareable(bool enable) } QNetworkAccessCache::QNetworkAccessCache() - : oldest(0), newest(0) + : oldest(nullptr), newest(nullptr) { } @@ -130,7 +130,7 @@ void QNetworkAccessCache::clear() timer.stop(); - oldest = newest = 0; + oldest = newest = nullptr; } /*! @@ -145,11 +145,11 @@ void QNetworkAccessCache::linkEntry(const QByteArray &key) Node *const node = &it.value(); Q_ASSERT(node != oldest && node != newest); - Q_ASSERT(node->older == 0 && node->newer == 0); + Q_ASSERT(node->older == nullptr && node->newer == nullptr); Q_ASSERT(node->useCount == 0); if (newest) { - Q_ASSERT(newest->newer == 0); + Q_ASSERT(newest->newer == nullptr); newest->newer = node; node->older = newest; } @@ -186,7 +186,7 @@ bool QNetworkAccessCache::unlinkEntry(const QByteArray &key) if (node->newer) node->newer->older = node->older; - node->newer = node->older = 0; + node->newer = node->older = nullptr; return wasOldest; } @@ -235,9 +235,9 @@ void QNetworkAccessCache::timerEvent(QTimerEvent *) // fixup the list if (oldest) - oldest->older = 0; + oldest->older = nullptr; else - newest = 0; + newest = nullptr; updateTimer(); } @@ -277,7 +277,7 @@ bool QNetworkAccessCache::requestEntry(const QByteArray &key, QObject *target, c if (node->useCount > 0 && !node->object->shareable) { // object is not shareable and is in use // queue for later use - Q_ASSERT(node->older == 0 && node->newer == 0); + Q_ASSERT(node->older == nullptr && node->newer == nullptr); node->receiverQueue.push_back({target, member}); // request queued @@ -296,7 +296,7 @@ QNetworkAccessCache::CacheableObject *QNetworkAccessCache::requestEntryNow(const { NodeHash::Iterator it = hash.find(key); if (it == hash.end()) - return 0; + return nullptr; if (it->useCount > 0) { if (it->object->shareable) { ++it->useCount; @@ -304,7 +304,7 @@ QNetworkAccessCache::CacheableObject *QNetworkAccessCache::requestEntryNow(const } // object in use and not shareable - return 0; + return nullptr; } // entry not in use, let the caller have it diff --git a/src/network/access/qnetworkaccessdebugpipebackend.cpp b/src/network/access/qnetworkaccessdebugpipebackend.cpp index 67a856506c..0406f2fac1 100644 --- a/src/network/access/qnetworkaccessdebugpipebackend.cpp +++ b/src/network/access/qnetworkaccessdebugpipebackend.cpp @@ -70,13 +70,13 @@ QNetworkAccessDebugPipeBackendFactory::create(QNetworkAccessManager::Operation o default: // no, we can't handle this operation - return 0; + return nullptr; } QUrl url = request.url(); if (url.scheme() == QLatin1String("debugpipe")) return new QNetworkAccessDebugPipeBackend; - return 0; + return nullptr; } QNetworkAccessDebugPipeBackend::QNetworkAccessDebugPipeBackend() @@ -188,7 +188,7 @@ void QNetworkAccessDebugPipeBackend::pushFromUpstreamToSocket() emitReplyUploadProgress(bytesUploaded, bytesUploaded); possiblyFinish(); break; - } else if (haveRead == 0 || readPointer == 0) { + } else if (haveRead == 0 || readPointer == nullptr) { // nothing to read right now, we will be called again later break; } else { @@ -242,9 +242,9 @@ void QNetworkAccessDebugPipeBackend::closeDownstreamChannel() void QNetworkAccessDebugPipeBackend::socketError() { - qWarning("QNetworkAccessDebugPipeBackend::socketError() %d",socket.error()); + qWarning("QNetworkAccessDebugPipeBackend::socketError() %d",socket.socketError()); QNetworkReply::NetworkError code; - switch (socket.error()) { + switch (socket.socketError()) { case QAbstractSocket::RemoteHostClosedError: return; // socketDisconnected will be called diff --git a/src/network/access/qnetworkaccessfilebackend.cpp b/src/network/access/qnetworkaccessfilebackend.cpp index 60353cb03e..507417f86c 100644 --- a/src/network/access/qnetworkaccessfilebackend.cpp +++ b/src/network/access/qnetworkaccessfilebackend.cpp @@ -73,7 +73,7 @@ QNetworkAccessFileBackendFactory::create(QNetworkAccessManager::Operation op, default: // no, we can't handle this operation - return 0; + return nullptr; } QUrl url = request.url(); @@ -95,7 +95,7 @@ QNetworkAccessFileBackendFactory::create(QNetworkAccessManager::Operation op, return new QNetworkAccessFileBackend; } - return 0; + return nullptr; } QNetworkAccessFileBackend::QNetworkAccessFileBackend() @@ -198,7 +198,7 @@ void QNetworkAccessFileBackend::uploadReadyReadSlot() file.close(); finished(); break; - } else if (haveRead == 0 || readPointer == 0) { + } else if (haveRead == 0 || readPointer == nullptr) { // nothing to read right now, we will be called again later break; } else { diff --git a/src/network/access/qnetworkaccessftpbackend.cpp b/src/network/access/qnetworkaccessftpbackend.cpp index 51ed2f5a55..fb8cd79c12 100644 --- a/src/network/access/qnetworkaccessftpbackend.cpp +++ b/src/network/access/qnetworkaccessftpbackend.cpp @@ -75,13 +75,13 @@ QNetworkAccessFtpBackendFactory::create(QNetworkAccessManager::Operation op, default: // no, we can't handle this operation - return 0; + return nullptr; } QUrl url = request.url(); if (url.scheme().compare(QLatin1String("ftp"), Qt::CaseInsensitive) == 0) return new QNetworkAccessFtpBackend; - return 0; + return nullptr; } class QNetworkAccessCachedFtpConnection: public QFtp, public QNetworkAccessCache::CacheableObject @@ -104,7 +104,7 @@ public: }; QNetworkAccessFtpBackend::QNetworkAccessFtpBackend() - : ftp(0), uploadDevice(0), totalBytes(0), helpId(-1), sizeId(-1), mdtmId(-1), pwdId(-1), + : ftp(nullptr), uploadDevice(nullptr), totalBytes(0), helpId(-1), sizeId(-1), mdtmId(-1), pwdId(-1), supportsSize(false), supportsMdtm(false), supportsPwd(false), state(Idle) { } @@ -215,7 +215,7 @@ void QNetworkAccessFtpBackend::disconnectFromFtp(CacheCleanupMode mode) state = Disconnecting; if (ftp) { - disconnect(ftp, 0, this, 0); + disconnect(ftp, nullptr, this, nullptr); QByteArray key = makeCacheKey(url()); if (mode == RemoveCachedConnection) { @@ -225,7 +225,7 @@ void QNetworkAccessFtpBackend::disconnectFromFtp(CacheCleanupMode mode) QNetworkAccessManagerPrivate::getObjectCache(this)->releaseEntry(key); } - ftp = 0; + ftp = nullptr; } } @@ -362,7 +362,7 @@ void QNetworkAccessFtpBackend::ftpDone() QFtp::TransferType type = QFtp::Binary; if (operation() == QNetworkAccessManager::GetOperation) { setCachingEnabled(true); - ftp->get(url().path(), 0, type); + ftp->get(url().path(), nullptr, type); } else { ftp->put(uploadDevice, url().path(), type); } diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 76b95b5823..ff916ff283 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -1240,7 +1240,7 @@ void QNetworkAccessManager::connectToHostEncrypted(const QString &hostName, quin // There is no way to enable SPDY/HTTP2 via a request, so we need to check // the ssl configuration whether SPDY/HTTP2 is allowed here. if (sslConfiguration.allowedNextProtocols().contains(QSslConfiguration::ALPNProtocolHTTP2)) - request.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true); + request.setAttribute(QNetworkRequest::Http2AllowedAttribute, true); else if (sslConfiguration.allowedNextProtocols().contains(QSslConfiguration::NextProtocolSpdy3_0)) request.setAttribute(QNetworkRequest::SpdyAllowedAttribute, true); @@ -1404,6 +1404,11 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera req.setAttribute(QNetworkRequest::RedirectPolicyAttribute, redirectPolicy()); } +#if QT_CONFIG(http) + if (!req.transferTimeout()) + req.setTransferTimeout(transferTimeout()); +#endif + if (autoDeleteReplies() && req.attribute(QNetworkRequest::AutoDeleteReplyOnFinishAttribute).isNull()) { req.setAttribute(QNetworkRequest::AutoDeleteReplyOnFinishAttribute, true); @@ -1713,6 +1718,41 @@ void QNetworkAccessManager::setAutoDeleteReplies(bool shouldAutoDelete) d_func()->autoDeleteReplies = shouldAutoDelete; } +/*! + \since 5.15 + + Returns the timeout used for transfers, in milliseconds. + + This timeout is zero if setTransferTimeout() hasn't been + called, which means that the timeout is not used. +*/ +int QNetworkAccessManager::transferTimeout() const +{ + return d_func()->transferTimeout; +} + +/*! + \since 5.15 + + Sets \a timeout as the transfer timeout in milliseconds. + + Transfers are aborted if no bytes are transferred before + the timeout expires. Zero means no timer is set. If no + argument is provided, the timeout is + QNetworkRequest::TransferTimeoutPreset. If this function + is not called, the timeout is disabled and has the + value zero. The request-specific non-zero timeouts set for + the requests that are executed override this value. This means + that if QNetworkAccessManager has an enabled timeout, it needs + to be disabled to execute a request without a timeout. + + \sa transferTimeout() +*/ +void QNetworkAccessManager::setTransferTimeout(int timeout) +{ + d_func()->transferTimeout = timeout; +} + void QNetworkAccessManagerPrivate::_q_replyFinished() { Q_Q(QNetworkAccessManager); @@ -1941,7 +1981,7 @@ void QNetworkAccessManagerPrivate::destroyThread() { if (thread) { thread->quit(); - thread->wait(5000); + thread->wait(QDeadlineTimer(5000)); if (thread->isFinished()) delete thread; else diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h index 98498d07d2..aa4765a043 100644 --- a/src/network/access/qnetworkaccessmanager.h +++ b/src/network/access/qnetworkaccessmanager.h @@ -170,6 +170,9 @@ public: bool autoDeleteReplies() const; void setAutoDeleteReplies(bool autoDelete); + int transferTimeout() const; + void setTransferTimeout(int timeout = QNetworkRequest::TransferTimeoutPreset); + Q_SIGNALS: #ifndef QT_NO_NETWORKPROXY void proxyAuthenticationRequired(const QNetworkProxy &proxy, QAuthenticator *authenticator); diff --git a/src/network/access/qnetworkaccessmanager_p.h b/src/network/access/qnetworkaccessmanager_p.h index 67ea2094b3..d558f61eed 100644 --- a/src/network/access/qnetworkaccessmanager_p.h +++ b/src/network/access/qnetworkaccessmanager_p.h @@ -229,6 +229,8 @@ public: bool autoDeleteReplies = false; + int transferTimeout = 0; + #ifndef QT_NO_BEARERMANAGEMENT Q_AUTOTEST_EXPORT static const QWeakPointer<const QNetworkSession> getNetworkSession(const QNetworkAccessManager *manager); #endif diff --git a/src/network/access/qnetworkcookie.cpp b/src/network/access/qnetworkcookie.cpp index 903de322ff..47f6112b22 100644 --- a/src/network/access/qnetworkcookie.cpp +++ b/src/network/access/qnetworkcookie.cpp @@ -131,7 +131,7 @@ QNetworkCookie::QNetworkCookie(const QNetworkCookie &other) QNetworkCookie::~QNetworkCookie() { // QSharedDataPointer auto deletes - d = 0; + d = nullptr; } /*! diff --git a/src/network/access/qnetworkdiskcache.cpp b/src/network/access/qnetworkdiskcache.cpp index df2e4902a4..b30d1c9664 100644 --- a/src/network/access/qnetworkdiskcache.cpp +++ b/src/network/access/qnetworkdiskcache.cpp @@ -180,11 +180,11 @@ QIODevice *QNetworkDiskCache::prepare(const QNetworkCacheMetaData &metaData) #endif Q_D(QNetworkDiskCache); if (!metaData.isValid() || !metaData.url().isValid() || !metaData.saveToDisk()) - return 0; + return nullptr; if (d->cacheDirectory.isEmpty()) { qWarning("QNetworkDiskCache::prepare() The cache directory is not set"); - return 0; + return nullptr; } const auto headers = metaData.rawHeaders(); @@ -192,14 +192,14 @@ QIODevice *QNetworkDiskCache::prepare(const QNetworkCacheMetaData &metaData) if (header.first.compare("content-length", Qt::CaseInsensitive) == 0) { const qint64 size = header.second.toLongLong(); if (size > (maximumCacheSize() * 3)/4) - return 0; + return nullptr; break; } } QScopedPointer<QCacheItem> cacheItem(new QCacheItem); cacheItem->metaData = metaData; - QIODevice *device = 0; + QIODevice *device = nullptr; if (cacheItem->canCompress()) { cacheItem->data.open(QBuffer::ReadWrite); device = &(cacheItem->data); @@ -208,12 +208,12 @@ QIODevice *QNetworkDiskCache::prepare(const QNetworkCacheMetaData &metaData) QT_TRY { cacheItem->file = new QTemporaryFile(templateName, &cacheItem->data); } QT_CATCH(...) { - cacheItem->file = 0; + cacheItem->file = nullptr; } if (!cacheItem->file || !cacheItem->file->open()) { qWarning("QNetworkDiskCache::prepare() unable to open temporary file"); cacheItem.reset(); - return 0; + return nullptr; } cacheItem->writeHeader(cacheItem->file); device = cacheItem->file; @@ -397,19 +397,19 @@ QIODevice *QNetworkDiskCache::data(const QUrl &url) Q_D(QNetworkDiskCache); QScopedPointer<QBuffer> buffer; if (!url.isValid()) - return 0; + return nullptr; if (d->lastItem.metaData.url() == url && d->lastItem.data.isOpen()) { buffer.reset(new QBuffer); buffer->setData(d->lastItem.data.data()); } else { QScopedPointer<QFile> file(new QFile(d->cacheFileName(url))); if (!file->open(QFile::ReadOnly | QIODevice::Unbuffered)) - return 0; + return nullptr; if (!d->lastItem.read(file.data(), true)) { file->close(); remove(url); - return 0; + return nullptr; } if (d->lastItem.data.isOpen()) { // compressed @@ -419,7 +419,7 @@ QIODevice *QNetworkDiskCache::data(const QUrl &url) buffer.reset(new QBuffer); // ### verify that QFile uses the fd size and not the file name qint64 size = file->size() - file->pos(); - const uchar *p = 0; + const uchar *p = nullptr; #if !defined(Q_OS_INTEGRITY) p = file->map(file->pos(), size); #endif @@ -557,7 +557,7 @@ qint64 QNetworkDiskCache::expire() for (QCacheItem *item : qAsConst(d->inserting)) { if (item && item->file && item->file->fileName() == name) { delete item->file; - item->file = 0; + item->file = nullptr; break; } } diff --git a/src/network/access/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp index fb30bfd4f1..c22dce8f1c 100644 --- a/src/network/access/qnetworkreply.cpp +++ b/src/network/access/qnetworkreply.cpp @@ -554,14 +554,33 @@ QNetworkAccessManager::Operation QNetworkReply::operation() const return d_func()->operation; } +#if QT_DEPRECATED_SINCE(5, 15) /*! + \deprecated + + Use networkError() instead. + Returns the error that was found during the processing of this request. If no error was found, returns NoError. - \sa setError() + \sa setError(), networkError() */ QNetworkReply::NetworkError QNetworkReply::error() const { + return networkError(); +} +#endif // QT_DEPRECATED_SINCE(5, 15) + +/*! + \since 5.15 + + Returns the error that was found during the processing of this + request. If no error was found, returns NoError. + + \sa setError() +*/ +QNetworkReply::NetworkError QNetworkReply::networkError() const +{ return d_func()->errorCode; } @@ -858,7 +877,7 @@ void QNetworkReply::setRequest(const QNetworkRequest &request) Calling setError() does not emit the error(QNetworkReply::NetworkError) signal. - \sa error(), errorString() + \sa error(), errorString(), networkError() */ void QNetworkReply::setError(NetworkError errorCode, const QString &errorString) { diff --git a/src/network/access/qnetworkreply.h b/src/network/access/qnetworkreply.h index 4a402daa91..139009a56a 100644 --- a/src/network/access/qnetworkreply.h +++ b/src/network/access/qnetworkreply.h @@ -124,7 +124,12 @@ public: QNetworkAccessManager *manager() const; QNetworkAccessManager::Operation operation() const; QNetworkRequest request() const; - NetworkError error() const; + +#if QT_DEPRECATED_SINCE(5, 15) + QT_DEPRECATED_X("Use networkError()") NetworkError error() const; +#endif // QT_DEPRECATED_SINCE(5, 15) + NetworkError networkError() const; + bool isFinished() const; bool isRunning() const; QUrl url() const; diff --git a/src/network/access/qnetworkreplyfileimpl.cpp b/src/network/access/qnetworkreplyfileimpl.cpp index ef319ebf0d..afab8ffd94 100644 --- a/src/network/access/qnetworkreplyfileimpl.cpp +++ b/src/network/access/qnetworkreplyfileimpl.cpp @@ -50,7 +50,7 @@ QT_BEGIN_NAMESPACE QNetworkReplyFileImplPrivate::QNetworkReplyFileImplPrivate() - : QNetworkReplyPrivate(), managerPrivate(0), realFile(0) + : QNetworkReplyPrivate(), managerPrivate(nullptr), realFile(nullptr) { qRegisterMetaType<QNetworkRequest::KnownHeaders>(); qRegisterMetaType<QNetworkReply::NetworkError>(); diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 8ac81d1780..5a775142b0 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -461,6 +461,7 @@ QNetworkReplyHttpImplPrivate::QNetworkReplyHttpImplPrivate() , preMigrationDownloaded(-1) , bytesDownloaded(0) , bytesBuffered(0) + , transferTimeout(nullptr) , downloadBufferReadPosition(0) , downloadBufferCurrentSize(0) , downloadZerocopyBuffer(nullptr) @@ -692,7 +693,7 @@ void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpReq auto redirectPolicy = QNetworkRequest::ManualRedirectPolicy; const QVariant value = newHttpRequest.attribute(QNetworkRequest::RedirectPolicyAttribute); if (value.isValid()) - redirectPolicy = value.value<QNetworkRequest::RedirectPolicy>(); + redirectPolicy = qvariant_cast<QNetworkRequest::RedirectPolicy>(value); else if (newHttpRequest.attribute(QNetworkRequest::FollowRedirectsAttribute).toBool()) redirectPolicy = QNetworkRequest::NoLessSafeRedirectPolicy; @@ -777,7 +778,7 @@ void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpReq if (request.attribute(QNetworkRequest::SpdyAllowedAttribute).toBool()) httpRequest.setSPDYAllowed(true); - if (request.attribute(QNetworkRequest::HTTP2AllowedAttribute).toBool()) + if (request.attribute(QNetworkRequest::Http2AllowedAttribute).toBool()) httpRequest.setHTTP2Allowed(true); if (request.attribute(QNetworkRequest::Http2DirectAttribute).toBool()) { @@ -985,7 +986,7 @@ void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpReq } thread->quit(); - thread->wait(5000); + thread->wait(QDeadlineTimer(5000)); if (thread->isFinished()) delete thread; else @@ -1067,6 +1068,7 @@ void QNetworkReplyHttpImplPrivate::replyDownloadData(QByteArray d) if (!isHttpRedirectResponse()) { buffer.append(d); bytesDownloaded += d.size(); + setupTransferTimeout(); } bytesBuffered += d.size(); @@ -1280,15 +1282,15 @@ void QNetworkReplyHttpImplPrivate::replyDownloadMetaData(const QList<QPair<QByte } q->setAttribute(QNetworkRequest::HttpPipeliningWasUsedAttribute, pu); - const QVariant http2Allowed = request.attribute(QNetworkRequest::HTTP2AllowedAttribute); + const QVariant http2Allowed = request.attribute(QNetworkRequest::Http2AllowedAttribute); const QVariant http2Direct = request.attribute(QNetworkRequest::Http2DirectAttribute); if ((http2Allowed.isValid() && http2Allowed.toBool()) || (http2Direct.isValid() && http2Direct.toBool())) { - q->setAttribute(QNetworkRequest::HTTP2WasUsedAttribute, spdyWasUsed); + q->setAttribute(QNetworkRequest::Http2WasUsedAttribute, spdyWasUsed); q->setAttribute(QNetworkRequest::SpdyWasUsedAttribute, false); } else { q->setAttribute(QNetworkRequest::SpdyWasUsedAttribute, spdyWasUsed); - q->setAttribute(QNetworkRequest::HTTP2WasUsedAttribute, false); + q->setAttribute(QNetworkRequest::Http2WasUsedAttribute, false); } // reconstruct the HTTP header @@ -1401,6 +1403,7 @@ void QNetworkReplyHttpImplPrivate::replyDownloadProgressSlot(qint64 bytesReceive return; bytesDownloaded = bytesReceived; + setupTransferTimeout(); downloadBufferCurrentSize = bytesReceived; @@ -1857,7 +1860,6 @@ bool QNetworkReplyHttpImplPrivate::startWaitForSession(QSharedPointer<QNetworkSe void QNetworkReplyHttpImplPrivate::_q_startOperation() { Q_Q(QNetworkReplyHttpImpl); - if (state == Working) // ensure this function is only being called once return; @@ -1897,6 +1899,7 @@ void QNetworkReplyHttpImplPrivate::_q_startOperation() } #endif // QT_NO_BEARERMANAGEMENT + setupTransferTimeout(); if (synchronous) { state = Finished; q_func()->setFinished(true); @@ -2033,6 +2036,31 @@ void QNetworkReplyHttpImplPrivate::_q_bufferOutgoingData() } } +void QNetworkReplyHttpImplPrivate::_q_transferTimedOut() +{ + Q_Q(QNetworkReplyHttpImpl); + q->abort(); +} + +void QNetworkReplyHttpImplPrivate::setupTransferTimeout() +{ + Q_Q(QNetworkReplyHttpImpl); + if (!transferTimeout) { + transferTimeout = new QTimer(q); + QObject::connect(transferTimeout, SIGNAL(timeout()), + q, SLOT(_q_transferTimedOut()), + Qt::QueuedConnection); + } + transferTimeout->stop(); + if (request.transferTimeout()) { + transferTimeout->setSingleShot(true); + transferTimeout->setInterval(request.transferTimeout()); + QMetaObject::invokeMethod(transferTimeout, "start", + Qt::QueuedConnection); + + } +} + #ifndef QT_NO_BEARERMANAGEMENT void QNetworkReplyHttpImplPrivate::_q_networkSessionConnected() { @@ -2115,6 +2143,8 @@ void QNetworkReplyHttpImplPrivate::emitReplyUploadProgress(qint64 bytesSent, qin if (isFinished) return; + setupTransferTimeout(); + if (!emitAllUploadProgressSignals) { //choke signal emissions, except the first and last signals which are unconditional if (uploadProgressSignalChoke.isValid()) { @@ -2126,7 +2156,6 @@ void QNetworkReplyHttpImplPrivate::emitReplyUploadProgress(qint64 bytesSent, qin uploadProgressSignalChoke.start(); } } - emit q->uploadProgress(bytesSent, bytesTotal); } @@ -2159,7 +2188,8 @@ void QNetworkReplyHttpImplPrivate::_q_finished() void QNetworkReplyHttpImplPrivate::finished() { Q_Q(QNetworkReplyHttpImpl); - + if (transferTimeout) + transferTimeout->stop(); if (state == Finished || state == Aborted || state == WaitingForSession) return; diff --git a/src/network/access/qnetworkreplyhttpimpl_p.h b/src/network/access/qnetworkreplyhttpimpl_p.h index ef69ce0653..dec0c4c589 100644 --- a/src/network/access/qnetworkreplyhttpimpl_p.h +++ b/src/network/access/qnetworkreplyhttpimpl_p.h @@ -59,6 +59,7 @@ #include "QtCore/qdatetime.h" #include "QtCore/qsharedpointer.h" #include "QtCore/qscopedpointer.h" +#include "QtCore/qtimer.h" #include "qatomic.h" #include <QtNetwork/QNetworkCacheMetaData> @@ -100,6 +101,7 @@ public: Q_PRIVATE_SLOT(d_func(), void _q_cacheLoadReadyRead()) Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingData()) Q_PRIVATE_SLOT(d_func(), void _q_bufferOutgoingDataFinished()) + Q_PRIVATE_SLOT(d_func(), void _q_transferTimedOut()) #ifndef QT_NO_BEARERMANAGEMENT Q_PRIVATE_SLOT(d_func(), void _q_networkSessionConnected()) Q_PRIVATE_SLOT(d_func(), void _q_networkSessionFailed()) @@ -181,6 +183,9 @@ public: void _q_cacheSaveDeviceAboutToClose(); + void _q_transferTimedOut(); + void setupTransferTimeout(); + #ifndef QT_NO_BEARERMANAGEMENT void _q_networkSessionConnected(); void _q_networkSessionFailed(); @@ -250,6 +255,8 @@ public: qint64 bytesDownloaded; qint64 bytesBuffered; + QTimer *transferTimeout; + // Only used when the "zero copy" style is used. // Please note that the whole "zero copy" download buffer API is private right now. Do not use it. qint64 downloadBufferReadPosition; diff --git a/src/network/access/qnetworkreplyimpl.cpp b/src/network/access/qnetworkreplyimpl.cpp index 6eab500e8c..a43a29a239 100644 --- a/src/network/access/qnetworkreplyimpl.cpp +++ b/src/network/access/qnetworkreplyimpl.cpp @@ -53,9 +53,9 @@ QT_BEGIN_NAMESPACE inline QNetworkReplyImplPrivate::QNetworkReplyImplPrivate() - : backend(0), outgoingData(0), - copyDevice(0), - cacheEnabled(false), cacheSaveDevice(0), + : backend(nullptr), outgoingData(nullptr), + copyDevice(nullptr), + cacheEnabled(false), cacheSaveDevice(nullptr), notificationHandlingPaused(false), bytesDownloaded(0), lastBytesDownloaded(-1), bytesUploaded(-1), preMigrationDownloaded(-1), httpStatusCode(0), @@ -63,7 +63,7 @@ inline QNetworkReplyImplPrivate::QNetworkReplyImplPrivate() , downloadBufferReadPosition(0) , downloadBufferCurrentSize(0) , downloadBufferMaximumSize(0) - , downloadBuffer(0) + , downloadBuffer(nullptr) { if (request.attribute(QNetworkRequest::EmitAllUploadProgressSignalsAttribute).toBool() == true) emitAllUploadProgressSignals = true; @@ -489,7 +489,7 @@ void QNetworkReplyImplPrivate::resumeNotificationHandling() QAbstractNetworkCache *QNetworkReplyImplPrivate::networkCache() const { if (!backend) - return 0; + return nullptr; return backend->networkCache(); } @@ -504,7 +504,7 @@ void QNetworkReplyImplPrivate::createCache() bool QNetworkReplyImplPrivate::isCachingEnabled() const { - return (cacheEnabled && networkCache() != 0); + return (cacheEnabled && networkCache() != nullptr); } void QNetworkReplyImplPrivate::setCachingEnabled(bool enable) @@ -529,7 +529,7 @@ void QNetworkReplyImplPrivate::setCachingEnabled(bool enable) "backend %s probably needs to be fixed", backend->metaObject()->className()); networkCache()->remove(url); - cacheSaveDevice = 0; + cacheSaveDevice = nullptr; cacheEnabled = false; } } @@ -541,7 +541,7 @@ void QNetworkReplyImplPrivate::completeCacheSave() } else if (cacheEnabled && cacheSaveDevice) { networkCache()->insert(cacheSaveDevice); } - cacheSaveDevice = 0; + cacheSaveDevice = nullptr; cacheEnabled = false; } @@ -610,7 +610,7 @@ void QNetworkReplyImplPrivate::initCacheSaveDevice() networkCache()->metaObject()->className()); networkCache()->remove(url); - cacheSaveDevice = 0; + cacheSaveDevice = nullptr; cacheEnabled = false; } } @@ -927,9 +927,9 @@ void QNetworkReplyImpl::abort() // stop both upload and download if (d->outgoingData) - disconnect(d->outgoingData, 0, this, 0); + disconnect(d->outgoingData, nullptr, this, nullptr); if (d->copyDevice) - disconnect(d->copyDevice, 0, this, 0); + disconnect(d->copyDevice, nullptr, this, nullptr); QNetworkReply::close(); @@ -943,7 +943,7 @@ void QNetworkReplyImpl::abort() // finished may access the backend if (d->backend) { d->backend->deleteLater(); - d->backend = 0; + d->backend = nullptr; } } @@ -958,7 +958,7 @@ void QNetworkReplyImpl::close() if (d->backend) d->backend->closeDownstreamChannel(); if (d->copyDevice) - disconnect(d->copyDevice, 0, this, 0); + disconnect(d->copyDevice, nullptr, this, nullptr); QNetworkReply::close(); diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index 118fb6b1fb..70b09dba22 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -277,23 +277,30 @@ QT_BEGIN_NAMESPACE Indicates whether the QNetworkAccessManager code is allowed to use SPDY with this request. This applies only to SSL requests, and depends on the server supporting SPDY. + Obsolete, use Http2 instead of Spdy. \value SpdyWasUsedAttribute Replies only, type: QMetaType::Bool Indicates whether SPDY was used for receiving - this reply. + this reply. Obsolete, use Http2 instead of Spdy. - \value HTTP2AllowedAttribute + \value Http2AllowedAttribute Requests only, type: QMetaType::Bool (default: false) Indicates whether the QNetworkAccessManager code is allowed to use HTTP/2 with this request. This applies to SSL requests or 'cleartext' HTTP/2. - \value HTTP2WasUsedAttribute + \value Http2WasUsedAttribute Replies only, type: QMetaType::Bool (default: false) Indicates whether HTTP/2 was used for receiving this reply. (This value was introduced in 5.9.) + \value HTTP2AllowedAttribute + Obsolete alias for Http2AllowedAttribute. + + \value HTTP2WasUsedAttribute + Obsolete alias for Http2WasUsedAttribute. + \value EmitAllUploadProgressSignalsAttribute Requests only, type: QMetaType::Bool (default: false) Indicates whether all upload signals should be emitted. @@ -329,7 +336,7 @@ QT_BEGIN_NAMESPACE server supports HTTP/2. The attribute works with SSL or 'cleartext' HTTP/2. If a server turns out to not support HTTP/2, when HTTP/2 direct was specified, QNetworkAccessManager gives up, without attempting to - fall back to HTTP/1.1. If both HTTP2AllowedAttribute and + fall back to HTTP/1.1. If both Http2AllowedAttribute and Http2DirectAttribute are set, Http2DirectAttribute takes priority. (This value was introduced in 5.11.) @@ -418,6 +425,18 @@ QT_BEGIN_NAMESPACE based on some app-specific configuration. */ +/*! + \enum QNetworkRequest::TransferTimeoutConstant + \since 5.15 + + A constant that can be used for enabling transfer + timeouts with a preset value. + + \value TransferTimeoutPreset The transfer timeout in milliseconds. + Used if setTimeout() is called + without an argument. + */ + class QNetworkRequestPrivate: public QSharedData, public QNetworkHeadersPrivate { public: @@ -425,9 +444,10 @@ public: inline QNetworkRequestPrivate() : priority(QNetworkRequest::NormalPriority) #ifndef QT_NO_SSL - , sslConfiguration(0) + , sslConfiguration(nullptr) #endif , maxRedirectsAllowed(maxRedirectCount) + , transferTimeout(0) { qRegisterMetaType<QNetworkRequest>(); } ~QNetworkRequestPrivate() { @@ -444,7 +464,7 @@ public: priority = other.priority; maxRedirectsAllowed = other.maxRedirectsAllowed; #ifndef QT_NO_SSL - sslConfiguration = 0; + sslConfiguration = nullptr; if (other.sslConfiguration) sslConfiguration = new QSslConfiguration(*other.sslConfiguration); #endif @@ -452,6 +472,7 @@ public: #if QT_CONFIG(http) h2Configuration = other.h2Configuration; #endif + transferTimeout = other.transferTimeout; } inline bool operator==(const QNetworkRequestPrivate &other) const @@ -465,6 +486,7 @@ public: #if QT_CONFIG(http) && h2Configuration == other.h2Configuration #endif + && transferTimeout == other.transferTimeout ; // don't compare cookedHeaders } @@ -479,6 +501,7 @@ public: #if QT_CONFIG(http) QHttp2Configuration h2Configuration; #endif + int transferTimeout; }; /*! @@ -527,7 +550,7 @@ QNetworkRequest::QNetworkRequest(const QNetworkRequest &other) QNetworkRequest::~QNetworkRequest() { // QSharedDataPointer auto deletes - d = 0; + d = nullptr; } /*! @@ -902,6 +925,40 @@ void QNetworkRequest::setHttp2Configuration(const QHttp2Configuration &configura { d->h2Configuration = configuration; } + +/*! + \since 5.15 + + Returns the timeout used for transfers, in milliseconds. + + This timeout is zero if setTransferTimeout hasn't been + called, which means that the timeout is not used. + + \sa setTransferTimeout +*/ +int QNetworkRequest::transferTimeout() const +{ + return d->transferTimeout; +} + +/*! + \since 5.15 + + Sets \a timeout as the transfer timeout in milliseconds. + + Transfers are aborted if no bytes are transferred before + the timeout expires. Zero means no timer is set. If no + argument is provided, the timeout is + QNetworkRequest::TransferTimeoutPreset. If this function + is not called, the timeout is disabled and has the + value zero. + + \sa transferTimeout +*/ +void QNetworkRequest::setTransferTimeout(int timeout) +{ + d->transferTimeout = timeout; +} #endif // QT_CONFIG(http) || defined(Q_CLANG_QDOC) static QByteArray headerName(QNetworkRequest::KnownHeaders header) diff --git a/src/network/access/qnetworkrequest.h b/src/network/access/qnetworkrequest.h index e09ff8aaae..dcd2c6b61f 100644 --- a/src/network/access/qnetworkrequest.h +++ b/src/network/access/qnetworkrequest.h @@ -89,12 +89,18 @@ public: DownloadBufferAttribute, // internal SynchronousRequestAttribute, // internal BackgroundRequestAttribute, +#if QT_DEPRECATED_SINCE(5, 15) SpdyAllowedAttribute, SpdyWasUsedAttribute, - EmitAllUploadProgressSignalsAttribute, +#endif // QT_DEPRECATED_SINCE(5, 15) + EmitAllUploadProgressSignalsAttribute = BackgroundRequestAttribute + 3, FollowRedirectsAttribute, - HTTP2AllowedAttribute, - HTTP2WasUsedAttribute, + Http2AllowedAttribute, + Http2WasUsedAttribute, +#if QT_DEPRECATED_SINCE(5, 15) + HTTP2AllowedAttribute Q_DECL_ENUMERATOR_DEPRECATED_X("Use Http2AllowedAttribute") = Http2AllowedAttribute, + HTTP2WasUsedAttribute Q_DECL_ENUMERATOR_DEPRECATED_X("Use Http2WasUsedAttribute"), +#endif // QT_DEPRECATED_SINCE(5, 15) OriginalContentLengthAttribute, RedirectPolicyAttribute, Http2DirectAttribute, @@ -128,6 +134,9 @@ public: UserVerifiedRedirectPolicy }; + enum TransferTimeoutConstant { + TransferTimeoutPreset = 30000 + }; QNetworkRequest(); explicit QNetworkRequest(const QUrl &url); @@ -179,6 +188,9 @@ public: #if QT_CONFIG(http) || defined(Q_CLANG_QDOC) QHttp2Configuration http2Configuration() const; void setHttp2Configuration(const QHttp2Configuration &configuration); + + int transferTimeout() const; + void setTransferTimeout(int timeout = TransferTimeoutPreset); #endif // QT_CONFIG(http) || defined(Q_CLANG_QDOC) private: QSharedDataPointer<QNetworkRequestPrivate> d; diff --git a/src/network/access/qspdyprotocolhandler.cpp b/src/network/access/qspdyprotocolhandler.cpp index f845235bf7..eef8df288d 100644 --- a/src/network/access/qspdyprotocolhandler.cpp +++ b/src/network/access/qspdyprotocolhandler.cpp @@ -254,7 +254,7 @@ static const char spdyDictionary[] = { //} QSpdyProtocolHandler::QSpdyProtocolHandler(QHttpNetworkConnectionChannel *channel) - : QObject(0), QAbstractProtocolHandler(channel), + : QObject(nullptr), QAbstractProtocolHandler(channel), m_nextStreamID(-1), m_maxConcurrentStreams(100), // 100 is recommended in the SPDY RFC m_initialWindowSize(0), @@ -613,7 +613,7 @@ void QSpdyProtocolHandler::sendSYN_STREAM(const HttpMessagePair &messagePair, QHttpNetworkRequest request = messagePair.first; QHttpNetworkReply *reply = messagePair.second; - ControlFrameFlags flags = 0; + ControlFrameFlags flags; if (!request.uploadByteDevice()) { // no upload -> this is the last frame, send the FIN flag @@ -675,14 +675,14 @@ void QSpdyProtocolHandler::sendRST_STREAM(qint32 streamID, RST_STREAM_STATUS_COD char wireData[8]; appendIntToFourBytes(wireData, streamID); appendIntToFourBytes(wireData + 4, statusCode); - sendControlFrame(FrameType_RST_STREAM, /* flags = */ 0, wireData, /* length = */ 8); + sendControlFrame(FrameType_RST_STREAM, /* flags = */ { }, wireData, /* length = */ 8); } void QSpdyProtocolHandler::sendPING(quint32 pingID) { char rawData[4]; appendIntToFourBytes(rawData, pingID); - sendControlFrame(FrameType_PING, /* flags = */ 0, rawData, /* length = */ 4); + sendControlFrame(FrameType_PING, /* flags = */ { }, rawData, /* length = */ 4); } bool QSpdyProtocolHandler::uploadData(qint32 streamID) @@ -720,11 +720,11 @@ bool QSpdyProtocolHandler::uploadData(qint32 streamID) m_connection->d_func()->emitReplyError(m_socket, reply, QNetworkReply::UnknownNetworkError); return false; - } else if (readPointer == 0 || currentReadSize == 0) { + } else if (readPointer == nullptr || currentReadSize == 0) { // nothing to read currently, break the loop break; } else { - DataFrameFlags flags = 0; + DataFrameFlags flags; // we will send the FIN flag later if appropriate qint64 currentWriteSize = sendDataFrame(streamID, flags, currentReadSize, readPointer); if (currentWriteSize == -1 || currentWriteSize != currentReadSize) { @@ -746,7 +746,7 @@ bool QSpdyProtocolHandler::uploadData(qint32 streamID) } if (replyPrivate->totallyUploadedData == request.contentLength()) { DataFrameFlags finFlag = DataFrame_FLAG_FIN; - qint64 writeSize = sendDataFrame(streamID, finFlag, 0, 0); + qint64 writeSize = sendDataFrame(streamID, finFlag, 0, nullptr); Q_ASSERT(writeSize == 0); Q_UNUSED(writeSize); // silence -Wunused-variable replyPrivate->state = QHttpNetworkReplyPrivate::SPDYHalfClosed; @@ -774,7 +774,7 @@ void QSpdyProtocolHandler::sendWINDOW_UPDATE(qint32 streamID, quint32 deltaWindo appendIntToFourBytes(windowUpdateData, streamID); appendIntToFourBytes(windowUpdateData + 4, deltaWindowSize); - sendControlFrame(FrameType_WINDOW_UPDATE, /* flags = */ 0, windowUpdateData, /* length = */ 8); + sendControlFrame(FrameType_WINDOW_UPDATE, /* flags = */ { }, windowUpdateData, /* length = */ 8); } qint64 QSpdyProtocolHandler::sendDataFrame(qint32 streamID, DataFrameFlags flags, @@ -892,7 +892,7 @@ void QSpdyProtocolHandler::parseHttpHeaders(char flags, const QByteArray &frameD HttpMessagePair pair = it.value(); QHttpNetworkReply *httpReply = pair.second; - Q_ASSERT(httpReply != 0); + Q_ASSERT(httpReply != nullptr); if (httpReply->d_func()->state == QHttpNetworkReplyPrivate::SPDYClosed) { sendRST_STREAM(streamID, RST_STREAM_STREAM_ALREADY_CLOSED); @@ -950,7 +950,7 @@ void QSpdyProtocolHandler::parseHttpHeaders(char flags, const QByteArray &frameD if (flag_fin) { if (httpReply->d_func()->state != QHttpNetworkReplyPrivate::SPDYHalfClosed) - sendDataFrame(streamID, DataFrame_FLAG_FIN, 0, 0); + sendDataFrame(streamID, DataFrame_FLAG_FIN, 0, nullptr); replyFinished(httpReply, streamID); } } @@ -1199,7 +1199,7 @@ void QSpdyProtocolHandler::handleDataFrame(const QByteArray &frameHeaders) HttpMessagePair pair = it.value(); QHttpNetworkRequest httpRequest = pair.first; QHttpNetworkReply *httpReply = pair.second; - Q_ASSERT(httpReply != 0); + Q_ASSERT(httpReply != nullptr); QHttpNetworkReplyPrivate *replyPrivate = httpReply->d_func(); @@ -1261,7 +1261,7 @@ void QSpdyProtocolHandler::handleDataFrame(const QByteArray &frameHeaders) if (flag_fin) { if (httpReply->d_func()->state != QHttpNetworkReplyPrivate::SPDYHalfClosed) - sendDataFrame(streamID, DataFrame_FLAG_FIN, 0, 0); + sendDataFrame(streamID, DataFrame_FLAG_FIN, 0, nullptr); replyFinished(httpReply, streamID); } } |