From a78c24cd345d92fa6849fc9a709cb3e09d1c73f1 Mon Sep 17 00:00:00 2001 From: Vinh Le Date: Sun, 21 Nov 2021 16:40:49 +0700 Subject: [PATCH] For issue #223 - In the sendPacket() function, when timer is expired mqttwrite() function is not excute. So to give it a change to send ack packet (issue #223), we need to define a minimal timeout - The send packet timeout is defined by MIN_SEND_PACKET_TIMEOUT_MS macro --- MQTTClient-C/src/MQTTClient.c | 5 +++++ MQTTClient-C/src/MQTTClient.h | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/MQTTClient-C/src/MQTTClient.c b/MQTTClient-C/src/MQTTClient.c index bd24dff0..9cae1670 100755 --- a/MQTTClient-C/src/MQTTClient.c +++ b/MQTTClient-C/src/MQTTClient.c @@ -36,6 +36,11 @@ static int sendPacket(MQTTClient* c, int length, Timer* timer) int rc = FAILURE, sent = 0; + if(TimerLeftMS(timer) < MIN_SEND_PACKET_TIMEOUT_MS) + { + TimerInit(timer); + TimerCountdownMS(timer, MIN_SEND_PACKET_TIMEOUT_MS); + } while (sent < length && !TimerIsExpired(timer)) { rc = c->ipstack->mqttwrite(c->ipstack, &c->buf[sent], length, TimerLeftMS(timer)); diff --git a/MQTTClient-C/src/MQTTClient.h b/MQTTClient-C/src/MQTTClient.h index b612341d..920dd47b 100755 --- a/MQTTClient-C/src/MQTTClient.h +++ b/MQTTClient-C/src/MQTTClient.h @@ -51,6 +51,10 @@ #define MAX_MESSAGE_HANDLERS 5 /* redefinable - how many subscriptions do you want? */ #endif +#if !defined(MIN_SEND_PACKET_TIMEOUT_MS) +#define MIN_SEND_PACKET_TIMEOUT_MS 50 /* redefinable - minimal send timeout? */ +#endif + enum QoS { QOS0, QOS1, QOS2, SUBFAIL=0x80 }; /* all failure return codes must be negative */