From 4c4a6b8d3777857f1c08de4d401f1b608fc8dae3 Mon Sep 17 00:00:00 2001 From: Tomas Pilny Date: Fri, 18 Aug 2023 14:10:31 +0200 Subject: [PATCH 1/2] Reimplemented flush in WiFiClient --- libraries/WiFi/src/WiFiClient.cpp | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/libraries/WiFi/src/WiFiClient.cpp b/libraries/WiFi/src/WiFiClient.cpp index 9e2a85f5dea..23484ae30b6 100644 --- a/libraries/WiFi/src/WiFiClient.cpp +++ b/libraries/WiFi/src/WiFiClient.cpp @@ -153,6 +153,13 @@ class WiFiClientRxBuffer { size_t available(){ return _fill - _pos + r_available(); } + + void flush(){ + if(r_available()){ + fillBuffer(); + } + _pos = _fill; + } }; class WiFiClientSocketHandle { @@ -501,26 +508,8 @@ int WiFiClient::available() // Though flushing means to send all pending data, // seems that in Arduino it also means to clear RX void WiFiClient::flush() { - int res; - size_t a = available(), toRead = 0; - if(!a){ - return;//nothing to flush - } - uint8_t * buf = (uint8_t *)malloc(WIFI_CLIENT_FLUSH_BUFFER_SIZE); - if(!buf){ - return;//memory error - } - while(a){ - toRead = (a>WIFI_CLIENT_FLUSH_BUFFER_SIZE)?WIFI_CLIENT_FLUSH_BUFFER_SIZE:a; - res = recv(fd(), buf, toRead, MSG_DONTWAIT); - if(res < 0) { - log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno)); - stop(); - break; - } - a -= res; - } - free(buf); +#ifdef ARDUINO_DEBUG_LEVEL + _rxBuffer->flush(); } uint8_t WiFiClient::connected() From dd091755eeb451c12685280c2d1e99aab3d797c4 Mon Sep 17 00:00:00 2001 From: Tomas Pilny Date: Fri, 18 Aug 2023 15:02:20 +0200 Subject: [PATCH 2/2] Removed forgotten #ifdef --- libraries/WiFi/src/WiFiClient.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/WiFi/src/WiFiClient.cpp b/libraries/WiFi/src/WiFiClient.cpp index 23484ae30b6..85c348327dc 100644 --- a/libraries/WiFi/src/WiFiClient.cpp +++ b/libraries/WiFi/src/WiFiClient.cpp @@ -508,7 +508,6 @@ int WiFiClient::available() // Though flushing means to send all pending data, // seems that in Arduino it also means to clear RX void WiFiClient::flush() { -#ifdef ARDUINO_DEBUG_LEVEL _rxBuffer->flush(); }