components: Support bind socket to specified interface in esp_http_client and esp_websocket_client component

This commit is contained in:
yuanjm
2021-01-19 17:50:31 +08:00
committed by bot
parent c62cbd1254
commit bead3599ab
4 changed files with 28 additions and 2 deletions
+13 -1
View File
@@ -122,6 +122,7 @@ struct esp_http_client {
int header_index;
bool is_async;
esp_transport_keep_alive_t keep_alive_cfg;
struct ifreq *if_name;
};
typedef struct esp_http_client esp_http_client_t;
@@ -576,6 +577,7 @@ esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *co
ESP_LOGE(TAG, "Error initialize transport");
goto error;
}
if (config->keep_alive_enable == true) {
client->keep_alive_cfg.keep_alive_enable = true;
client->keep_alive_cfg.keep_alive_idle = (config->keep_alive_idle == 0) ? DEFAULT_KEEP_ALIVE_IDLE : config->keep_alive_idle;
@@ -583,6 +585,14 @@ esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *co
client->keep_alive_cfg.keep_alive_count = (config->keep_alive_count == 0) ? DEFAULT_KEEP_ALIVE_COUNT : config->keep_alive_count;
esp_transport_tcp_set_keep_alive(tcp, &client->keep_alive_cfg);
}
if (config->if_name) {
client->if_name = calloc(1, sizeof(struct ifreq) + 1);
HTTP_MEM_CHECK(TAG, client->if_name, goto error);
memcpy(client->if_name, config->if_name, sizeof(struct ifreq));
esp_transport_tcp_set_interface_name(tcp, client->if_name);
}
#ifdef CONFIG_ESP_HTTP_CLIENT_ENABLE_HTTPS
esp_transport_handle_t ssl = NULL;
_success = (
@@ -719,7 +729,9 @@ esp_err_t esp_http_client_cleanup(esp_http_client_handle_t client)
free(client->response->buffer);
free(client->response);
}
if (client->if_name) {
free(client->if_name);
}
free(client->parser);
free(client->parser_settings);
_clear_connection_info(client);