esp_tls: Renamed public API to indicate the Plain TCP connection

Also added parameter checks if used from as a public API
and updated the `is_plein_tcp` description that it's possible to connect
directly using plain tcp transport with the new API.
This commit is contained in:
David Cermak
2021-05-19 12:58:06 +02:00
parent 38fd2ed10b
commit f68d7d7023
3 changed files with 20 additions and 5 deletions

View File

@@ -267,7 +267,7 @@ static esp_err_t esp_tls_set_socket_non_blocking(int fd, bool non_blocking)
return ESP_OK;
}
esp_err_t esp_tls_tcp_connect(const char *host, int hostlen, int port, const esp_tls_cfg_t *cfg, esp_tls_error_handle_t error_handle, int *sockfd)
static inline esp_err_t tcp_connect(const char *host, int hostlen, int port, const esp_tls_cfg_t *cfg, esp_tls_error_handle_t error_handle, int *sockfd)
{
struct sockaddr_storage address;
int fd;
@@ -371,7 +371,7 @@ static int esp_tls_low_level_conn(const char *hostname, int hostlen, int port, c
_esp_tls_net_init(tls);
tls->is_tls = true;
}
if ((esp_ret = esp_tls_tcp_connect(hostname, hostlen, port, cfg, tls->error_handle, &tls->sockfd)) != ESP_OK) {
if ((esp_ret = tcp_connect(hostname, hostlen, port, cfg, tls->error_handle, &tls->sockfd)) != ESP_OK) {
ESP_INT_EVENT_TRACKER_CAPTURE(tls->error_handle, ESP_TLS_ERR_TYPE_ESP, esp_ret);
return -1;
}
@@ -440,6 +440,17 @@ static int esp_tls_low_level_conn(const char *hostname, int hostlen, int port, c
return -1;
}
/**
* @brief Create a new plain TCP connection
*/
esp_err_t esp_tls_plain_tcp_connect(const char *host, int hostlen, int port, const esp_tls_cfg_t *cfg, esp_tls_error_handle_t error_handle, int *sockfd)
{
if (sockfd == NULL || error_handle == NULL) {
return ESP_ERR_INVALID_ARG;
}
return tcp_connect(host, hostlen, port, cfg, error_handle, sockfd);
}
/**
* @brief Create a new TLS/SSL connection
*/