esp_tls: fail connection if esp_tls_conn_new() timeouts
This commit is contained in:
parent
463a9d8b7f
commit
e0c88dbd73
1 changed files with 9 additions and 0 deletions
|
@ -665,6 +665,7 @@ esp_tls_t *esp_tls_conn_new(const char *hostname, int hostlen, int port, const e
|
||||||
}
|
}
|
||||||
/* esp_tls_conn_new() API establishes connection in a blocking manner thus this loop ensures that esp_tls_conn_new()
|
/* esp_tls_conn_new() API establishes connection in a blocking manner thus this loop ensures that esp_tls_conn_new()
|
||||||
API returns only after connection is established unless there is an error*/
|
API returns only after connection is established unless there is an error*/
|
||||||
|
size_t start = xTaskGetTickCount();
|
||||||
while (1) {
|
while (1) {
|
||||||
int ret = esp_tls_low_level_conn(hostname, hostlen, port, cfg, tls);
|
int ret = esp_tls_low_level_conn(hostname, hostlen, port, cfg, tls);
|
||||||
if (ret == 1) {
|
if (ret == 1) {
|
||||||
|
@ -673,6 +674,14 @@ esp_tls_t *esp_tls_conn_new(const char *hostname, int hostlen, int port, const e
|
||||||
esp_tls_conn_delete(tls);
|
esp_tls_conn_delete(tls);
|
||||||
ESP_LOGE(TAG, "Failed to open new connection");
|
ESP_LOGE(TAG, "Failed to open new connection");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
} else if (ret == 0 && cfg->timeout_ms >= 0) {
|
||||||
|
size_t timeout_ticks = pdMS_TO_TICKS(cfg->timeout_ms);
|
||||||
|
uint32_t expired = xTaskGetTickCount() - start;
|
||||||
|
if (expired >= timeout_ticks) {
|
||||||
|
esp_tls_conn_delete(tls);
|
||||||
|
ESP_LOGE(TAG, "Failed to open new connection in specified timeout");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
Loading…
Reference in a new issue