Merge branch 'bugfix/esp_tls_blocking_timeout_v3.3' into 'release/v3.3'

esp-tls: add timeout for blocking connection (v3.3)

See merge request espressif/esp-idf!7397
This commit is contained in:
Angus Gratton 2020-01-22 11:44:01 +08:00
commit f8151b2bfe

View file

@ -481,6 +481,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()
API returns only after connection is established unless there is an error*/
size_t start = xTaskGetTickCount();
while (1) {
int ret = esp_tls_low_level_conn(hostname, hostlen, port, cfg, tls);
if (ret == 1) {
@ -489,6 +490,14 @@ esp_tls_t *esp_tls_conn_new(const char *hostname, int hostlen, int port, const e
esp_tls_conn_delete(tls);
ESP_LOGE(TAG, "Failed to open new connection");
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;