Skip to content

Commit 235500c

Browse files
authored
Fix dropped SSL connection when buffer gets full.
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. Fixes: espressif/arduino-esp32#2494
1 parent beedeea commit 235500c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Diff for: libraries/WiFiClientSecure/src/ssl_client.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,11 @@ int send_ssl_data(sslclient_context *ssl_client, const uint8_t *data, uint16_t l
289289
log_v("Writing HTTP request with %d bytes...", len); //for low level debug
290290
int ret = -1;
291291

292-
if ((ret = mbedtls_ssl_write(&ssl_client->ssl_ctx, data, len)) <= 0){
293-
log_v("Handling error %d", ret); //for low level debug
294-
return handle_error(ret);
295-
} else{
296-
log_v("Returning with %d bytes written", ret); //for low level debug
292+
while ((ret = mbedtls_ssl_write(&ssl_client->ssl_ctx, data, len)) <= 0) {
293+
if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE && ret < 0) {
294+
log_v("Handling error %d", ret); //for low level debug
295+
return handle_error(ret);
296+
}
297297
}
298298

299299
return ret;

0 commit comments

Comments
 (0)