@@ -200,7 +200,10 @@ class MQTTClient {
200200 // connect to broker
201201 this ->_lastError = lwmqtt_connect (&this ->client , options, will, &this ->_returnCode , this ->timeout );
202202 if (this ->_lastError != LWMQTT_SUCCESS) {
203- return this ->close ();
203+ // close connection
204+ this ->close ();
205+
206+ return false ;
204207 }
205208
206209 // set flag
@@ -253,7 +256,10 @@ class MQTTClient {
253256 // publish message
254257 this ->_lastError = lwmqtt_publish (&this ->client , lwmqtt_string (topic), message, this ->timeout );
255258 if (this ->_lastError != LWMQTT_SUCCESS) {
256- return this ->close ();
259+ // close connection
260+ this ->close ();
261+
262+ return false ;
257263 }
258264
259265 return true ;
@@ -274,7 +280,10 @@ class MQTTClient {
274280 // subscribe to topic
275281 this ->_lastError = lwmqtt_subscribe_one (&this ->client , lwmqtt_string (topic), (lwmqtt_qos_t )qos, this ->timeout );
276282 if (this ->_lastError != LWMQTT_SUCCESS) {
277- return this ->close ();
283+ // close connection
284+ this ->close ();
285+
286+ return false ;
278287 }
279288
280289 return true ;
@@ -291,7 +300,10 @@ class MQTTClient {
291300 // unsubscribe from topic
292301 this ->_lastError = lwmqtt_unsubscribe_one (&this ->client , lwmqtt_string (topic), this ->timeout );
293302 if (this ->_lastError != LWMQTT_SUCCESS) {
294- return this ->close ();
303+ // close connection
304+ this ->close ();
305+
306+ return false ;
295307 }
296308
297309 return true ;
@@ -310,14 +322,20 @@ class MQTTClient {
310322 if (available > 0 ) {
311323 this ->_lastError = lwmqtt_yield (&this ->client , available, this ->timeout );
312324 if (this ->_lastError != LWMQTT_SUCCESS) {
313- return this ->close ();
325+ // close connection
326+ this ->close ();
327+
328+ return false ;
314329 }
315330 }
316331
317332 // keep the connection alive
318333 this ->_lastError = lwmqtt_keep_alive (&this ->client , this ->timeout );
319334 if (this ->_lastError != LWMQTT_SUCCESS) {
320- return this ->close ();
335+ // close connection
336+ this ->close ();
337+
338+ return false ;
321339 }
322340
323341 return true ;
@@ -349,14 +367,12 @@ class MQTTClient {
349367 }
350368
351369 private:
352- bool close () {
370+ void close () {
353371 // set flag
354372 this ->_connected = false ;
355373
356374 // close network
357375 this ->netClient ->stop ();
358-
359- return false ;
360376 }
361377};
362378
0 commit comments