Skip to content

Commit a9779a8

Browse files
fix read() logic to correctly return number of bytes 'read' including peeked byte
1 parent c19d5b8 commit a9779a8

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

libraries/WiFiClientSecure/src/WiFiClientSecure.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ size_t WiFiClientSecure::write(const uint8_t *buf, size_t size)
185185

186186
int WiFiClientSecure::read(uint8_t *buf, size_t size)
187187
{
188-
int peeked = 0;
189188
if ((!buf && size) || (_peek < 0 && !available())) {
190189
return -1;
191190
}
@@ -196,19 +195,16 @@ int WiFiClientSecure::read(uint8_t *buf, size_t size)
196195
buf[0] = _peek;
197196
_peek = -1;
198197
size--;
199-
if(!size || !available()){
200-
return 1;
201-
}
202-
buf++;
203-
peeked = 1;
198+
int ret = read(buf+1, size-1);
199+
return 1 + ((ret > 0) ? ret : 0);
204200
}
205201

206202
int res = get_ssl_receive(sslclient, buf, size);
207203
if (res < 0) {
208204
stop();
209205
return res;
210206
}
211-
return res + peeked;
207+
return res;
212208
}
213209

214210
int WiFiClientSecure::available()

0 commit comments

Comments
 (0)