Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix subscribe for large payloads #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions paho_mqtt_embedded_c/MQTTClient/src/MQTTClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,10 +473,22 @@ int MQTT::Client<Network, Timer, MAX_MQTT_PACKET_SIZE, b>::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];
Expand Down Expand Up @@ -581,7 +593,6 @@ int MQTT::Client<Network, Timer, a, b>::yield(unsigned long timeout_ms)
return rc;
}


template<class Network, class Timer, int MAX_MQTT_PACKET_SIZE, int b>
int MQTT::Client<Network, Timer, MAX_MQTT_PACKET_SIZE, b>::cycle(Timer& timer)
{
Expand Down