Skip to content

Commit

Permalink
Fix dropped SSL connection when buffer gets full. (#4820)
Browse files Browse the repository at this point in the history
mbedTLS requires repeated calls to mbedtls_ssl_write() whenever it returns MBEDTLS_ERR_SSL_WANT_READ or MBEDTLS_ERR_SSL_WANT_WRITE. this happens when the client sends data faster then the server or the connection can handle.
  • Loading branch information
everslick authored Feb 22, 2021
1 parent 4b3f5c8 commit 560c0f4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions libraries/WiFiClientSecure/src/ssl_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,13 @@ int send_ssl_data(sslclient_context *ssl_client, const uint8_t *data, uint16_t l
log_v("Writing HTTP request with %d bytes...", len); //for low level debug
int ret = -1;

if ((ret = mbedtls_ssl_write(&ssl_client->ssl_ctx, data, len)) <= 0){
log_v("Handling error %d", ret); //for low level debug
return handle_error(ret);
} else{
log_v("Returning with %d bytes written", ret); //for low level debug
while ((ret = mbedtls_ssl_write(&ssl_client->ssl_ctx, data, len)) <= 0) {
if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE && ret < 0) {
log_v("Handling error %d", ret); //for low level debug
return handle_error(ret);
}
//wait for space to become available
vTaskDelay(2);
}

return ret;
Expand Down

0 comments on commit 560c0f4

Please sign in to comment.