Skip to content

Commit fbe67fc

Browse files
committed
fixed regression
1 parent 1b6ac32 commit fbe67fc

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/MQTTClient.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,29 @@ inline lwmqtt_err_t lwmqtt_arduino_network_read(void *ref, uint8_t *buffer, size
3232
// set timeout
3333
uint32_t start = millis();
3434

35-
// read bytes
35+
// reset counter
3636
*read = 0;
37-
while (len && (millis() - start < timeout)) {
37+
38+
// read until all bytes have been read or timeout has been reached
39+
while (len > 0 && (millis() - start < timeout)) {
40+
// read from connection
3841
int r = n->client->read(buffer, len);
39-
if (r > 0) { // read some bytes, advance buffer
42+
43+
// handle read data
44+
if (r > 0) {
4045
buffer += r;
4146
*read += r;
4247
len -= r;
48+
continue;
49+
}
4350

44-
} else if (r < 0) { // negative result - network failure
51+
// otherwise check status
52+
if (!n->client->connected()) {
4553
return LWMQTT_NETWORK_FAILED_READ;
4654
}
4755
}
4856

57+
// check counter
4958
if (*read == 0) {
5059
return LWMQTT_NETWORK_TIMEOUT;
5160
}

src/MQTTClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class MQTTClient {
5757
lwmqtt_err_t _lastError = (lwmqtt_err_t)0;
5858

5959
public:
60-
void * ref = nullptr;
60+
void *ref = nullptr;
6161

6262
explicit MQTTClient(int bufSize = 128);
6363

0 commit comments

Comments
 (0)