Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
handle reading zero-length packets
  • Loading branch information
brentru committed Aug 17, 2018
commit 81cb29a3053d76415708d6e8c041f72e7da10ebd
6 changes: 6 additions & 0 deletions Adafruit_MQTT_Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint16_t maxlen,
uint16_t len = 0;
int16_t t = timeout;


while (client->connected() && (timeout >= 0)) {
//DEBUG_PRINT('.');
while (client->available()) {
Expand All @@ -62,6 +63,11 @@ uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint16_t maxlen,
buffer[len] = c;
//DEBUG_PRINTLN((uint8_t)c, HEX);
len++;

if (maxlen == 0) { // handle zero-length packets
return 0;
}

if (len == maxlen) { // we read all we want, bail
DEBUG_PRINT(F("Read data:\t"));
DEBUG_PRINTBUFFER(buffer, len);
Expand Down