Skip to content

Commit

Permalink
For issue eclipse-paho#223
Browse files Browse the repository at this point in the history
- In the sendPacket() function, when timer is expired mqttwrite() function is not excute. So to give it a change to send ack packet (issue eclipse-paho#223), we need to define a minimal timeout
- The send packet timeout is defined by MIN_SEND_PACKET_TIMEOUT_MS macro
  • Loading branch information
vinhlq committed Nov 21, 2021
1 parent 29ab2aa commit a78c24c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions MQTTClient-C/src/MQTTClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 4 additions & 0 deletions MQTTClient-C/src/MQTTClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit a78c24c

Please sign in to comment.