From 5fa7baf22719804fbdaae8afa0a11d1ef3c93ce8 Mon Sep 17 00:00:00 2001 From: Ian Craggs Date: Fri, 4 Mar 2022 10:50:29 +0000 Subject: [PATCH] If first round of commit retries doesn't finish, complete it later #1203 --- src/MQTTProtocolClient.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/MQTTProtocolClient.c b/src/MQTTProtocolClient.c index 2f73e0b9..102c65fc 100644 --- a/src/MQTTProtocolClient.c +++ b/src/MQTTProtocolClient.c @@ -751,12 +751,20 @@ void MQTTProtocol_keepalive(START_TIME_TYPE now) static void MQTTProtocol_retries(START_TIME_TYPE now, Clients* client, int regardless) { ListElement* outcurrent = NULL; + static int connect_count = 0; + static int connect_sent = 0; FUNC_ENTRY; - if (!regardless && client->retryInterval <= 0) /* 0 or -ive retryInterval turns off retry except on reconnect */ + if (!regardless && client->retryInterval <= 0 && /* 0 or -ive retryInterval turns off retry except on reconnect */ + connect_sent == connect_count) goto exit; + if (regardless) + connect_count = client->outboundMsgs->count; /* remember the number of messages to retry on connect */ + else if (connect_sent < connect_count) /* continue a connect retry which didn't complete first time around */ + regardless = 1; + while (client && ListNextElement(client->outboundMsgs, &outcurrent) && client->connected && client->good && /* client is connected and has no errors */ Socket_noPendingWrites(client->net.socket)) /* there aren't any previous packets still stacked up on the socket */ @@ -764,6 +772,8 @@ static void MQTTProtocol_retries(START_TIME_TYPE now, Clients* client, int regar Messages* m = (Messages*)(outcurrent->content); if (regardless || MQTTTime_difftime(now, m->lastTouch) > (DIFF_TIME_TYPE)(max(client->retryInterval, 10) * 1000)) { + if (regardless) + ++connect_sent; if (m->qos == 1 || (m->qos == 2 && m->nextMessageType == PUBREC)) { Publish publish; @@ -808,7 +818,6 @@ static void MQTTProtocol_retries(START_TIME_TYPE now, Clients* client, int regar else m->lastTouch = MQTTTime_now(); } - /* break; why not do all retries at once? */ } } exit: