From 7e40de226fee6ef7189e9f024ef373dff581a777 Mon Sep 17 00:00:00 2001 From: M Hotchin <35244463+MHotchin@users.noreply.github.com> Date: Tue, 27 Oct 2020 03:01:41 -0700 Subject: [PATCH] Fixes #4435 - WiFiClient improperly treats zero data available for read as an error (#4448) --- libraries/WiFi/src/WiFiClient.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/WiFi/src/WiFiClient.cpp b/libraries/WiFi/src/WiFiClient.cpp index e422b636..52df2731 100644 --- a/libraries/WiFi/src/WiFiClient.cpp +++ b/libraries/WiFi/src/WiFiClient.cpp @@ -105,7 +105,7 @@ public: int read(uint8_t * dst, size_t len){ if(!dst || !len || (_pos == _fill && !fillBuffer())){ - return -1; + return _failed ? -1 : 0; } size_t a = _fill - _pos; if(len <= a || ((len - a) <= (_size - _fill) && fillBuffer() >= (len - a))){ @@ -346,6 +346,9 @@ int WiFiClient::read() if(res < 0) { return res; } + if (res == 0) { // No data available. + return -1; + } return data; }