esp-tls: Separate timeout_ms conditional judgement from keep alive

This commit is contained in:
yuanjm
2021-02-19 19:38:50 +08:00
committed by bot
parent a412eb867c
commit f68e55edb3

View File

@@ -196,16 +196,18 @@ static void ms_to_timeval(int timeout_ms, struct timeval *tv)
static esp_err_t esp_tls_set_socket_options(int fd, const esp_tls_cfg_t *cfg) static esp_err_t esp_tls_set_socket_options(int fd, const esp_tls_cfg_t *cfg)
{ {
if (cfg && cfg->timeout_ms >= 0) { if (cfg) {
struct timeval tv; if (cfg->timeout_ms >= 0) {
ms_to_timeval(cfg->timeout_ms, &tv); struct timeval tv;
if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) != 0) { ms_to_timeval(cfg->timeout_ms, &tv);
ESP_LOGE(TAG, "Fail to setsockopt SO_RCVTIMEO"); if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) != 0) {
return ESP_ERR_ESP_TLS_SOCKET_SETOPT_FAILED; ESP_LOGE(TAG, "Fail to setsockopt SO_RCVTIMEO");
} return ESP_ERR_ESP_TLS_SOCKET_SETOPT_FAILED;
if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) != 0) { }
ESP_LOGE(TAG, "Fail to setsockopt SO_SNDTIMEO"); if (setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) != 0) {
return ESP_ERR_ESP_TLS_SOCKET_SETOPT_FAILED; ESP_LOGE(TAG, "Fail to setsockopt SO_SNDTIMEO");
return ESP_ERR_ESP_TLS_SOCKET_SETOPT_FAILED;
}
} }
if (cfg->keep_alive_cfg && cfg->keep_alive_cfg->keep_alive_enable) { if (cfg->keep_alive_cfg && cfg->keep_alive_cfg->keep_alive_enable) {
int keep_alive_enable = 1; int keep_alive_enable = 1;