Skip to content

Commit 560c0f4

Browse files
authored
Fix dropped SSL connection when buffer gets full. (#4820)
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.
1 parent 4b3f5c8 commit 560c0f4

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

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

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

305307
return ret;

0 commit comments

Comments
 (0)