From 31325f46e97e753e51533bd82b84ed1a2df85193 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:12:54 +0200 Subject: [PATCH 1/2] Revert "Revert 8541 wifi client fix (#267)" This reverts commit 419e0aca05e7d34625971384d59cd31b4f9d3b3a. --- .github/ISSUE_TEMPLATE/Issue-report.yml | 2 -- libraries/WiFi/src/WiFiClient.cpp | 28 +++++++------------------ 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/Issue-report.yml b/.github/ISSUE_TEMPLATE/Issue-report.yml index 7e9a8aea4a2..3628cba1fca 100644 --- a/.github/ISSUE_TEMPLATE/Issue-report.yml +++ b/.github/ISSUE_TEMPLATE/Issue-report.yml @@ -41,8 +41,6 @@ body: options: - latest master (checkout manually) - latest development Release Candidate (RC-X) - - v2.0.13 - - v2.0.12 - v2.0.11 - v2.0.10 - v2.0.9 diff --git a/libraries/WiFi/src/WiFiClient.cpp b/libraries/WiFi/src/WiFiClient.cpp index ee704c2dbca..f666531cf30 100644 --- a/libraries/WiFi/src/WiFiClient.cpp +++ b/libraries/WiFi/src/WiFiClient.cpp @@ -158,6 +158,13 @@ class WiFiClientRxBuffer { size_t available(){ return _fill - _pos + r_available(); } + + void flush(){ + if(r_available()){ + fillBuffer(); + } + _pos = _fill; + } }; class WiFiClientSocketHandle { @@ -529,26 +536,7 @@ 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); + _rxBuffer->flush(); } uint8_t WiFiClient::connected() From 8a5b7838e375e238ff0d8dac7fc8c581e1e1dc45 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:17:59 +0200 Subject: [PATCH 2/2] Bugfix/wificlient (#273) * WiFiClient - Properly initialize and check _rxBuffer --------- Co-authored-by: Me No Dev Co-authored-by: Lucas Saavedra Vaz --- .github/ISSUE_TEMPLATE/Issue-report.yml | 2 ++ libraries/WiFi/src/WiFiClient.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/Issue-report.yml b/.github/ISSUE_TEMPLATE/Issue-report.yml index 3628cba1fca..7e9a8aea4a2 100644 --- a/.github/ISSUE_TEMPLATE/Issue-report.yml +++ b/.github/ISSUE_TEMPLATE/Issue-report.yml @@ -41,6 +41,8 @@ body: options: - latest master (checkout manually) - latest development Release Candidate (RC-X) + - v2.0.13 + - v2.0.12 - v2.0.11 - v2.0.10 - v2.0.9 diff --git a/libraries/WiFi/src/WiFiClient.cpp b/libraries/WiFi/src/WiFiClient.cpp index f666531cf30..d7cfd338b27 100644 --- a/libraries/WiFi/src/WiFiClient.cpp +++ b/libraries/WiFi/src/WiFiClient.cpp @@ -187,7 +187,7 @@ class WiFiClientSocketHandle { } }; -WiFiClient::WiFiClient():_connected(false),_timeout(WIFI_CLIENT_DEF_CONN_TIMEOUT_MS),next(NULL) +WiFiClient::WiFiClient():_rxBuffer(nullptr),_connected(false),_timeout(WIFI_CLIENT_DEF_CONN_TIMEOUT_MS),next(NULL) { } @@ -536,7 +536,9 @@ int WiFiClient::available() // Though flushing means to send all pending data, // seems that in Arduino it also means to clear RX void WiFiClient::flush() { - _rxBuffer->flush(); + if (_rxBuffer != nullptr) { + _rxBuffer->flush(); + } } uint8_t WiFiClient::connected()