Skip to content

Commit 89df285

Browse files
committed
WiFiClientSecure::available fix
Attempt to read data from SSL engine inside WiFiClientSecure::available() if RX buffer is empty. Fix #784.
1 parent 989eeb5 commit 89df285

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

hardware/esp8266com/esp8266/libraries/ESP8266WiFi/src/WiFiClientSecure.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ extern "C"
5050
#define SSL_DEBUG_OPTS 0
5151
#endif
5252

53+
#define SSL_RX_BUF_SIZE 1536
54+
5355
class SSLContext {
5456
public:
5557
SSLContext() {
@@ -58,7 +60,7 @@ class SSLContext {
5860
}
5961
++_ssl_ctx_refcnt;
6062

61-
_rxbuf = new cbuf(1536);
63+
_rxbuf = new cbuf(SSL_RX_BUF_SIZE);
6264
}
6365

6466
~SSLContext() {
@@ -112,8 +114,14 @@ class SSLContext {
112114
}
113115

114116
int available() {
115-
optimistic_yield(100);
116-
return _rxbuf->getSize();
117+
auto rc = _rxbuf->getSize();
118+
if (rc == 0) {
119+
_readAll();
120+
rc = _rxbuf->getSize();
121+
} else {
122+
optimistic_yield(100);
123+
}
124+
return rc;
117125
}
118126

119127
operator SSL*() {
@@ -297,7 +305,7 @@ extern "C" int ax_port_read(int fd, uint8_t* buffer, size_t count) {
297305
errno = EAGAIN;
298306
}
299307
if (cb == 0) {
300-
yield();
308+
optimistic_yield(100);
301309
return -1;
302310
}
303311
return cb;

0 commit comments

Comments
 (0)