From ab8ddaa7ca3899b734ea7f56074d0151a7d9a4df Mon Sep 17 00:00:00 2001 From: Takashi Matsuoka Date: Fri, 14 May 2021 18:06:39 +0900 Subject: [PATCH] Fix subscribe for large payloads --- .../MQTTClient/src/MQTTClient.h | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/paho_mqtt_embedded_c/MQTTClient/src/MQTTClient.h b/paho_mqtt_embedded_c/MQTTClient/src/MQTTClient.h index e15a2fa..7467237 100644 --- a/paho_mqtt_embedded_c/MQTTClient/src/MQTTClient.h +++ b/paho_mqtt_embedded_c/MQTTClient/src/MQTTClient.h @@ -473,10 +473,22 @@ int MQTT::Client::readPacket(Timer& tim } /* 3. read the rest of the buffer using a callback to supply the rest of the data */ - if (rem_len > 0 && (ipstack.read(readbuf + len, rem_len, timer.left_ms()) != rem_len)) + while (rem_len > 0) { - rc = FAILURE; - goto exit; + const int read_len = ipstack.read(readbuf + len, rem_len, timer.left_ms()); + if (read_len < 0 || rem_len < read_len) // Error + { + rc = FAILURE; + goto exit; + } + if (read_len == 0) // Time out + { + rc = 0; + goto exit; + } + + len += read_len; + rem_len -= read_len; } header.byte = readbuf[0]; @@ -581,7 +593,6 @@ int MQTT::Client::yield(unsigned long timeout_ms) return rc; } - template int MQTT::Client::cycle(Timer& timer) {