diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-03-16 03:05:17 +0100 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-03-16 03:05:17 +0100 |
commit | 5b8ae24da570f61123e14b6f84eb6bab41ac8a29 (patch) | |
tree | d8e86c4253bc1da0d81768ed574f9ff133948559 | |
parent | 8c964ff26eb32e93c4ff03b3bc8f5c4d568b39a3 (diff) | |
parent | 1966376a937ac4e4486c30e5a5946494d20446dc (diff) |
Merge remote-tracking branch 'origin/5.13' into dev
Change-Id: I11bde6a2389cd66c6d945d9f8bd32528dc43cc31
-rw-r--r-- | src/mqtt/qmqttclient.cpp | 3 | ||||
-rw-r--r-- | src/mqtt/qmqttconnection.cpp | 12 | ||||
-rw-r--r-- | src/mqtt/qmqttconnection_p.h | 1 |
3 files changed, 16 insertions, 0 deletions
diff --git a/src/mqtt/qmqttclient.cpp b/src/mqtt/qmqttclient.cpp index 57050a0..e233ae7 100644 --- a/src/mqtt/qmqttclient.cpp +++ b/src/mqtt/qmqttclient.cpp @@ -93,6 +93,9 @@ Q_LOGGING_CATEGORY(lcMqttClient, "qt.mqtt.client") The interval is specified in milliseconds. However, most brokers are not capable of using such a high granularity and will fall back to an interval specified in seconds. + + If the broker does not respond within a grace period the connection will be + closed. */ /*! diff --git a/src/mqtt/qmqttconnection.cpp b/src/mqtt/qmqttconnection.cpp index 8ef8fff..6759306 100644 --- a/src/mqtt/qmqttconnection.cpp +++ b/src/mqtt/qmqttconnection.cpp @@ -578,11 +578,19 @@ bool QMqttConnection::sendControlPingRequest() if (m_internalState != QMqttConnection::BrokerConnected) return false; + // 3.1.2.10 If a Client does not receive a PINGRESP packet within a reasonable amount of time + // after it has sent a PINGREQ, it SHOULD close the Network Connection to the Server + // Consider two pending PINGRESP as reasonable. + if (m_pingTimeout > 1) { + closeConnection(QMqttClient::ServerUnavailable); + return false; + } const QMqttControlPacket packet(QMqttControlPacket::PINGREQ); if (!writePacketToTransport(packet)) { qCDebug(lcMqttConnection) << "Failed to write PINGREQ to transport."; return false; } + m_pingTimeout++; return true; } @@ -591,6 +599,7 @@ bool QMqttConnection::sendControlDisconnect() qCDebug(lcMqttConnection) << Q_FUNC_INFO; m_pingTimer.stop(); + m_pingTimeout = 0; m_activeSubscriptions.clear(); @@ -676,6 +685,7 @@ void QMqttConnection::transportConnectionClosed() m_readBuffer.clear(); m_readPosition = 0; m_pingTimer.stop(); + m_pingTimeout = 0; if (m_internalState == BrokerDisconnected) // We manually disconnected m_clientPrivate->setStateAndError(QMqttClient::Disconnected, QMqttClient::NoError); else @@ -730,6 +740,7 @@ void QMqttConnection::closeConnection(QMqttClient::ClientError error) m_readBuffer.clear(); m_readPosition = 0; m_pingTimer.stop(); + m_pingTimeout = 0; m_activeSubscriptions.clear(); m_internalState = BrokerDisconnected; m_transport->disconnect(); @@ -1620,6 +1631,7 @@ void QMqttConnection::finalize_pingresp() closeConnection(QMqttClient::ProtocolViolation); return; } + m_pingTimeout--; emit m_clientPrivate->m_client->pingResponseReceived(); } diff --git a/src/mqtt/qmqttconnection_p.h b/src/mqtt/qmqttconnection_p.h index 933d1dc..626addc 100644 --- a/src/mqtt/qmqttconnection_p.h +++ b/src/mqtt/qmqttconnection_p.h @@ -157,6 +157,7 @@ private: QMap<quint16, QSharedPointer<QMqttControlPacket>> m_pendingReleaseMessages; InternalConnectionState m_internalState{BrokerDisconnected}; QTimer m_pingTimer; + int m_pingTimeout{0}; QVector<QMqttTopicName> m_receiveAliases; QVector<QMqttTopicName> m_publishAliases; |