mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Fix WiFiClientSecure::available() blocking on dropped connections (#6449)
* Fix WiFiClientSecure::available blocking Added a check of WiFiClient::availableForWrite to prevent blocking writes when the _run_until blocking flag is false * change availForWrite from int to size_t * add timeout to _run_until loop fixes #6464 * use polledTimeout with _timeout millis
This commit is contained in:
parent
f2de9e130c
commit
5d609fd294
@ -32,6 +32,7 @@ extern "C" {
|
||||
}
|
||||
#include "debug.h"
|
||||
#include "ESP8266WiFi.h"
|
||||
#include "PolledTimeout.h"
|
||||
#include "WiFiClient.h"
|
||||
#include "WiFiClientSecureBearSSL.h"
|
||||
#include "StackThunk.h"
|
||||
@ -437,10 +438,15 @@ int WiFiClientSecure::_run_until(unsigned target, bool blocking) {
|
||||
DEBUG_BSSL("_run_until: Not connected\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
esp8266::polledTimeout::oneShotMs loopTimeout(_timeout);
|
||||
|
||||
for (int no_work = 0; blocking || no_work < 2;) {
|
||||
if (blocking) {
|
||||
// Only for blocking operations can we afford to yield()
|
||||
optimistic_yield(100);
|
||||
|
||||
if (loopTimeout) {
|
||||
DEBUG_BSSL("_run_until: Timeout\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
int state;
|
||||
@ -461,8 +467,19 @@ int WiFiClientSecure::_run_until(unsigned target, bool blocking) {
|
||||
unsigned char *buf;
|
||||
size_t len;
|
||||
int wlen;
|
||||
size_t availForWrite;
|
||||
|
||||
buf = br_ssl_engine_sendrec_buf(_eng, &len);
|
||||
availForWrite = WiFiClient::availableForWrite();
|
||||
|
||||
if (!blocking && len > availForWrite) {
|
||||
/*
|
||||
writes on WiFiClient will block if len > availableForWrite()
|
||||
this is needed to prevent available() calls from blocking
|
||||
on dropped connections
|
||||
*/
|
||||
len = availForWrite;
|
||||
}
|
||||
wlen = WiFiClient::write(buf, len);
|
||||
if (wlen <= 0) {
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user