Skip to content

Commit

Permalink
Always try sendPacket at least once, as in the C++ client eclipse-pah…
Browse files Browse the repository at this point in the history
  • Loading branch information
icraggs authored and CIPop committed Aug 11, 2023
1 parent 023f9a8 commit 3273a8e
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 3273a8e

Please sign in to comment.