Skip to content

Commit 85ff99d

Browse files
author
blue-2357
committed
Flush client with single call to available
1 parent bdc5b8a commit 85ff99d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Diff for: libraries/WiFi/src/WiFiClient.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ int WiFiClient::available()
255255
// Though flushing means to send all pending data,
256256
// seems that in Arduino it also means to clear RX
257257
void WiFiClient::flush() {
258+
int res;
258259
size_t a = available(), toRead = 0;
259260
if(!a){
260261
return;//nothing to flush
@@ -265,12 +266,13 @@ void WiFiClient::flush() {
265266
}
266267
while(a){
267268
toRead = (a>WIFI_CLIENT_FLUSH_BUFFER_SIZE)?WIFI_CLIENT_FLUSH_BUFFER_SIZE:a;
268-
if(recv(fd(), buf, toRead, MSG_DONTWAIT) < 0) {
269+
res = recv(fd(), buf, toRead, MSG_DONTWAIT);
270+
if(res < 0) {
269271
log_e("%d", errno);
270272
stop();
271273
break;
272274
}
273-
a = available();
275+
a -= res;
274276
}
275277
free(buf);
276278
}

0 commit comments

Comments
 (0)