Merge branch 'bugfix/tcp_transport_tls_no_mem' into 'master'

tcp_transport: Fix error handling of esp_tls_init()

Closes IDFGH-4952

See merge request espressif/esp-idf!12822
This commit is contained in:
David Čermák 2021-03-26 18:44:35 +00:00
commit b2a60e0d7c
3 changed files with 9 additions and 0 deletions

View File

@ -57,6 +57,7 @@ enum tcp_transport_errors {
ERR_TCP_TRANSPORT_CONNECTION_CLOSED_BY_FIN,
ERR_TCP_TRANSPORT_CONNECTION_FAILED,
ERR_TCP_TRANSPORT_SETOPT_FAILED,
ERR_TCP_TRANSPORT_NO_MEM,
};
/**

View File

@ -345,6 +345,9 @@ void capture_tcp_transport_error(esp_transport_handle_t t, enum tcp_transport_er
case ERR_TCP_TRANSPORT_SETOPT_FAILED:
err_handle->last_error = ESP_ERR_ESP_TLS_SOCKET_SETOPT_FAILED;
break;
case ERR_TCP_TRANSPORT_NO_MEM:
err_handle->last_error = ESP_ERR_NO_MEM;
break;
}
}

View File

@ -104,6 +104,11 @@ static int esp_tls_connect(esp_transport_handle_t t, const char *host, int port,
ssl->ssl_initialized = true;
ssl->tls = esp_tls_init();
if (ssl->tls == NULL) {
ESP_LOGE(TAG, "Failed to initialize new connection object");
capture_tcp_transport_error(t, ERR_TCP_TRANSPORT_NO_MEM);
return -1;
}
if (esp_tls_conn_new_sync(host, strlen(host), port, &ssl->cfg, ssl->tls) <= 0) {
ESP_LOGE(TAG, "Failed to open a new connection");
esp_transport_set_errors(t, ssl->tls->error_handle);