Skip to content

Commit

Permalink
WiFiClientSecure::available fix
Browse files Browse the repository at this point in the history
Attempt to read data from SSL engine inside WiFiClientSecure::available() if RX buffer is empty.
Fix esp8266#784.
  • Loading branch information
igrr committed Sep 16, 2015
1 parent 989eeb5 commit 89df285
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ extern "C"
#define SSL_DEBUG_OPTS 0
#endif

#define SSL_RX_BUF_SIZE 1536

class SSLContext {
public:
SSLContext() {
Expand All @@ -58,7 +60,7 @@ class SSLContext {
}
++_ssl_ctx_refcnt;

_rxbuf = new cbuf(1536);
_rxbuf = new cbuf(SSL_RX_BUF_SIZE);
}

~SSLContext() {
Expand Down Expand Up @@ -112,8 +114,14 @@ class SSLContext {
}

int available() {
optimistic_yield(100);
return _rxbuf->getSize();
auto rc = _rxbuf->getSize();
if (rc == 0) {
_readAll();
rc = _rxbuf->getSize();
} else {
optimistic_yield(100);
}
return rc;
}

operator SSL*() {
Expand Down Expand Up @@ -297,7 +305,7 @@ extern "C" int ax_port_read(int fd, uint8_t* buffer, size_t count) {
errno = EAGAIN;
}
if (cb == 0) {
yield();
optimistic_yield(100);
return -1;
}
return cb;
Expand Down

0 comments on commit 89df285

Please sign in to comment.