From 529baabef83b25453ebefecab2ce313bbfe8df07 Mon Sep 17 00:00:00 2001 From: "Earle F. Philhower, III" Date: Wed, 23 May 2018 08:24:34 -0700 Subject: [PATCH] Return data in internal SSL buffers after close (#4756) When the TCP socket is closed there may be some data left in the BearSSL internal buffers which can be read by the application. The BearSSL pump, however, would always return no data available in the case the socket was disconnected before checking if the SSL was in a state where the app could possibly read. Fix by returning if the state is available, even if the connection is gone. Eventually no more data will become available to read and the original -1 will be returned. This should match the existing axTLS ::connected() behavior. --- libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp index 5e641a678..6aebf1f6c 100644 --- a/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp +++ b/libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp @@ -228,8 +228,7 @@ bool WiFiClientSecure::_clientConnected() { } uint8_t WiFiClientSecure::connected() { - if (WiFiClient::connected() || available() || - (_clientConnected() && _handshake_done)) { + if (available() || (_clientConnected() && _handshake_done)) { return true; } return false; @@ -398,7 +397,7 @@ int WiFiClientSecure::_run_until(unsigned target, bool blocking) { } if (!(_client->state() == ESTABLISHED) && !WiFiClient::available()) { - return -1; + return (state & target) ? 0 : -1; } /*