esp_tls: Make esp_tls_t as private structure.

This commit is contained in:
Aditya Patwardhan
2022-04-20 08:09:13 +05:30
committed by BOT
parent 523c51818c
commit 434e74ff73
9 changed files with 180 additions and 76 deletions
+30 -7
View File
@@ -76,7 +76,11 @@ static int esp_tls_connect_async(esp_transport_handle_t t, const char *host, int
if (ssl->conn_state == TRANS_SSL_CONNECTING) {
int progress = esp_tls_conn_new_async(host, strlen(host), port, &ssl->cfg, ssl->tls);
if (progress >= 0) {
ssl->sockfd = ssl->tls->sockfd;
if (esp_tls_get_conn_sockfd(ssl->tls, &ssl->sockfd) != ESP_OK) {
ESP_LOGE(TAG, "Error in obtaining socket fd for the session");
esp_tls_conn_destroy(ssl->tls);
return -1;
}
}
return progress;
@@ -110,14 +114,23 @@ static int ssl_connect(esp_transport_handle_t t, const char *host, int port, int
}
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);
esp_tls_error_handle_t esp_tls_error_handle;
esp_tls_get_error_handle(ssl->tls, &esp_tls_error_handle);
esp_transport_set_errors(t, esp_tls_error_handle);
goto exit_failure;
}
if (esp_tls_get_conn_sockfd(ssl->tls, &ssl->sockfd) != ESP_OK) {
ESP_LOGE(TAG, "Error in obtaining socket fd for the session");
goto exit_failure;
}
return 0;
exit_failure:
esp_tls_conn_destroy(ssl->tls);
ssl->tls = NULL;
ssl->sockfd = INVALID_SOCKET;
return -1;
}
ssl->sockfd = ssl->tls->sockfd;
return 0;
}
static int tcp_connect(esp_transport_handle_t t, const char *host, int port, int timeout_ms)
@@ -200,7 +213,12 @@ static int ssl_write(esp_transport_handle_t t, const char *buffer, int len, int
int ret = esp_tls_conn_write(ssl->tls, (const unsigned char *) buffer, len);
if (ret < 0) {
ESP_LOGE(TAG, "esp_tls_conn_write error, errno=%s", strerror(errno));
esp_transport_set_errors(t, ssl->tls->error_handle);
esp_tls_error_handle_t esp_tls_error_handle;
if (esp_tls_get_error_handle(ssl->tls, &esp_tls_error_handle) == ESP_OK) {
esp_transport_set_errors(t, esp_tls_error_handle);
} else {
ESP_LOGE(TAG, "Error in obtaining the error handle");
}
}
return ret;
}
@@ -233,7 +251,12 @@ static int ssl_read(esp_transport_handle_t t, char *buffer, int len, int timeout
int ret = esp_tls_conn_read(ssl->tls, (unsigned char *)buffer, len);
if (ret < 0) {
ESP_LOGE(TAG, "esp_tls_conn_read error, errno=%s", strerror(errno));
esp_transport_set_errors(t, ssl->tls->error_handle);
esp_tls_error_handle_t esp_tls_error_handle;
if (esp_tls_get_error_handle(ssl->tls, &esp_tls_error_handle) == ESP_OK) {
esp_transport_set_errors(t, esp_tls_error_handle);
} else {
ESP_LOGE(TAG, "Error in obtaining the error handle");
}
}
if (ret == 0) {
if (poll > 0) {