Skip to content
Merged
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern "C" {
}
#include "debug.h"
#include "ESP8266WiFi.h"
#include "PolledTimeout.h"
#include "WiFiClient.h"
#include "WiFiClientSecureBearSSL.h"
#include "StackThunk.h"
Expand Down Expand Up @@ -437,12 +438,17 @@ int WiFiClientSecure::_run_until(unsigned target, bool blocking) {
DEBUG_BSSL("_run_until: Not connected\n");
return -1;
}
for (int no_work = 0; blocking || no_work < 2;) {
if (blocking) {
// Only for blocking operations can we afford to yield()
optimistic_yield(100);

esp8266::polledTimeout::oneShotMs loopTimeout(_timeout);

for (int no_work = 0; blocking || no_work < 2;) {
optimistic_yield(100);

if (loopTimeout) {
DEBUG_BSSL("_run_until: Timeout\n");
return -1;
}

int state;
state = br_ssl_engine_current_state(_eng);
if (state & BR_SSL_CLOSED) {
Expand All @@ -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) {
/*
Expand Down