Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions components/esp-tls/esp_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,12 @@ static int esp_tls_low_level_conn(const char *hostname, int hostlen, int port, c
switch (tls->conn_state) {
case ESP_TLS_INIT:
tls->sockfd = -1;
if (cfg != NULL && cfg->is_plain_tcp == false) {
_esp_tls_net_init(tls);
tls->is_tls = true;
}
_esp_tls_net_init(tls);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_esp_tls_net_init() is called by esp_tls_init() anyway, no matter if plain or TLS.

It's only job is to set tls->server_fd.fd = -1; for mbedtls. For wolfssl, it is no-op. So it is safe to call it here always, especially, as tls->sockfd = -1; is forced also.

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;
}
if (tls->is_tls == false) {
if (cfg && cfg->is_plain_tcp) {
tls->read = tcp_read;
tls->write = tcp_write;
ESP_LOGD(TAG, "non-tls connection established");
Expand Down
10 changes: 4 additions & 6 deletions components/esp-tls/esp_tls_mbedtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,12 +456,10 @@ void esp_mbedtls_conn_delete(esp_tls_t *tls)
{
if (tls != NULL) {
esp_mbedtls_cleanup(tls);
if (tls->is_tls) {
if (tls->server_fd.fd != -1) {
mbedtls_net_free(&tls->server_fd);
/* Socket is already closed by `mbedtls_net_free` and hence also change assignment of its copy to an invalid value */
tls->sockfd = -1;
}
if (tls->server_fd.fd != -1) {
mbedtls_net_free(&tls->server_fd);
/* Socket is already closed by `mbedtls_net_free` and hence also change assignment of its copy to an invalid value */
tls->sockfd = -1;
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions components/esp-tls/private_include/esp_tls_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ struct esp_tls {

fd_set wset; /*!< write file descriptors */

bool is_tls; /*!< indicates connection type (TLS or NON-TLS) */

esp_tls_role_t role; /*!< esp-tls role
- ESP_TLS_CLIENT
- ESP_TLS_SERVER */
Expand Down