提交 8fb84784 编写于 作者: M me-no-dev

Flush client with single call to available

上级 1058e89d
...@@ -255,6 +255,7 @@ int WiFiClient::available() ...@@ -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() { ...@@ -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);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册