Skip to content

Commit

Permalink
esp-tls: Added getter/setter function for the conn_state.
Browse files Browse the repository at this point in the history
* Added the setter function to set the connection sockfd value
Closes #10871
  • Loading branch information
AdityaHPatwardhan committed Apr 24, 2023
1 parent d020a58 commit e24e674
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
30 changes: 30 additions & 0 deletions components/esp-tls/esp_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,36 @@ esp_err_t esp_tls_get_conn_sockfd(esp_tls_t *tls, int *sockfd)
return ESP_OK;
}

esp_err_t esp_tls_set_conn_sockfd(esp_tls_t *tls, int sockfd)
{
if (!tls || sockfd < 0) {
ESP_LOGE(TAG, "Invalid arguments passed");
return ESP_ERR_INVALID_ARG;
}
tls->sockfd = sockfd;
return ESP_OK;
}

esp_err_t esp_tls_get_conn_state(esp_tls_t *tls, esp_tls_conn_state_t *conn_state)
{
if (!tls || !conn_state) {
ESP_LOGE(TAG, "Invalid arguments passed");
return ESP_ERR_INVALID_ARG;
}
*conn_state = tls->conn_state;
return ESP_OK;
}

esp_err_t esp_tls_set_conn_state(esp_tls_t *tls, esp_tls_conn_state_t conn_state)
{
if (!tls || conn_state < ESP_TLS_INIT || conn_state > ESP_TLS_DONE) {
ESP_LOGE(TAG, "Invalid arguments passed");
return ESP_ERR_INVALID_ARG;
}
tls->conn_state = conn_state;
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) {
Expand Down
36 changes: 36 additions & 0 deletions components/esp-tls/esp_tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,42 @@ ssize_t esp_tls_get_bytes_avail(esp_tls_t *tls);
*/
esp_err_t esp_tls_get_conn_sockfd(esp_tls_t *tls, int *sockfd);

/**
* @brief Sets the connection socket file descriptor for the esp_tls session
*
* @param[in] tls handle to esp_tls context
*
* @param[in] sockfd sockfd value to set.
*
* @return - ESP_OK on success and value of sockfd for the tls connection shall updated withthe provided value
* - ESP_ERR_INVALID_ARG if (tls == NULL || sockfd < 0)
*/
esp_err_t esp_tls_set_conn_sockfd(esp_tls_t *tls, int sockfd);

/**
* @brief Gets the connection state for the esp_tls session
*
* @param[in] tls handle to esp_tls context
*
* @param[out] conn_state pointer to the connection state value.
*
* @return - ESP_OK on success and value of sockfd for the tls connection shall updated withthe provided value
* - ESP_ERR_INVALID_ARG (Invalid arguments)
*/
esp_err_t esp_tls_get_conn_state(esp_tls_t *tls, esp_tls_conn_state_t *conn_state);

/**
* @brief Sets the connection state for the esp_tls session
*
* @param[in] tls handle to esp_tls context
*
* @param[in] conn_state connection state value to set.
*
* @return - ESP_OK on success and value of sockfd for the tls connection shall updated withthe provided value
* - ESP_ERR_INVALID_ARG (Invalid arguments)
*/
esp_err_t esp_tls_set_conn_state(esp_tls_t *tls, esp_tls_conn_state_t conn_state);

/**
* @brief Returns the ssl context
*
Expand Down

0 comments on commit e24e674

Please sign in to comment.