If first round of commit retries doesn't finish, complete it later #1203

This commit is contained in:
Ian Craggs 2022-03-04 10:50:29 +00:00
parent 5bf0e00ea2
commit 5fa7baf227
1 changed files with 11 additions and 2 deletions

View File

@ -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: