Skip to content

Commit 529baab

Browse files
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.
1 parent 9b5f3c2 commit 529baab

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ bool WiFiClientSecure::_clientConnected() {
228228
}
229229

230230
uint8_t WiFiClientSecure::connected() {
231-
if (WiFiClient::connected() || available() ||
232-
(_clientConnected() && _handshake_done)) {
231+
if (available() || (_clientConnected() && _handshake_done)) {
233232
return true;
234233
}
235234
return false;
@@ -398,7 +397,7 @@ int WiFiClientSecure::_run_until(unsigned target, bool blocking) {
398397
}
399398

400399
if (!(_client->state() == ESTABLISHED) && !WiFiClient::available()) {
401-
return -1;
400+
return (state & target) ? 0 : -1;
402401
}
403402

404403
/*

0 commit comments

Comments
 (0)