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 */