Skip to content

Commit

Permalink
Always try sendPacket at least once, as in the C++ client #223
Browse files Browse the repository at this point in the history
  • Loading branch information
icraggs committed Aug 1, 2023
1 parent 0792363 commit 5e5cae6
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions MQTTClient-C/src/MQTTClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ static int sendPacket(MQTTClient* c, int32_t length, Timer* timer)
int rc = MQTTCLIENT_FAILURE,
sent = 0;

while (sent < length && !TimerIsExpired(timer))
while (sent < length)
{
rc = c->ipstack->mqttwrite(c->ipstack, &c->buf[sent], length - sent, TimerLeftMS(timer));
if (rc < 0) // there was an error writing the data
if (rc < 0) /* there was an error writing the data */
break;
sent += rc;
if (TimerIsExpired(timer)) /* only check expiry after at least one attempt to write */
break;
}
if (sent == length)
{
TimerCountdown(&c->last_sent, c->keepAliveInterval); // record the fact that we have successfully sent the packet
TimerCountdown(&c->last_sent, c->keepAliveInterval); /* record the fact that we have successfully sent the packet */
rc = MQTTCLIENT_SUCCESS;
}
else
Expand Down

0 comments on commit 5e5cae6

Please sign in to comment.