Merge branch 'feature/modify_esp_tls_structure' into 'master'

esp-tls: add API to retrieve sockfd for tls connection.

See merge request espressif/esp-idf!7329
This commit is contained in:
Mahavir Jain 2020-01-16 18:12:16 +08:00
commit c7f44a301d
2 changed files with 25 additions and 2 deletions

View file

@ -115,8 +115,9 @@ esp_tls_t *esp_tls_init(void)
return NULL;
}
#ifdef CONFIG_ESP_TLS_USING_MBEDTLS
tls->server_fd.fd = tls->sockfd = -1;
tls->server_fd.fd = -1;
#endif
tls->sockfd = -1;
return tls;
}
@ -309,7 +310,7 @@ static int esp_tls_low_level_conn(const char *hostname, int hostlen, int port, c
*/
esp_tls_t *esp_tls_conn_new(const char *hostname, int hostlen, int port, const esp_tls_cfg_t *cfg)
{
esp_tls_t *tls = (esp_tls_t *)calloc(1, sizeof(esp_tls_t));
esp_tls_t *tls = esp_tls_init();
if (!tls) {
return NULL;
}
@ -432,6 +433,16 @@ ssize_t esp_tls_get_bytes_avail(esp_tls_t *tls)
return _esp_tls_get_bytes_avail(tls);
}
esp_err_t esp_tls_get_conn_sockfd(esp_tls_t *tls, int *sockfd)
{
if (!tls || !sockfd) {
ESP_LOGE(TAG, "Invalid arguments passed");
return ESP_ERR_INVALID_ARG;
}
*sockfd = tls->sockfd;
return ESP_OK;
}
esp_err_t esp_tls_get_and_clear_last_error(esp_tls_error_handle_t h, int *esp_tls_code, int *esp_tls_flags)
{
if (!h) {

View file

@ -477,6 +477,18 @@ void esp_tls_conn_delete(esp_tls_t *tls);
*/
ssize_t esp_tls_get_bytes_avail(esp_tls_t *tls);
/**
* @brief Returns the connection socket file descriptor from esp_tls session
*
* @param[in] tls handle to esp_tls context
*
* @param[out] sockfd int pointer to sockfd value.
*
* @return - ESP_OK on success and value of sockfd will be updated with socket file descriptor for connection
* - ESP_ERR_INVALID_ARG if (tls == NULL || sockfd == NULL)
*/
esp_err_t esp_tls_get_conn_sockfd(esp_tls_t *tls, int *sockfd);
/**
* @brief Create a global CA store, initially empty.
*