diff options
Diffstat (limited to 'src/network')
26 files changed, 748 insertions, 423 deletions
diff --git a/src/network/access/access.pri b/src/network/access/access.pri index 8a92308f12..cfb20dcd71 100644 --- a/src/network/access/access.pri +++ b/src/network/access/access.pri @@ -97,7 +97,8 @@ qtConfig(http) { access/qhttpnetworkrequest.cpp \ access/qhttpprotocolhandler.cpp \ access/qhttpthreaddelegate.cpp \ - access/qnetworkreplyhttpimpl.cpp + access/qnetworkreplyhttpimpl.cpp \ + access/qhttp2configuration.cpp HEADERS += \ access/qabstractprotocolhandler_p.h \ @@ -111,7 +112,8 @@ qtConfig(http) { access/qhttpnetworkrequest_p.h \ access/qhttpprotocolhandler_p.h \ access/qhttpthreaddelegate_p.h \ - access/qnetworkreplyhttpimpl_p.h + access/qnetworkreplyhttpimpl_p.h \ + access/qhttp2configuration.h qtConfig(ssl) { SOURCES += \ diff --git a/src/network/access/http2/hpack.cpp b/src/network/access/http2/hpack.cpp index 2d324d5092..b40cc29e1a 100644 --- a/src/network/access/http2/hpack.cpp +++ b/src/network/access/http2/hpack.cpp @@ -208,6 +208,11 @@ void Encoder::setMaxDynamicTableSize(quint32 size) lookupTable.setMaxDynamicTableSize(size); } +void Encoder::setCompressStrings(bool compress) +{ + compressStrings = compress; +} + bool Encoder::encodeRequestPseudoHeaders(BitOStream &outputStream, const HttpHeader &header) { diff --git a/src/network/access/http2/hpack_p.h b/src/network/access/http2/hpack_p.h index 6a1d30d87b..8c2701e7af 100644 --- a/src/network/access/http2/hpack_p.h +++ b/src/network/access/http2/hpack_p.h @@ -83,6 +83,7 @@ public: quint32 newSize); void setMaxDynamicTableSize(quint32 size); + void setCompressStrings(bool compress); private: bool encodeRequestPseudoHeaders(BitOStream &outputStream, diff --git a/src/network/access/http2/http2frames.cpp b/src/network/access/http2/http2frames.cpp index e695b4dd9e..ce33505683 100644 --- a/src/network/access/http2/http2frames.cpp +++ b/src/network/access/http2/http2frames.cpp @@ -305,7 +305,7 @@ FrameStatus FrameReader::read(QAbstractSocket &socket) return status; } - if (Http2PredefinedParameters::maxFrameSize < frame.payloadSize()) + if (Http2PredefinedParameters::maxPayloadSize < frame.payloadSize()) return FrameStatus::sizeError; frame.buffer.resize(frame.payloadSize() + frameHeaderSize); @@ -388,7 +388,7 @@ void FrameWriter::setPayloadSize(quint32 size) auto &buffer = frame.buffer; Q_ASSERT(buffer.size() >= frameHeaderSize); - Q_ASSERT(size < maxPayloadSize); + Q_ASSERT(size <= maxPayloadSize); buffer[0] = size >> 16; buffer[1] = size >> 8; diff --git a/src/network/access/http2/http2protocol.cpp b/src/network/access/http2/http2protocol.cpp index 0be72042c6..31da6fd616 100644 --- a/src/network/access/http2/http2protocol.cpp +++ b/src/network/access/http2/http2protocol.cpp @@ -43,6 +43,8 @@ #include "private/qhttpnetworkrequest_p.h" #include "private/qhttpnetworkreply_p.h" +#include <access/qhttp2configuration.h> + #include <QtCore/qbytearray.h> #include <QtCore/qstring.h> @@ -62,88 +64,29 @@ const char Http2clientPreface[clientPrefaceLength] = 0x2e, 0x30, 0x0d, 0x0a, 0x0d, 0x0a, 0x53, 0x4d, 0x0d, 0x0a, 0x0d, 0x0a}; -// TODO: (in 5.11) - remove it! -const char *http2ParametersPropertyName = "QT_HTTP2_PARAMETERS_PROPERTY"; - -ProtocolParameters::ProtocolParameters() -{ - settingsFrameData[Settings::INITIAL_WINDOW_SIZE_ID] = qtDefaultStreamReceiveWindowSize; - settingsFrameData[Settings::ENABLE_PUSH_ID] = 0; -} - -bool ProtocolParameters::validate() const +Frame configurationToSettingsFrame(const QHttp2Configuration &config) { - // 0. Huffman/indexing: any values are valid and allowed. - - // 1. Session receive window size (client side): HTTP/2 starts from the - // default value of 64Kb, if a client code tries to set lesser value, - // the delta would become negative, but this is not allowed. - if (maxSessionReceiveWindowSize < qint32(defaultSessionWindowSize)) { - qCWarning(QT_HTTP2, "Session receive window must be at least 65535 bytes"); - return false; - } - - // 2. HEADER_TABLE_SIZE: we do not validate HEADER_TABLE_SIZE, considering - // all values as valid. RFC 7540 and 7541 do not provide any lower/upper - // limits. If it's 0 - we do not index anything, if it's too huge - a user - // who provided such a value can potentially have a huge memory footprint, - // up to them to decide. - - // 3. SETTINGS_ENABLE_PUSH: RFC 7540, 6.5.2, a value other than 0 or 1 will - // be treated by our peer as a PROTOCOL_ERROR. - if (settingsFrameData.contains(Settings::ENABLE_PUSH_ID) - && settingsFrameData[Settings::ENABLE_PUSH_ID] > 1) { - qCWarning(QT_HTTP2, "SETTINGS_ENABLE_PUSH can be only 0 or 1"); - return false; - } - - // 4. SETTINGS_MAX_CONCURRENT_STREAMS : RFC 7540 recommends 100 as the lower - // limit, says nothing about the upper limit. The RFC allows 0, but this makes - // no sense to us at all: there is no way a user can change this later and - // we'll not be able to get any responses on such a connection. - if (settingsFrameData.contains(Settings::MAX_CONCURRENT_STREAMS_ID) - && !settingsFrameData[Settings::MAX_CONCURRENT_STREAMS_ID]) { - qCWarning(QT_HTTP2, "MAX_CONCURRENT_STREAMS must be a positive number"); - return false; - } - - // 5. SETTINGS_INITIAL_WINDOW_SIZE. - if (settingsFrameData.contains(Settings::INITIAL_WINDOW_SIZE_ID)) { - const quint32 value = settingsFrameData[Settings::INITIAL_WINDOW_SIZE_ID]; - // RFC 7540, 6.5.2 (the upper limit). The lower limit is our own - we send - // SETTINGS frame only once and will not be able to change this 0, thus - // we'll suspend all streams. - if (!value || value > quint32(maxSessionReceiveWindowSize)) { - qCWarning(QT_HTTP2, "INITIAL_WINDOW_SIZE must be in the range " - "(0, 2^31-1]"); - return false; - } - } - - // 6. SETTINGS_MAX_FRAME_SIZE: RFC 7540, 6.5.2, a value outside of the range - // [2^14-1, 2^24-1] will be treated by our peer as a PROTOCOL_ERROR. - if (settingsFrameData.contains(Settings::MAX_FRAME_SIZE_ID)) { - const quint32 value = settingsFrameData[Settings::INITIAL_WINDOW_SIZE_ID]; - if (value < maxFrameSize || value > maxPayloadSize) { - qCWarning(QT_HTTP2, "MAX_FRAME_SIZE must be in the range [2^14, 2^24-1]"); - return false; - } + // 6.5 SETTINGS + FrameWriter builder(FrameType::SETTINGS, FrameFlag::EMPTY, connectionStreamID); + // Server push: + builder.append(Settings::ENABLE_PUSH_ID); + builder.append(int(config.serverPushEnabled())); + // Stream receive window size: + builder.append(Settings::INITIAL_WINDOW_SIZE_ID); + builder.append(config.streamReceiveWindowSize()); + + if (config.maxFrameSize() != minPayloadLimit) { + builder.append(Settings::MAX_FRAME_SIZE_ID); + builder.append(config.maxFrameSize()); } - - // For SETTINGS_MAX_HEADER_LIST_SIZE RFC 7540 does not provide any specific - // numbers. It's clear, if a value is too small, no header can ever be sent - // by our peer at all. The default value is unlimited and we normally do not - // change this. - // - // Note: the size is calculated as the length of uncompressed (no HPACK) - // name + value + 32 bytes. - - return true; + // TODO: In future, if the need is proven, we can + // also send decoding table size and header list size. + // For now, defaults suffice. + return builder.outboundFrame(); } -QByteArray ProtocolParameters::settingsFrameToBase64() const +QByteArray settingsFrameToBase64(const Frame &frame) { - Frame frame(settingsFrame()); // SETTINGS frame's payload consists of pairs: // 2-byte-identifier | 4-byte-value == multiple of 6. Q_ASSERT(frame.payloadSize() && !(frame.payloadSize() % 6)); @@ -157,20 +100,7 @@ QByteArray ProtocolParameters::settingsFrameToBase64() const return wrapper.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals); } -Frame ProtocolParameters::settingsFrame() const -{ - // 6.5 SETTINGS - FrameWriter builder(FrameType::SETTINGS, FrameFlag::EMPTY, connectionStreamID); - for (auto it = settingsFrameData.cbegin(), end = settingsFrameData.cend(); - it != end; ++it) { - builder.append(it.key()); - builder.append(it.value()); - } - - return builder.outboundFrame(); -} - -void ProtocolParameters::addProtocolUpgradeHeaders(QHttpNetworkRequest *request) const +void appendProtocolUpgradeHeaders(const QHttp2Configuration &config, QHttpNetworkRequest *request) { Q_ASSERT(request); // RFC 2616, 14.10 @@ -184,8 +114,10 @@ void ProtocolParameters::addProtocolUpgradeHeaders(QHttpNetworkRequest *request) request->setHeaderField("Connection", value); // This we just (re)write. request->setHeaderField("Upgrade", "h2c"); + + const Frame frame(configurationToSettingsFrame(config)); // This we just (re)write. - request->setHeaderField("HTTP2-Settings", settingsFrameToBase64()); + request->setHeaderField("HTTP2-Settings", settingsFrameToBase64(frame)); } void qt_error(quint32 errorCode, QNetworkReply::NetworkError &error, diff --git a/src/network/access/http2/http2protocol_p.h b/src/network/access/http2/http2protocol_p.h index f7a89859d3..b0af5aa919 100644 --- a/src/network/access/http2/http2protocol_p.h +++ b/src/network/access/http2/http2protocol_p.h @@ -55,12 +55,14 @@ #include <QtCore/qloggingcategory.h> #include <QtCore/qmetatype.h> #include <QtCore/qglobal.h> +#include <QtCore/qmap.h> // Different HTTP/2 constants/values as defined by RFC 7540. QT_BEGIN_NAMESPACE class QHttpNetworkRequest; +class QHttp2Configuration; class QHttpNetworkReply; class QByteArray; class QString; @@ -118,13 +120,19 @@ enum Http2PredefinedParameters connectionStreamID = 0, // HTTP/2, 5.1.1 frameHeaderSize = 9, // HTTP/2, 4.1 - // It's our max frame size we send in SETTINGS frame, - // it's also the default one and we also use it to later - // validate incoming frames: - maxFrameSize = 16384, // HTTP/2 6.5.2 + // The initial allowed payload size. We would use it as an + // upper limit for a frame payload we send, until our peer + // updates us with a larger SETTINGS_MAX_FRAME_SIZE. - defaultSessionWindowSize = 65535, // HTTP/2 6.5.2 + // The initial maximum payload size that an HTTP/2 frame + // can contain is 16384. It's also the minimal size that + // can be advertised via 'SETTINGS' frames. A real frame + // can have a payload smaller than 16384. + minPayloadLimit = 16384, // HTTP/2 6.5.2 + // The maximum allowed payload size. maxPayloadSize = (1 << 24) - 1, // HTTP/2 6.5.2 + + defaultSessionWindowSize = 65535, // HTTP/2 6.5.2 // Using 1000 (rather arbitrarily), just to // impose *some* upper limit: maxPeerConcurrentStreams = 1000, @@ -145,46 +153,9 @@ const quint32 lastValidStreamID((quint32(1) << 31) - 1); // HTTP/2, 5.1.1 const qint32 maxSessionReceiveWindowSize((quint32(1) << 31) - 1); const qint32 qtDefaultStreamReceiveWindowSize = maxSessionReceiveWindowSize / maxConcurrentStreams; -// The class ProtocolParameters allows client code to customize HTTP/2 protocol -// handler, if needed. Normally, we use our own default parameters (see below). -// In 5.10 we can also use setProperty/property on a QNAM object to pass the -// non-default values to the protocol handler. In 5.11 this will probably become -// a public API. - -using RawSettings = QMap<Settings, quint32>; - -struct Q_AUTOTEST_EXPORT ProtocolParameters -{ - ProtocolParameters(); - - bool validate() const; - QByteArray settingsFrameToBase64() const; - struct Frame settingsFrame() const; - void addProtocolUpgradeHeaders(QHttpNetworkRequest *request) const; - - // HPACK: - // TODO: for now we ignore them (fix it for 5.11, would require changes in HPACK) - bool useHuffman = true; - bool indexStrings = true; - - // This parameter is not negotiated via SETTINGS frames, so we have it - // as a member and will convey it to our peer as a WINDOW_UPDATE frame: - qint32 maxSessionReceiveWindowSize = Http2::maxSessionReceiveWindowSize; - - // This is our default SETTINGS frame: - // - // SETTINGS_INITIAL_WINDOW_SIZE: (2^31 - 1) / 100 - // SETTINGS_ENABLE_PUSH: 0. - // - // Note, whenever we skip some value in our SETTINGS frame, our peer - // will assume the defaults recommended by RFC 7540, which in general - // are good enough, although we (and most browsers) prefer to work - // with larger window sizes. - RawSettings settingsFrameData; -}; - -// TODO: remove in 5.11 -extern const Q_AUTOTEST_EXPORT char *http2ParametersPropertyName; +struct Frame configurationToSettingsFrame(const QHttp2Configuration &configuration); +QByteArray settingsFrameToBase64(const Frame &settingsFrame); +void appendProtocolUpgradeHeaders(const QHttp2Configuration &configuration, QHttpNetworkRequest *request); extern const Q_AUTOTEST_EXPORT char Http2clientPreface[clientPrefaceLength]; @@ -233,6 +204,5 @@ Q_DECLARE_LOGGING_CATEGORY(QT_HTTP2) QT_END_NAMESPACE Q_DECLARE_METATYPE(Http2::Settings) -Q_DECLARE_METATYPE(Http2::ProtocolParameters) #endif diff --git a/src/network/access/qhttp2configuration.cpp b/src/network/access/qhttp2configuration.cpp new file mode 100644 index 0000000000..a32bccfd09 --- /dev/null +++ b/src/network/access/qhttp2configuration.cpp @@ -0,0 +1,312 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qhttp2configuration.h" + +#include "private/http2protocol_p.h" +#include "private/hpack_p.h" + +#include "qdebug.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QHttp2Configuration + \brief The QHttp2Configuration class controls HTTP/2 parameters and settings + \since 5.14 + + \reentrant + \inmodule QtNetwork + \ingroup network + \ingroup shared + + QHttp2Configuration controls HTTP/2 parameters and settings that + QNetworkAccessManager will use to send requests and process responses + when the HTTP/2 protocol is enabled. + + The HTTP/2 parameters that QHttp2Configuration currently supports include: + + \list + \li The session window size for connection-level flow control. + Will be sent to a remote peer when needed as 'WINDOW_UPDATE' + frames on the stream with an identifier 0. + \li The stream receiving window size for stream-level flow control. + Sent as 'SETTINGS_INITIAL_WINDOW_SIZE' parameter in the initial + SETTINGS frame and, when needed, 'WINDOW_UPDATE' frames will be + sent on streams that QNetworkAccessManager opens. + \li The maximum frame size. This parameter limits the maximum payload + a frame coming from the remote peer can have. Sent by QNetworkAccessManager + as 'SETTINGS_MAX_FRAME_SIZE' parameter in the initial 'SETTINGS' + frame. + \li The server push. Allows to enable or disable server push. Sent + as 'SETTINGS_ENABLE_PUSH' parameter in the initial 'SETTINGS' + frame. + \endlist + + The QHttp2Configuration class also controls if the header compression + algorithm (HPACK) is additionally using Huffman coding for string + compression. + + \note The configuration must be set before the first request + was sent to a given host (and thus an HTTP/2 session established). + + \note Details about flow control, server push and 'SETTINGS' + can be found in \l {https://httpwg.org/specs/rfc7540.html}{RFC 7540}. + Different modes and parameters of the HPACK compression algorithm + are described in \l {https://httpwg.org/specs/rfc7541.html}{RFC 7541}. + + \sa QNetworkRequest::setHttp2Configuration(), QNetworkRequest::http2Configuration(), QNetworkAccessManager +*/ + +class QHttp2ConfigurationPrivate : public QSharedData +{ +public: + unsigned sessionWindowSize = Http2::defaultSessionWindowSize; + // The size below is quite a limiting default value, QNetworkRequest + // by default sets a larger number, an application can change this using + // QNetworkRequest::setHttp2Configuration. + unsigned streamWindowSize = Http2::defaultSessionWindowSize; + + unsigned maxFrameSize = Http2::minPayloadLimit; // Initial (default) value of 16Kb. + + bool pushEnabled = false; + // TODO: for now those two below are noop. + bool huffmanCompressionEnabled = true; +}; + +/*! + Default constructs a QHttp2Configuration object. + + Such a configuration has the following values: + \list + \li Server push is disabled + \li Huffman string compression is enabled + \li Window size for connection-level flow control is 65535 octets + \li Window size for stream-level flow control is 65535 octets + \li Frame size is 16384 octets + \endlist +*/ +QHttp2Configuration::QHttp2Configuration() + : d(new QHttp2ConfigurationPrivate) +{ +} + +/*! + Copy-constructs this QHttp2Configuration. +*/ +QHttp2Configuration::QHttp2Configuration(const QHttp2Configuration &) = default; + +/*! + Move-constructs this QHttp2Configuration from \a other +*/ +QHttp2Configuration::QHttp2Configuration(QHttp2Configuration &&other) noexcept +{ + swap(other); +} + +/*! + Copy-assigns to this QHttp2Configuration. +*/ +QHttp2Configuration &QHttp2Configuration::operator=(const QHttp2Configuration &) = default; + +/*! + Move-assigns to this QHttp2Configuration. +*/ +QHttp2Configuration &QHttp2Configuration::operator=(QHttp2Configuration &&) noexcept = default; + +/*! + Destructor. +*/ +QHttp2Configuration::~QHttp2Configuration() +{ +} + +/*! + If \a enable is \c true, a remote server can potentially + use server push to send reponses in advance. + + \sa serverPushEnabled +*/ +void QHttp2Configuration::setServerPushEnabled(bool enable) +{ + d->pushEnabled = enable; +} + +/*! + Returns true if server push was enabled. + + \note By default, QNetworkAccessManager disables server + push via the 'SETTINGS' frame. + + \sa setServerPushEnabled +*/ +bool QHttp2Configuration::serverPushEnabled() const +{ + return d->pushEnabled; +} + +/*! + If \a enable is \c true, HPACK compression will additionally + compress string using the Huffman coding. Enabled by default. + + \note This parameter only affects 'HEADERS' frames that + QNetworkAccessManager is sending. + + \sa huffmanCompressionEnabled +*/ +void QHttp2Configuration::setHuffmanCompressionEnabled(bool enable) +{ + d->huffmanCompressionEnabled = enable; +} + +/*! + Returns \c true if the Huffman coding in HPACK is enabled. + + \sa setHuffmanCompressionEnabled +*/ +bool QHttp2Configuration::huffmanCompressionEnabled() const +{ + return d->huffmanCompressionEnabled; +} + +/*! + Sets the window size for connection-level flow control. + \a size cannot be 0 and must not exceed 2147483647 octets. + + \sa sessionReceiveWindowSize +*/ +bool QHttp2Configuration::setSessionReceiveWindowSize(unsigned size) +{ + if (!size || size > Http2::maxSessionReceiveWindowSize) { // RFC-7540, 6.9 + qCWarning(QT_HTTP2) << "Invalid session window size"; + return false; + } + + d->sessionWindowSize = size; + return true; +} + +/*! + Returns the window size for connection-level flow control. + The default value QNetworkAccessManager will be using is + 2147483647 octets. +*/ +unsigned QHttp2Configuration::sessionReceiveWindowSize() const +{ + return d->sessionWindowSize; +} + +/*! + Sets the window size for stream-level flow control. + \a size cannot be 0 and must not exceed 2147483647 octets. + + \sa streamReceiveWindowSize + */ +bool QHttp2Configuration::setStreamReceiveWindowSize(unsigned size) +{ + if (!size || size > Http2::maxSessionReceiveWindowSize) { // RFC-7540, 6.9 + qCWarning(QT_HTTP2) << "Invalid stream window size"; + return false; + } + + d->streamWindowSize = size; + return true; +} + +/*! + Returns the window size for stream-level flow control. + The default value QNetworkAccessManager will be using is + 21474836 octets. +*/ +unsigned QHttp2Configuration::streamReceiveWindowSize() const +{ + return d->streamWindowSize; +} + +/*! + Sets the maximum frame size that QNetworkAccessManager + will advertise to the server when sending its initial SETTINGS frame. + \note While this \a size is required to be within a range between + 16384 and 16777215 inclusive, the actual payload size in frames + that carry payload maybe be less than 16384. +*/ +bool QHttp2Configuration::setMaxFrameSize(unsigned size) +{ + if (size < Http2::minPayloadLimit || size > Http2::maxPayloadSize) { + qCWarning(QT_HTTP2) << "Maximum frame size to advertise is invalid"; + return false; + } + + d->maxFrameSize = size; + return true; +} + +/*! + The maximum payload size that HTTP/2 frames can + have. The default (initial) value is 16384 octets. +*/ +unsigned QHttp2Configuration::maxFrameSize() const +{ + return d->maxFrameSize; +} + +/*! + Swaps this configuration with the \a other configuration. +*/ +void QHttp2Configuration::swap(QHttp2Configuration &other) noexcept +{ + d.swap(other.d); +} + +/*! + Returns \c true if \a lhs and \a rhs have the same set of HTTP/2 + parameters. +*/ +bool operator==(const QHttp2Configuration &lhs, const QHttp2Configuration &rhs) +{ + if (lhs.d == rhs.d) + return true; + + return lhs.d->pushEnabled == rhs.d->pushEnabled + && lhs.d->huffmanCompressionEnabled == rhs.d->huffmanCompressionEnabled + && lhs.d->sessionWindowSize == rhs.d->sessionWindowSize + && lhs.d->streamWindowSize == rhs.d->streamWindowSize; +} + +QT_END_NAMESPACE diff --git a/src/network/access/qhttp2configuration.h b/src/network/access/qhttp2configuration.h new file mode 100644 index 0000000000..e5c235e2be --- /dev/null +++ b/src/network/access/qhttp2configuration.h @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtNetwork module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QHTTP2CONFIGURATION_H +#define QHTTP2CONFIGURATION_H + +#include <QtNetwork/qtnetworkglobal.h> + +#include <QtCore/qshareddata.h> + +#ifndef Q_CLANG_QDOC +QT_REQUIRE_CONFIG(http); +#endif + +QT_BEGIN_NAMESPACE + +class QHttp2ConfigurationPrivate; +class Q_NETWORK_EXPORT QHttp2Configuration +{ + friend Q_NETWORK_EXPORT bool operator==(const QHttp2Configuration &lhs, const QHttp2Configuration &rhs); + +public: + QHttp2Configuration(); + QHttp2Configuration(const QHttp2Configuration &other); + QHttp2Configuration(QHttp2Configuration &&other) noexcept; + QHttp2Configuration &operator = (const QHttp2Configuration &other); + QHttp2Configuration &operator = (QHttp2Configuration &&other) noexcept; + + ~QHttp2Configuration(); + + void setServerPushEnabled(bool enable); + bool serverPushEnabled() const; + + void setHuffmanCompressionEnabled(bool enable); + bool huffmanCompressionEnabled() const; + + bool setSessionReceiveWindowSize(unsigned size); + unsigned sessionReceiveWindowSize() const; + + bool setStreamReceiveWindowSize(unsigned size); + unsigned streamReceiveWindowSize() const; + + bool setMaxFrameSize(unsigned size); + unsigned maxFrameSize() const; + + void swap(QHttp2Configuration &other) noexcept; + +private: + + QSharedDataPointer<QHttp2ConfigurationPrivate> d; +}; + +Q_DECLARE_SHARED(QHttp2Configuration) + +Q_NETWORK_EXPORT bool operator==(const QHttp2Configuration &lhs, const QHttp2Configuration &rhs); + +inline bool operator!=(const QHttp2Configuration &lhs, const QHttp2Configuration &rhs) +{ + return !(lhs == rhs); +} + +QT_END_NAMESPACE + +#endif // QHTTP2CONFIGURATION_H diff --git a/src/network/access/qhttp2protocolhandler.cpp b/src/network/access/qhttp2protocolhandler.cpp index 0ece5b7179..c1053882af 100644 --- a/src/network/access/qhttp2protocolhandler.cpp +++ b/src/network/access/qhttp2protocolhandler.cpp @@ -40,6 +40,7 @@ #include "qhttpnetworkconnection_p.h" #include "qhttp2protocolhandler_p.h" +#include "http2/http2frames_p.h" #include "http2/bitstreams_p.h" #include <private/qnoncontiguousbytedevice_p.h> @@ -51,6 +52,8 @@ #include <QtCore/qlist.h> #include <QtCore/qurl.h> +#include <qhttp2configuration.h> + #ifndef QT_NO_NETWORKPROXY #include <QtNetwork/qnetworkproxy.h> #endif @@ -172,30 +175,11 @@ QHttp2ProtocolHandler::QHttp2ProtocolHandler(QHttpNetworkConnectionChannel *chan Q_ASSERT(channel && m_connection); continuedFrames.reserve(20); - const ProtocolParameters params(m_connection->http2Parameters()); - Q_ASSERT(params.validate()); - - maxSessionReceiveWindowSize = params.maxSessionReceiveWindowSize; - - const RawSettings &data = params.settingsFrameData; - for (auto param = data.cbegin(), end = data.cend(); param != end; ++param) { - switch (param.key()) { - case Settings::INITIAL_WINDOW_SIZE_ID: - streamInitialReceiveWindowSize = param.value(); - break; - case Settings::ENABLE_PUSH_ID: - pushPromiseEnabled = param.value(); - break; - case Settings::HEADER_TABLE_SIZE_ID: - case Settings::MAX_CONCURRENT_STREAMS_ID: - case Settings::MAX_FRAME_SIZE_ID: - case Settings::MAX_HEADER_LIST_SIZE_ID: - // These other settings are just recommendations to our peer. We - // only check they are not crazy in ProtocolParameters::validate(). - default: - break; - } - } + const auto h2Config = m_connection->http2Parameters(); + maxSessionReceiveWindowSize = h2Config.sessionReceiveWindowSize(); + pushPromiseEnabled = h2Config.serverPushEnabled(); + streamInitialReceiveWindowSize = h2Config.streamReceiveWindowSize(); + encoder.setCompressStrings(h2Config.huffmanCompressionEnabled()); if (!channel->ssl && m_connection->connectionType() != QHttpNetworkConnection::ConnectionTypeHTTP2Direct) { // We upgraded from HTTP/1.1 to HTTP/2. channel->request was already sent @@ -422,20 +406,17 @@ bool QHttp2ProtocolHandler::sendClientPreface() return false; // 6.5 SETTINGS - const ProtocolParameters params(m_connection->http2Parameters()); - Q_ASSERT(params.validate()); - frameWriter.setOutboundFrame(params.settingsFrame()); + frameWriter.setOutboundFrame(Http2::configurationToSettingsFrame(m_connection->http2Parameters())); Q_ASSERT(frameWriter.outboundFrame().payloadSize()); if (!frameWriter.write(*m_socket)) return false; sessionReceiveWindowSize = maxSessionReceiveWindowSize; - // ProtocolParameters::validate does not allow maxSessionReceiveWindowSize - // to be smaller than defaultSessionWindowSize, so everything is OK here with - // 'delta': + // We only send WINDOW_UPDATE for the connection if the size differs from the + // default 64 KB: const auto delta = maxSessionReceiveWindowSize - Http2::defaultSessionWindowSize; - if (!sendWINDOW_UPDATE(Http2::connectionStreamID, delta)) + if (delta && !sendWINDOW_UPDATE(Http2::connectionStreamID, delta)) return false; prefaceSent = true; @@ -1069,7 +1050,7 @@ bool QHttp2ProtocolHandler::acceptSetting(Http2::Settings identifier, quint32 ne } if (identifier == Settings::MAX_FRAME_SIZE_ID) { - if (newValue < Http2::maxFrameSize || newValue > Http2::maxPayloadSize) { + if (newValue < Http2::minPayloadLimit || newValue > Http2::maxPayloadSize) { connectionError(PROTOCOL_ERROR, "SETTGINGS max frame size is out of range"); return false; } diff --git a/src/network/access/qhttp2protocolhandler_p.h b/src/network/access/qhttp2protocolhandler_p.h index b582123961..1943827e23 100644 --- a/src/network/access/qhttp2protocolhandler_p.h +++ b/src/network/access/qhttp2protocolhandler_p.h @@ -55,6 +55,8 @@ #include <private/qabstractprotocolhandler_p.h> #include <private/qhttpnetworkrequest_p.h> +#include <access/qhttp2configuration.h> + #include <private/http2protocol_p.h> #include <private/http2streams_p.h> #include <private/http2frames_p.h> @@ -163,8 +165,9 @@ private: static const std::deque<quint32>::size_type maxRecycledStreams; std::deque<quint32> recycledStreams; - // Peer's max frame size. - quint32 maxFrameSize = Http2::maxFrameSize; + // Peer's max frame size (this min is the default value + // we start with, that can be updated by SETTINGS frame): + quint32 maxFrameSize = Http2::minPayloadLimit; Http2::FrameReader frameReader; Http2::Frame inboundFrame; @@ -176,28 +179,28 @@ private: // Control flow: - // This is how many concurrent streams our peer expects from us: - // 100 is the default value, can be updated by the server's SETTINGS - // frame(s): + // This is how many concurrent streams our peer allows us, 100 is the + // initial value, can be updated by the server's SETTINGS frame(s): quint32 maxConcurrentStreams = Http2::maxConcurrentStreams; // While we allow sending SETTTINGS_MAX_CONCURRENT_STREAMS to limit our peer, // it's just a hint and we do not actually enforce it (and we can continue // sending requests and creating streams while maxConcurrentStreams allows). - // This is the max value, we set it in a ctor from Http2::ProtocolParameters, - // it does not change after that. + // This is our (client-side) maximum possible receive window size, we set + // it in a ctor from QHttp2Configuration, it does not change after that. + // The default is 64Kb: qint32 maxSessionReceiveWindowSize = Http2::defaultSessionWindowSize; - // Our session receive window size, default is 64Kb. We'll update it from QNAM's - // Http2::ProtocolParameters. Signed integer since it can become negative + // Our session current receive window size, updated in a ctor from + // QHttp2Configuration. Signed integer since it can become negative // (it's still a valid window size). qint32 sessionReceiveWindowSize = Http2::defaultSessionWindowSize; // Our per-stream receive window size, default is 64 Kb, will be updated - // from QNAM's Http2::ProtocolParameters. Again, signed - can become negative. + // from QHttp2Configuration. Again, signed - can become negative. qint32 streamInitialReceiveWindowSize = Http2::defaultSessionWindowSize; // These are our peer's receive window sizes, they will be updated by the - // peer's SETTINGS and WINDOW_UPDATE frames. + // peer's SETTINGS and WINDOW_UPDATE frames, defaults presumed to be 64Kb. qint32 sessionSendWindowSize = Http2::defaultSessionWindowSize; qint32 streamInitialSendWindowSize = Http2::defaultSessionWindowSize; diff --git a/src/network/access/qhttpnetworkconnection.cpp b/src/network/access/qhttpnetworkconnection.cpp index 1f1de478ea..13be1aa6b5 100644 --- a/src/network/access/qhttpnetworkconnection.cpp +++ b/src/network/access/qhttpnetworkconnection.cpp @@ -1456,21 +1456,16 @@ void QHttpNetworkConnection::setConnectionType(ConnectionType type) d->connectionType = type; } -Http2::ProtocolParameters QHttpNetworkConnection::http2Parameters() const +QHttp2Configuration QHttpNetworkConnection::http2Parameters() const { Q_D(const QHttpNetworkConnection); return d->http2Parameters; } -void QHttpNetworkConnection::setHttp2Parameters(const Http2::ProtocolParameters ¶ms) +void QHttpNetworkConnection::setHttp2Parameters(const QHttp2Configuration ¶ms) { Q_D(QHttpNetworkConnection); - if (params.validate()) { - d->http2Parameters = params; - } else { - qCWarning(QT_HTTP2) - << "invalid HTTP/2 parameters, falling back to defaults instead"; - } + d->http2Parameters = params; } // SSL support below diff --git a/src/network/access/qhttpnetworkconnection_p.h b/src/network/access/qhttpnetworkconnection_p.h index 85d89f20c2..6808a0c0ac 100644 --- a/src/network/access/qhttpnetworkconnection_p.h +++ b/src/network/access/qhttpnetworkconnection_p.h @@ -57,6 +57,8 @@ #include <QtNetwork/qabstractsocket.h> #include <QtNetwork/qnetworksession.h> +#include <qhttp2configuration.h> + #include <private/qobject_p.h> #include <qauthenticator.h> #include <qnetworkproxy.h> @@ -142,8 +144,8 @@ public: ConnectionType connectionType(); void setConnectionType(ConnectionType type); - Http2::ProtocolParameters http2Parameters() const; - void setHttp2Parameters(const Http2::ProtocolParameters ¶ms); + QHttp2Configuration http2Parameters() const; + void setHttp2Parameters(const QHttp2Configuration ¶ms); #ifndef QT_NO_SSL void setSslConfiguration(const QSslConfiguration &config); @@ -294,7 +296,7 @@ public: QSharedPointer<QNetworkSession> networkSession; #endif - Http2::ProtocolParameters http2Parameters; + QHttp2Configuration http2Parameters; QString peerVerifyName; // If network status monitoring is enabled, we activate connectionMonitor diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 3c9d53c5b5..716ea6c8b2 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -40,6 +40,7 @@ #include "qhttpnetworkconnectionchannel_p.h" #include "qhttpnetworkconnection_p.h" +#include "qhttp2configuration.h" #include "private/qnoncontiguousbytedevice_p.h" #include <qpair.h> @@ -48,6 +49,7 @@ #include <private/qhttp2protocolhandler_p.h> #include <private/qhttpprotocolhandler_p.h> #include <private/qspdyprotocolhandler_p.h> +#include <private/http2protocol_p.h> #ifndef QT_NO_SSL # include <private/qsslsocket_p.h> @@ -947,9 +949,7 @@ void QHttpNetworkConnectionChannel::_q_connected() if (tryProtocolUpgrade) { // Let's augment our request with some magic headers and try to // switch to HTTP/2. - const Http2::ProtocolParameters params(connection->http2Parameters()); - Q_ASSERT(params.validate()); - params.addProtocolUpgradeHeaders(&request); + Http2::appendProtocolUpgradeHeaders(connection->http2Parameters(), &request); } sendRequest(); } diff --git a/src/network/access/qhttpthreaddelegate.cpp b/src/network/access/qhttpthreaddelegate.cpp index acc551a7c9..1900397eab 100644 --- a/src/network/access/qhttpthreaddelegate.cpp +++ b/src/network/access/qhttpthreaddelegate.cpp @@ -352,9 +352,9 @@ void QHttpThreadDelegate::startRequest() networkSession); #endif // QT_NO_BEARERMANAGEMENT if (connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2 - && http2Parameters.validate()) { + || connectionType == QHttpNetworkConnection::ConnectionTypeHTTP2Direct) { httpConnection->setHttp2Parameters(http2Parameters); - } // else we ignore invalid parameters and use our own defaults. + } #ifndef QT_NO_SSL // Set the QSslConfiguration from this QNetworkRequest. if (ssl) diff --git a/src/network/access/qhttpthreaddelegate_p.h b/src/network/access/qhttpthreaddelegate_p.h index 6184b39b30..355d1afc30 100644 --- a/src/network/access/qhttpthreaddelegate_p.h +++ b/src/network/access/qhttpthreaddelegate_p.h @@ -62,6 +62,7 @@ #include <QNetworkReply> #include "qhttpnetworkrequest_p.h" #include "qhttpnetworkconnection_p.h" +#include "qhttp2configuration.h" #include <QSharedPointer> #include <QScopedPointer> #include "private/qnoncontiguousbytedevice_p.h" @@ -116,7 +117,7 @@ public: qint64 removedContentLength; QNetworkReply::NetworkError incomingErrorCode; QString incomingErrorDetail; - Http2::ProtocolParameters http2Parameters; + QHttp2Configuration http2Parameters; #ifndef QT_NO_BEARERMANAGEMENT QSharedPointer<QNetworkSession> networkSession; #endif diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index 29192ae7b0..76b95b5823 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -70,6 +70,7 @@ #include "QtNetwork/private/qauthenticator_p.h" #include "QtNetwork/qsslconfiguration.h" #include "QtNetwork/qnetworkconfigmanager.h" +#include "QtNetwork/private/http2protocol_p.h" #if QT_CONFIG(http) #include "qhttpmultipart.h" @@ -489,6 +490,7 @@ QNetworkAccessManager::QNetworkAccessManager(QObject *parent) qRegisterMetaType<QSharedPointer<char> >(); Q_D(QNetworkAccessManager); + if (QNetworkStatusMonitor::isEnabled()) { connect(&d->statusMonitor, SIGNAL(onlineStateChanged(bool)), SLOT(_q_onlineStateChanged(bool))); @@ -1178,7 +1180,6 @@ QSharedPointer<QNetworkSession> QNetworkAccessManagerPrivate::getNetworkSession( #endif // QT_NO_BEARERMANAGEMENT - #ifndef QT_NO_SSL /*! \since 5.2 @@ -1688,7 +1689,7 @@ void QNetworkAccessManager::clearConnectionCache() \sa setAutoDeleteReplies, QNetworkRequest::AutoDeleteReplyOnFinishAttribute */ -bool QNetworkAccessManager::autoDeleteReplies() +bool QNetworkAccessManager::autoDeleteReplies() const { return d_func()->autoDeleteReplies; } diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h index 601d0420ff..98498d07d2 100644 --- a/src/network/access/qnetworkaccessmanager.h +++ b/src/network/access/qnetworkaccessmanager.h @@ -167,7 +167,7 @@ public: void setRedirectPolicy(QNetworkRequest::RedirectPolicy policy); QNetworkRequest::RedirectPolicy redirectPolicy() const; - bool autoDeleteReplies(); + bool autoDeleteReplies() const; void setAutoDeleteReplies(bool autoDelete); Q_SIGNALS: diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index b9651b35d2..b3dec282b0 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -797,10 +797,8 @@ void QNetworkReplyHttpImplPrivate::postRequest(const QNetworkRequest &newHttpReq // Create the HTTP thread delegate QHttpThreadDelegate *delegate = new QHttpThreadDelegate; - // Propagate Http/2 settings if any - const QVariant blob(manager->property(Http2::http2ParametersPropertyName)); - if (blob.isValid() && blob.canConvert<Http2::ProtocolParameters>()) - delegate->http2Parameters = blob.value<Http2::ProtocolParameters>(); + // Propagate Http/2 settings: + delegate->http2Parameters = request.http2Configuration(); #ifndef QT_NO_BEARERMANAGEMENT if (!QNetworkStatusMonitor::isEnabled()) delegate->networkSession = managerPrivate->getNetworkSession(); @@ -1054,59 +1052,39 @@ void QNetworkReplyHttpImplPrivate::replyDownloadData(QByteArray d) if (!q->isOpen()) return; - int pendingSignals = (int)pendingDownloadDataEmissions->fetchAndAddAcquire(-1) - 1; + if (cacheEnabled && isCachingAllowed() && !cacheSaveDevice) + initCacheSaveDevice(); + + // This is going to look a little strange. When downloading data while a + // HTTP redirect is happening (and enabled), we write the redirect + // response to the cache. However, we do not append it to our internal + // buffer as that will contain the response data only for the final + // response + if (cacheSaveDevice) + cacheSaveDevice->write(d); + + if (!isHttpRedirectResponse()) { + buffer.append(d); + bytesDownloaded += d.size(); + } + bytesBuffered += d.size(); + int pendingSignals = pendingDownloadDataEmissions->fetchAndSubAcquire(1) - 1; if (pendingSignals > 0) { // Some more signal emissions to this slot are pending. // Instead of writing the downstream data, we wait // and do it in the next call we get // (signal comppression) - pendingDownloadData.append(d); return; } - pendingDownloadData.append(d); - d.clear(); - // We need to usa a copy for calling writeDownstreamData as we could - // possibly recurse into this this function when we call - // appendDownstreamDataSignalEmissions because the user might call - // processEvents() or spin an event loop when this occur. - QByteDataBuffer pendingDownloadDataCopy = pendingDownloadData; - pendingDownloadData.clear(); - - if (cacheEnabled && isCachingAllowed() && !cacheSaveDevice) { - initCacheSaveDevice(); - } - - qint64 bytesWritten = 0; - for (int i = 0; i < pendingDownloadDataCopy.bufferCount(); i++) { - QByteArray const &item = pendingDownloadDataCopy[i]; - - // This is going to look a little strange. When downloading data while a - // HTTP redirect is happening (and enabled), we write the redirect - // response to the cache. However, we do not append it to our internal - // buffer as that will contain the response data only for the final - // response - if (cacheSaveDevice) - cacheSaveDevice->write(item.constData(), item.size()); - - if (!isHttpRedirectResponse()) - buffer.append(item); - - bytesWritten += item.size(); - } - bytesBuffered += bytesWritten; - pendingDownloadDataCopy.clear(); + if (isHttpRedirectResponse()) + return; QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); if (preMigrationDownloaded != Q_INT64_C(-1)) totalSize = totalSize.toLongLong() + preMigrationDownloaded; - if (isHttpRedirectResponse()) - return; - - bytesDownloaded += bytesWritten; - emit q->readyRead(); // emit readyRead before downloadProgress incase this will cause events to be // processed and we get into a recursive call (as in QProgressDialog). diff --git a/src/network/access/qnetworkreplyhttpimpl_p.h b/src/network/access/qnetworkreplyhttpimpl_p.h index f5f01d0811..ef69ce0653 100644 --- a/src/network/access/qnetworkreplyhttpimpl_p.h +++ b/src/network/access/qnetworkreplyhttpimpl_p.h @@ -63,7 +63,6 @@ #include <QtNetwork/QNetworkCacheMetaData> #include <private/qhttpnetworkrequest_p.h> -#include <private/qbytedata_p.h> #include <private/qnetworkreply_p.h> #include <QtNetwork/QNetworkProxy> #include <QtNetwork/QNetworkSession> @@ -248,7 +247,6 @@ public: quint64 resumeOffset; qint64 preMigrationDownloaded; - QByteDataBuffer pendingDownloadData; // For signal compression qint64 bytesDownloaded; qint64 bytesBuffered; diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index 37f64c3f52..118fb6b1fb 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -42,6 +42,10 @@ #include "qplatformdefs.h" #include "qnetworkcookie.h" #include "qsslconfiguration.h" +#if QT_CONFIG(http) || defined(Q_CLANG_QDOC) +#include "qhttp2configuration.h" +#include "private/http2protocol_p.h" +#endif #include "QtCore/qshareddata.h" #include "QtCore/qlocale.h" #include "QtCore/qdatetime.h" @@ -445,6 +449,9 @@ public: sslConfiguration = new QSslConfiguration(*other.sslConfiguration); #endif peerVerifyName = other.peerVerifyName; +#if QT_CONFIG(http) + h2Configuration = other.h2Configuration; +#endif } inline bool operator==(const QNetworkRequestPrivate &other) const @@ -454,7 +461,11 @@ public: rawHeaders == other.rawHeaders && attributes == other.attributes && maxRedirectsAllowed == other.maxRedirectsAllowed && - peerVerifyName == other.peerVerifyName; + peerVerifyName == other.peerVerifyName +#if QT_CONFIG(http) + && h2Configuration == other.h2Configuration +#endif + ; // don't compare cookedHeaders } @@ -465,6 +476,9 @@ public: #endif int maxRedirectsAllowed; QString peerVerifyName; +#if QT_CONFIG(http) + QHttp2Configuration h2Configuration; +#endif }; /*! @@ -476,6 +490,15 @@ public: QNetworkRequest::QNetworkRequest() : d(new QNetworkRequestPrivate) { +#if QT_CONFIG(http) + // Initial values proposed by RFC 7540 are quite draconian, + // so unless an application will set its own parameters, we + // make stream window size larger and increase (via WINDOW_UPDATE) + // the session window size. These are our 'defaults': + d->h2Configuration.setStreamReceiveWindowSize(Http2::qtDefaultStreamReceiveWindowSize); + d->h2Configuration.setSessionReceiveWindowSize(Http2::maxSessionReceiveWindowSize); + d->h2Configuration.setServerPushEnabled(false); +#endif // QT_CONFIG(http) } /*! @@ -835,6 +858,52 @@ void QNetworkRequest::setPeerVerifyName(const QString &peerName) d->peerVerifyName = peerName; } +#if QT_CONFIG(http) || defined(Q_CLANG_QDOC) +/*! + \since 5.14 + + Returns the current parameters that QNetworkAccessManager is + using for this request and its underlying HTTP/2 connection. + This is either a configuration previously set by an application + or a default configuration. + + The default values that QNetworkAccessManager is using are: + + \list + \li Window size for connection-level flowcontrol is 2147483647 octets + \li Window size for stream-level flowcontrol is 21474836 octets + \li Max frame size is 16384 + \endlist + + By default, server push is disabled, Huffman compression and + string indexing are enabled. + + \sa setHttp2Configuration +*/ +QHttp2Configuration QNetworkRequest::http2Configuration() const +{ + return d->h2Configuration; +} + +/*! + \since 5.14 + + Sets request's HTTP/2 parameters from \a configuration. + + \note The configuration must be set prior to making a request. + \note HTTP/2 multiplexes several streams in a single HTTP/2 + connection. This implies that QNetworkAccessManager will use + the configuration found in the first request from a series + of requests sent to the same host. + + \sa http2Configuration, QNetworkAccessManager, QHttp2Configuration +*/ +void QNetworkRequest::setHttp2Configuration(const QHttp2Configuration &configuration) +{ + d->h2Configuration = configuration; +} +#endif // QT_CONFIG(http) || defined(Q_CLANG_QDOC) + static QByteArray headerName(QNetworkRequest::KnownHeaders header) { switch (header) { diff --git a/src/network/access/qnetworkrequest.h b/src/network/access/qnetworkrequest.h index 8ad4ab41c0..e09ff8aaae 100644 --- a/src/network/access/qnetworkrequest.h +++ b/src/network/access/qnetworkrequest.h @@ -49,6 +49,7 @@ QT_BEGIN_NAMESPACE class QSslConfiguration; +class QHttp2Configuration; class QNetworkRequestPrivate; class Q_NETWORK_EXPORT QNetworkRequest @@ -175,6 +176,10 @@ public: QString peerVerifyName() const; void setPeerVerifyName(const QString &peerName); +#if QT_CONFIG(http) || defined(Q_CLANG_QDOC) + QHttp2Configuration http2Configuration() const; + void setHttp2Configuration(const QHttp2Configuration &configuration); +#endif // QT_CONFIG(http) || defined(Q_CLANG_QDOC) private: QSharedDataPointer<QNetworkRequestPrivate> d; friend class QNetworkRequestPrivate; diff --git a/src/network/bearer/qbearerengine.cpp b/src/network/bearer/qbearerengine.cpp index a7c139fe63..06bf449611 100644 --- a/src/network/bearer/qbearerengine.cpp +++ b/src/network/bearer/qbearerengine.cpp @@ -38,6 +38,8 @@ ****************************************************************************/ #include "qbearerengine_p.h" +#include <QtCore/private/qlocking_p.h> + #include <algorithm> #ifndef QT_NO_BEARERMANAGEMENT @@ -86,7 +88,7 @@ bool QBearerEngine::requiresPolling() const */ bool QBearerEngine::configurationsInUse() const { - QMutexLocker locker(&mutex); + const auto locker = qt_scoped_lock(mutex); return hasUsedConfiguration(accessPointConfigurations) || hasUsedConfiguration(snapConfigurations) || hasUsedConfiguration(userChoiceConfigurations); diff --git a/src/network/bearer/qnetworkconfigmanager_p.cpp b/src/network/bearer/qnetworkconfigmanager_p.cpp index 91ea063af1..b432444669 100644 --- a/src/network/bearer/qnetworkconfigmanager_p.cpp +++ b/src/network/bearer/qnetworkconfigmanager_p.cpp @@ -45,6 +45,7 @@ #include <QtCore/qstringlist.h> #include <QtCore/qthread.h> #include <QtCore/private/qcoreapplication_p.h> +#include <QtCore/private/qlocking_p.h> #include <QtCore/private/qthread_p.h> #include <QtCore/qbytearray.h> @@ -115,10 +116,10 @@ QNetworkConfiguration QNetworkConfigurationManagerPrivate::defaultConfiguration( QNetworkConfigurationPrivatePointer defaultConfiguration; for (QBearerEngine *engine : sessionEngines) { - QMutexLocker locker(&engine->mutex); + const auto locker = qt_scoped_lock(engine->mutex); for (const auto &ptr : qAsConst(engine->snapConfigurations)) { - QMutexLocker configLocker(&ptr->mutex); + const auto locker = qt_scoped_lock(ptr->mutex); if ((ptr->state & QNetworkConfiguration::Active) == QNetworkConfiguration::Active) { QNetworkConfiguration config; @@ -211,11 +212,11 @@ QList<QNetworkConfiguration> QNetworkConfigurationManagerPrivate::allConfigurati for (QBearerEngine *engine : sessionEngines) { - QMutexLocker locker(&engine->mutex); + const auto locker = qt_scoped_lock(engine->mutex); //find all InternetAccessPoints for (const auto &ptr : qAsConst(engine->accessPointConfigurations)) { - QMutexLocker configLocker(&ptr->mutex); + const auto locker = qt_scoped_lock(ptr->mutex); if ((ptr->state & filter) == filter) { QNetworkConfiguration pt; @@ -226,7 +227,7 @@ QList<QNetworkConfiguration> QNetworkConfigurationManagerPrivate::allConfigurati //find all service networks for (const auto &ptr : qAsConst(engine->snapConfigurations)) { - QMutexLocker configLocker(&ptr->mutex); + const auto locker = qt_scoped_lock(ptr->mutex); if ((ptr->state & filter) == filter) { QNetworkConfiguration pt; @@ -243,10 +244,10 @@ QNetworkConfiguration QNetworkConfigurationManagerPrivate::configurationFromIden { QNetworkConfiguration item; - QMutexLocker locker(&mutex); + const auto locker = qt_scoped_lock(mutex); for (QBearerEngine *engine : sessionEngines) { - QMutexLocker locker(&engine->mutex); + const auto locker = qt_scoped_lock(engine->mutex); if (auto ptr = engine->accessPointConfigurations.value(identifier)) { item.d = std::move(ptr); break; @@ -266,7 +267,7 @@ QNetworkConfiguration QNetworkConfigurationManagerPrivate::configurationFromIden bool QNetworkConfigurationManagerPrivate::isOnline() const { - QMutexLocker locker(&mutex); + const auto locker = qt_scoped_lock(mutex); // We need allConfigurations since onlineConfigurations is filled with queued connections // and thus is not always (more importantly just after creation) up to date @@ -275,7 +276,7 @@ bool QNetworkConfigurationManagerPrivate::isOnline() const QNetworkConfigurationManager::Capabilities QNetworkConfigurationManagerPrivate::capabilities() const { - QMutexLocker locker(&mutex); + const auto locker = qt_scoped_lock(mutex); QNetworkConfigurationManager::Capabilities capFlags; @@ -287,7 +288,7 @@ QNetworkConfigurationManager::Capabilities QNetworkConfigurationManagerPrivate:: void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurationPrivatePointer ptr) { - QMutexLocker locker(&mutex); + const auto locker = qt_scoped_lock(mutex); if (!firstUpdate) { QNetworkConfiguration item; @@ -295,24 +296,24 @@ void QNetworkConfigurationManagerPrivate::configurationAdded(QNetworkConfigurati emit configurationAdded(item); } - ptr->mutex.lock(); + auto ptrLocker = qt_unique_lock(ptr->mutex); if (ptr->state == QNetworkConfiguration::Active) { - ptr->mutex.unlock(); - onlineConfigurations.insert(ptr->id); + const auto id = ptr->id; + ptrLocker.unlock(); + onlineConfigurations.insert(id); if (!firstUpdate && onlineConfigurations.count() == 1) emit onlineStateChanged(true); - } else { - ptr->mutex.unlock(); } } void QNetworkConfigurationManagerPrivate::configurationRemoved(QNetworkConfigurationPrivatePointer ptr) { - QMutexLocker locker(&mutex); + const auto locker = qt_scoped_lock(mutex); - ptr->mutex.lock(); - ptr->isValid = false; - ptr->mutex.unlock(); + { + const auto locker = qt_scoped_lock(ptr->mutex); + ptr->isValid = false; + } if (!firstUpdate) { QNetworkConfiguration item; @@ -327,7 +328,7 @@ void QNetworkConfigurationManagerPrivate::configurationRemoved(QNetworkConfigura void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigurationPrivatePointer ptr) { - QMutexLocker locker(&mutex); + const auto locker = qt_scoped_lock(mutex); if (!firstUpdate) { QNetworkConfiguration item; @@ -337,12 +338,13 @@ void QNetworkConfigurationManagerPrivate::configurationChanged(QNetworkConfigura bool previous = !onlineConfigurations.isEmpty(); - ptr->mutex.lock(); - if (ptr->state == QNetworkConfiguration::Active) - onlineConfigurations.insert(ptr->id); - else - onlineConfigurations.remove(ptr->id); - ptr->mutex.unlock(); + { + const auto locker = qt_scoped_lock(ptr->mutex); + if (ptr->state == QNetworkConfiguration::Active) + onlineConfigurations.insert(ptr->id); + else + onlineConfigurations.remove(ptr->id); + } bool online = !onlineConfigurations.isEmpty(); @@ -354,7 +356,8 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() { typedef QMultiMap<int, QString> PluginKeyMap; typedef PluginKeyMap::const_iterator PluginKeyMapConstIterator; - QMutexLocker locker(&mutex); + + auto locker = qt_unique_lock(mutex); if (firstUpdate) { if (qobject_cast<QBearerEngine *>(sender())) @@ -432,7 +435,7 @@ void QNetworkConfigurationManagerPrivate::updateConfigurations() void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() { - QMutexLocker locker(&mutex); + const auto locker = qt_scoped_lock(mutex); if (sessionEngines.isEmpty()) { emit configurationUpdateComplete(); @@ -449,14 +452,14 @@ void QNetworkConfigurationManagerPrivate::performAsyncConfigurationUpdate() QList<QBearerEngine *> QNetworkConfigurationManagerPrivate::engines() const { - QMutexLocker locker(&mutex); + const auto locker = qt_scoped_lock(mutex); return sessionEngines; } void QNetworkConfigurationManagerPrivate::startPolling() { - QMutexLocker locker(&mutex); + const auto locker = qt_scoped_lock(mutex); if (!pollTimer) { pollTimer = new QTimer(this); bool ok; @@ -482,7 +485,7 @@ void QNetworkConfigurationManagerPrivate::startPolling() void QNetworkConfigurationManagerPrivate::pollEngines() { - QMutexLocker locker(&mutex); + const auto locker = qt_scoped_lock(mutex); for (QBearerEngine *engine : qAsConst(sessionEngines)) { if (engine->requiresPolling() && (forcedPolling || engine->configurationsInUse())) { @@ -494,7 +497,7 @@ void QNetworkConfigurationManagerPrivate::pollEngines() void QNetworkConfigurationManagerPrivate::enablePolling() { - QMutexLocker locker(&mutex); + const auto locker = qt_scoped_lock(mutex); ++forcedPolling; @@ -504,7 +507,7 @@ void QNetworkConfigurationManagerPrivate::enablePolling() void QNetworkConfigurationManagerPrivate::disablePolling() { - QMutexLocker locker(&mutex); + const auto locker = qt_scoped_lock(mutex); --forcedPolling; } diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index 487cac6d90..9ce2d72bd3 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -102,16 +102,6 @@ std::pair<OutputIt1, OutputIt2> separate_if(InputIt first, InputIt last, OutputI return std::make_pair(dest1, dest2); } -int get_signal_index() -{ - static auto senderMetaObject = &QHostInfoResult::staticMetaObject; - static auto signal = &QHostInfoResult::resultsReady; - int signal_index = -1; - void *args[] = { &signal_index, &signal }; - senderMetaObject->static_metacall(QMetaObject::IndexOfMethod, 0, args); - return signal_index + QMetaObjectPrivate::signalOffset(senderMetaObject); -} - } /* @@ -129,38 +119,59 @@ void QHostInfoResult::postResultsReady(const QHostInfo &info) { // queued connection will take care of dispatching to right thread if (!slotObj) { - emitResultsReady(info); + emit resultsReady(info); return; } - static const int signal_index = get_signal_index(); - // we used to have a context object, but it's already destroyed if (withContextObject && !receiver) return; - /* QHostInfoResult c'tor moves the result object to the thread of receiver. - If we don't have a receiver, then the result object will not live in a - thread that runs an event loop - so move it to this' thread, which is the thread - that initiated the lookup, and required to have a running event loop. */ - auto result = new QHostInfoResult(receiver, slotObj); - if (!receiver) - result->moveToThread(thread()); + static const int signal_index = []() -> int { + auto senderMetaObject = &QHostInfoResult::staticMetaObject; + auto signal = &QHostInfoResult::resultsReady; + int signal_index = -1; + void *args[] = { &signal_index, &signal }; + senderMetaObject->static_metacall(QMetaObject::IndexOfMethod, 0, args); + return signal_index + QMetaObjectPrivate::signalOffset(senderMetaObject); + }(); + + // a long-living version of this + auto result = new QHostInfoResult(this); Q_CHECK_PTR(result); + const int nargs = 2; - auto types = reinterpret_cast<int *>(malloc(nargs * sizeof(int))); - Q_CHECK_PTR(types); + auto metaCallEvent = new QMetaCallEvent(slotObj, nullptr, signal_index, nargs); + Q_CHECK_PTR(metaCallEvent); + void **args = metaCallEvent->args(); + int *types = metaCallEvent->types(); types[0] = QMetaType::type("void"); types[1] = QMetaType::type("QHostInfo"); - auto args = reinterpret_cast<void **>(malloc(nargs * sizeof(void *))); - Q_CHECK_PTR(args); - args[0] = 0; + args[0] = nullptr; args[1] = QMetaType::create(types[1], &info); Q_CHECK_PTR(args[1]); - auto metaCallEvent = new QMetaCallEvent(slotObj, nullptr, signal_index, nargs, types, args); - Q_CHECK_PTR(metaCallEvent); qApp->postEvent(result, metaCallEvent); } +/* + Receives the event posted by postResultsReady, and calls the functor. +*/ +bool QHostInfoResult::event(QEvent *event) +{ + if (event->type() == QEvent::MetaCall) { + Q_ASSERT(slotObj); + auto metaCallEvent = static_cast<QMetaCallEvent *>(event); + auto args = metaCallEvent->args(); + // we didn't have a context object, or it's still alive + if (!withContextObject || receiver) + slotObj->call(const_cast<QObject*>(receiver.data()), args); + slotObj->destroyIfLastRef(); + + deleteLater(); + return true; + } + return QObject::event(event); +} + /*! \class QHostInfo \brief The QHostInfo class provides static functions for host name lookups. @@ -255,64 +266,9 @@ static int nextId() \sa abortHostLookup(), addresses(), error(), fromName() */ -int QHostInfo::lookupHost(const QString &name, QObject *receiver, - const char *member) +int QHostInfo::lookupHost(const QString &name, QObject *receiver, const char *member) { -#if defined QHOSTINFO_DEBUG - qDebug("QHostInfo::lookupHost(\"%s\", %p, %s)", - name.toLatin1().constData(), receiver, member ? member + 1 : 0); -#endif - - if (!QAbstractEventDispatcher::instance(QThread::currentThread())) { - qWarning("QHostInfo::lookupHost() called with no event dispatcher"); - return -1; - } - - qRegisterMetaType<QHostInfo>(); - - int id = nextId(); // generate unique ID - - if (name.isEmpty()) { - if (!receiver) - return -1; - - QHostInfo hostInfo(id); - hostInfo.setError(QHostInfo::HostNotFound); - hostInfo.setErrorString(QCoreApplication::translate("QHostInfo", "No host name given")); - QScopedPointer<QHostInfoResult> result(new QHostInfoResult); - QObject::connect(result.data(), SIGNAL(resultsReady(QHostInfo)), - receiver, member, Qt::QueuedConnection); - result.data()->emitResultsReady(hostInfo); - return id; - } - - QHostInfoLookupManager *manager = theHostInfoLookupManager(); - - if (manager) { - // the application is still alive - if (manager->cache.isEnabled()) { - // check cache first - bool valid = false; - QHostInfo info = manager->cache.get(name, &valid); - if (valid) { - if (!receiver) - return -1; - - info.setLookupId(id); - QHostInfoResult result; - QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection); - result.emitResultsReady(info); - return id; - } - } - - // cache is not enabled or it was not in the cache, do normal lookup - QHostInfoRunnable* runnable = new QHostInfoRunnable(name, id); - if (receiver) - QObject::connect(&runnable->resultEmitter, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection); - manager->scheduleLookup(runnable); - } - return id; + return QHostInfoPrivate::lookupHostImpl(name, receiver, nullptr, member); } /*! @@ -818,14 +774,32 @@ QString QHostInfo::localHostName() \sa hostName() */ +// ### Qt 6 merge with function below int QHostInfo::lookupHostImpl(const QString &name, const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj) { + return QHostInfoPrivate::lookupHostImpl(name, receiver, slotObj, nullptr); +} +/* + Called by the various lookupHost overloads to perform the lookup. + + Signals either the functor encapuslated in the \a slotObj in the context + of \a receiver, or the \a member slot of the \a receiver. + + \a receiver might be the nullptr, but only if a \a slotObj is provided. +*/ +int QHostInfoPrivate::lookupHostImpl(const QString &name, + const QObject *receiver, + QtPrivate::QSlotObjectBase *slotObj, + const char *member) +{ #if defined QHOSTINFO_DEBUG - qDebug("QHostInfo::lookupHost(\"%s\", %p, %p)", - name.toLatin1().constData(), receiver, slotObj); + qDebug("QHostInfoPrivate::lookupHostImpl(\"%s\", %p, %p, %s)", + name.toLatin1().constData(), receiver, slotObj, member ? member + 1 : 0); #endif + Q_ASSERT(!member != !slotObj); // one of these must be set, but not both + Q_ASSERT(receiver || slotObj); if (!QAbstractEventDispatcher::instance(QThread::currentThread())) { qWarning("QHostInfo::lookupHost() called with no event dispatcher"); @@ -840,8 +814,13 @@ int QHostInfo::lookupHostImpl(const QString &name, QHostInfo hostInfo(id); hostInfo.setError(QHostInfo::HostNotFound); hostInfo.setErrorString(QCoreApplication::translate("QHostInfo", "No host name given")); + QHostInfoResult result(receiver, slotObj); + if (receiver && member) + QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)), + receiver, member, Qt::QueuedConnection); result.postResultsReady(hostInfo); + return id; } @@ -856,23 +835,24 @@ int QHostInfo::lookupHostImpl(const QString &name, if (valid) { info.setLookupId(id); QHostInfoResult result(receiver, slotObj); + if (receiver && member) + QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)), + receiver, member, Qt::QueuedConnection); result.postResultsReady(info); return id; } } // cache is not enabled or it was not in the cache, do normal lookup - QHostInfoRunnable* runnable = new QHostInfoRunnable(name, id, receiver, slotObj); + QHostInfoRunnable *runnable = new QHostInfoRunnable(name, id, receiver, slotObj); + if (receiver && member) + QObject::connect(&runnable->resultEmitter, SIGNAL(resultsReady(QHostInfo)), + receiver, member, Qt::QueuedConnection); manager->scheduleLookup(runnable); } return id; } -QHostInfoRunnable::QHostInfoRunnable(const QString &hn, int i) : toBeLookedUp(hn), id(i) -{ - setAutoDelete(true); -} - QHostInfoRunnable::QHostInfoRunnable(const QString &hn, int i, const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj) : toBeLookedUp(hn), id(i), resultEmitter(receiver, slotObj) @@ -1119,7 +1099,7 @@ QHostInfo qt_qhostinfo_lookup(const QString &name, QObject *receiver, const char } // was not in cache, trigger lookup - *id = QHostInfo::lookupHost(name, receiver, member); + *id = QHostInfoPrivate::lookupHostImpl(name, receiver, nullptr, member); // return empty response, valid==false return QHostInfo(); diff --git a/src/network/kernel/qhostinfo_p.h b/src/network/kernel/qhostinfo_p.h index 9a4657234e..1798ceab0a 100644 --- a/src/network/kernel/qhostinfo_p.h +++ b/src/network/kernel/qhostinfo_p.h @@ -81,58 +81,38 @@ QT_BEGIN_NAMESPACE class QHostInfoResult : public QObject { Q_OBJECT - - QPointer<const QObject> receiver = nullptr; - QtPrivate::QSlotObjectBase *slotObj = nullptr; - const bool withContextObject = false; - public: - QHostInfoResult() = default; - QHostInfoResult(const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj) : - receiver(receiver), - slotObj(slotObj), - withContextObject(slotObj && receiver) + QHostInfoResult(const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj) + : receiver(receiver), slotObj(slotObj), + withContextObject(slotObj && receiver) { - connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this, - &QObject::deleteLater); - if (slotObj && receiver) + if (receiver) moveToThread(receiver->thread()); } void postResultsReady(const QHostInfo &info); -public Q_SLOTS: - inline void emitResultsReady(const QHostInfo &info) - { - if (slotObj) { - // we used to have a context object, but it's already destroyed - if (withContextObject && !receiver) - return; - QHostInfo copy = info; - void *args[2] = { nullptr, reinterpret_cast<void *>(©) }; - slotObj->call(const_cast<QObject*>(receiver.data()), args); - slotObj->destroyIfLastRef(); - } else { - emit resultsReady(info); - } - } +Q_SIGNALS: + void resultsReady(const QHostInfo &info); protected: - bool event(QEvent *event) override + bool event(QEvent *event) override; + +private: + QHostInfoResult(const QHostInfoResult *other) + : receiver(other->receiver), slotObj(other->slotObj), + withContextObject(other->withContextObject) { - if (event->type() == QEvent::MetaCall) { - auto metaCallEvent = static_cast<QMetaCallEvent *>(event); - auto args = metaCallEvent->args(); - auto hostInfo = reinterpret_cast<QHostInfo *>(args[1]); - emitResultsReady(*hostInfo); - deleteLater(); - return true; - } - return QObject::event(event); + // cleanup if the application terminates before results are delivered + connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, + this, &QObject::deleteLater); + // maintain thread affinity + moveToThread(other->thread()); } -Q_SIGNALS: - void resultsReady(const QHostInfo &info); + QPointer<const QObject> receiver = nullptr; + QtPrivate::QSlotObjectBase *slotObj = nullptr; + const bool withContextObject = false; }; class QHostInfoAgent @@ -160,6 +140,10 @@ public: //not a public API yet static QHostInfo fromName(const QString &hostName, QSharedPointer<QNetworkSession> networkSession); #endif + static int lookupHostImpl(const QString &name, + const QObject *receiver, + QtPrivate::QSlotObjectBase *slotObj, + const char *member); QHostInfo::HostInfoError err; QString errorStr; @@ -204,7 +188,6 @@ private: class QHostInfoRunnable : public QRunnable { public: - QHostInfoRunnable(const QString &hn, int i); QHostInfoRunnable(const QString &hn, int i, const QObject *receiver, QtPrivate::QSlotObjectBase *slotObj); void run() override; diff --git a/src/network/kernel/qnetconmonitor_win.cpp b/src/network/kernel/qnetconmonitor_win.cpp index b543508169..a010df8e3a 100644 --- a/src/network/kernel/qnetconmonitor_win.cpp +++ b/src/network/kernel/qnetconmonitor_win.cpp @@ -99,7 +99,7 @@ QNetworkInterface getInterfaceFromHostAddress(const QHostAddress &local) } } // anonymous namespace -class QNetworkConnectionEvents final : public INetworkConnectionEvents +class QNetworkConnectionEvents : public INetworkConnectionEvents { public: QNetworkConnectionEvents(QNetworkConnectionMonitorPrivate *monitor); @@ -139,7 +139,7 @@ private: QNetworkConnectionMonitorPrivate *monitor = nullptr; - QAtomicInteger<ULONG> ref = 1; // start at 1 for our own initial reference + QAtomicInteger<ULONG> ref = 0; DWORD cookie = 0; }; @@ -346,6 +346,8 @@ QNetworkConnectionMonitorPrivate::~QNetworkConnectionMonitorPrivate() { if (comInitFailed) return; + if (monitoring) + stopMonitoring(); connectionEvents.Reset(); CoUninitialize(); } @@ -465,7 +467,7 @@ bool QNetworkConnectionMonitor::isReachable() return d_func()->connectivity & required; } -class QNetworkListManagerEvents final : public INetworkListManagerEvents +class QNetworkListManagerEvents : public INetworkListManagerEvents { public: QNetworkListManagerEvents(QNetworkStatusMonitorPrivate *monitor); @@ -496,7 +498,7 @@ private: QNetworkStatusMonitorPrivate *monitor = nullptr; - QAtomicInteger<ULONG> ref = 1; // start at 1 for our own initial reference + QAtomicInteger<ULONG> ref = 0; DWORD cookie = 0; }; |