Flush client with single call to available

This commit is contained in:
me-no-dev 2017-03-03 14:56:18 +02:00
parent 1058e89dc3
commit 8fb8478431

View File

@ -255,6 +255,7 @@ int WiFiClient::available()
// Though flushing means to send all pending data, // Though flushing means to send all pending data,
// seems that in Arduino it also means to clear RX // seems that in Arduino it also means to clear RX
void WiFiClient::flush() { void WiFiClient::flush() {
int res;
size_t a = available(), toRead = 0; size_t a = available(), toRead = 0;
if(!a){ if(!a){
return;//nothing to flush return;//nothing to flush
@ -265,12 +266,13 @@ void WiFiClient::flush() {
} }
while(a){ while(a){
toRead = (a>WIFI_CLIENT_FLUSH_BUFFER_SIZE)?WIFI_CLIENT_FLUSH_BUFFER_SIZE:a; toRead = (a>WIFI_CLIENT_FLUSH_BUFFER_SIZE)?WIFI_CLIENT_FLUSH_BUFFER_SIZE:a;
if(recv(fd(), buf, toRead, MSG_DONTWAIT) < 0) { res = recv(fd(), buf, toRead, MSG_DONTWAIT);
if(res < 0) {
log_e("%d", errno); log_e("%d", errno);
stop(); stop();
break; break;
} }
a = available(); a -= res;
} }
free(buf); free(buf);
} }