Skip to content

Commit 33d8939

Browse files
authored
[2.0.0] Fix dropped SSL connection when buffer gets full. (#4821)
* 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: #2494 * Update ssl_client.cpp Add vTaskDelay()
1 parent b545321 commit 33d8939

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

+6-5
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,12 @@ 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+
}
297+
vTaskDelay(2);
297298
}
298299

299300
return ret;

0 commit comments

Comments
 (0)