aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSona Kurazyan <sona.kurazyan@qt.io>2019-07-11 15:07:23 +0200
committerSona Kurazyan <sona.kurazyan@qt.io>2019-07-11 14:15:05 +0000
commit9c933b340023ae0399fd6cbe0f0ef84c3a46d12c (patch)
treee68a4182119924f71fb869da772b89613ef3430e
parentc3f764b524b959eac506d210f30554d12c1ce9ca (diff)
Fix assertion when setting the timeout
After 5d7e221bbf9e27e90448243909abc76d81733381 an assertion will be triggered when calling QRandomGenerator::bounded with equal low and high values. Change-Id: Id6d7c0f583285a54303452a6f2538f3ca72adced Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/coap/qcoapprotocol.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/coap/qcoapprotocol.cpp b/src/coap/qcoapprotocol.cpp
index 30ee188..42ef4ba 100644
--- a/src/coap/qcoapprotocol.cpp
+++ b/src/coap/qcoapprotocol.cpp
@@ -180,10 +180,17 @@ void QCoapProtocol::sendRequest(QPointer<QCoapReply> reply, QCoapConnection *con
internalRequest->setToSendBlock(0, d->blockSize);
}
- if (requestMessage->type() == QCoapMessage::Type::Confirmable)
- internalRequest->setTimeout(QtCoap::randomGenerator().bounded(minimumTimeout(), maximumTimeout()));
- else
+ if (requestMessage->type() == QCoapMessage::Type::Confirmable) {
+ const auto minTimeout = minimumTimeout();
+ const auto maxTimeout = maximumTimeout();
+ Q_ASSERT(minTimeout <= maxTimeout);
+
+ internalRequest->setTimeout(minTimeout == maxTimeout
+ ? minTimeout
+ : QtCoap::randomGenerator().bounded(minTimeout, maxTimeout));
+ } else {
internalRequest->setTimeout(maximumTimeout());
+ }
connect(internalRequest.data(), &QCoapInternalRequest::timeout,
[this](QCoapInternalRequest *request) {