Skip to content

Commit 3eb7ab1

Browse files
committed
wip
1 parent 934ab80 commit 3eb7ab1

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,13 @@ bool WiFiClientSecureCtx::_engineConnected() {
260260
}
261261

262262
uint8_t WiFiClientSecureCtx::connected() {
263-
if (!_clientConnected()) {
263+
if (!_engineConnected()) {
264264
return false;
265265
}
266266

267-
return (_updateRecvBuffer() || _engineConnected());
267+
_pollRecvBuffer();
268+
269+
return _engineConnected();
268270
}
269271

270272
int WiFiClientSecureCtx::availableForWrite () {
@@ -353,7 +355,7 @@ int WiFiClientSecureCtx::read(uint8_t *buf, size_t size) {
353355

354356
// will either check the internal buffer, or try to wait for some data
355357
// *may* attempt to write some pending ::write() data b/c of _run_until
356-
int avail = _updateRecvBuffer();
358+
int avail = _pollRecvBuffer();
357359

358360
// internal buffer might still be available for some time
359361
bool engine = _engineConnected();
@@ -412,7 +414,7 @@ int WiFiClientSecureCtx::read() {
412414
return -1;
413415
}
414416

415-
int WiFiClientSecureCtx::_updateRecvBuffer() {
417+
int WiFiClientSecureCtx::_pollRecvBuffer() {
416418
if (_recvapp_buf) {
417419
return _recvapp_len; // Anything from last call?
418420
}
@@ -434,11 +436,11 @@ int WiFiClientSecureCtx::_updateRecvBuffer() {
434436
}
435437

436438
int WiFiClientSecureCtx::available() {
437-
return _updateRecvBuffer();
439+
return _pollRecvBuffer();
438440
}
439441

440442
int WiFiClientSecureCtx::peek() {
441-
if (!ctx_present() || !_updateRecvBuffer()) {
443+
if (!ctx_present() || (0 == _pollRecvBuffer())) {
442444
DEBUG_BSSL("peek: Not connected, none left available\n");
443445
return -1;
444446
}
@@ -457,7 +459,7 @@ size_t WiFiClientSecureCtx::peekBytes(uint8_t *buffer, size_t length) {
457459
}
458460

459461
_startMillis = millis();
460-
while ((_updateRecvBuffer() < (int) length) && ((millis() - _startMillis) < 5000)) {
462+
while ((_pollRecvBuffer() < (int) length) && ((millis() - _startMillis) < 5000)) {
461463
yield();
462464
}
463465

libraries/ESP8266WiFi/src/WiFiClientSecureBearSSL.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,13 @@ class WiFiClientSecureCtx : public WiFiClient {
192192
uint32_t _tls_min;
193193
uint32_t _tls_max;
194194

195-
// Pending received data buffer, used internally & as available()
196-
int _updateRecvBuffer();
197195
unsigned char *_recvapp_buf;
198196
size_t _recvapp_len;
199197

198+
int _pollRecvBuffer(); // If there's a buffer with some pending data, return it's length
199+
// If there's no buffer, poll the engine and store any received data there and return the length
200+
// (which also may change the internal state, e.g. make us disconnected)
201+
200202
bool _clientConnected(); // Is the underlying socket alive?
201203
bool _engineConnected(); // Are both socket and the bearssl engine alive?
202204

0 commit comments

Comments
 (0)