From 5357a282d7a856bc660ae5705e5bfab3a2e928ad Mon Sep 17 00:00:00 2001 From: fpagliughi Date: Sat, 6 Jul 2024 14:33:46 -0400 Subject: [PATCH] Fixed connect with listener --- src/async_client.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/async_client.cpp b/src/async_client.cpp index 5314bd7a..5b785b99 100644 --- a/src/async_client.cpp +++ b/src/async_client.cpp @@ -413,19 +413,14 @@ token_ptr async_client::connect(connect_options opts) token_ptr async_client::connect(connect_options opts, void* userContext, iaction_listener& cb) { - // If the options specified a new MQTT protocol version, we should - // use it, otherwise default to the version requested when the client - // was created. - if (opts.opts_.MQTTVersion == 0 && mqttVersion_ >= 5) - opts.opts_.MQTTVersion = mqttVersion_; - else - mqttVersion_ = opts.opts_.MQTTVersion; + // Remember the requested protocol version + mqttVersion_ = opts.opts_.MQTTVersion; // The C lib is very picky about version and clean start/session - if (opts.opts_.MQTTVersion >= 5) - opts.opts_.cleansession = 0; - else + if (opts.opts_.MQTTVersion < 5) opts.opts_.cleanstart = 0; + else + opts.opts_.cleansession = 0; auto tmpTok = connTok_; connTok_ = token::create(token::Type::CONNECT, *this, userContext, cb);