From 3551b84c3a6bc37cec92c376a909555f0b64eed1 Mon Sep 17 00:00:00 2001 From: Jitin George Date: Wed, 24 Oct 2018 13:02:47 +0530 Subject: [PATCH] esp_http_client: Fix crash in async mode Closes https://github.com/espressif/esp-idf/issues/2624 --- components/esp_http_client/esp_http_client.c | 4 ++++ components/esp_http_client/include/esp_http_client.h | 2 +- components/tcp_transport/transport.c | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index 27181f3ec1..81e54b7e06 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -943,6 +943,10 @@ static esp_err_t esp_http_client_connect(esp_http_client_handle_t client) int ret = esp_transport_connect_async(client->transport, client->connection_info.host, client->connection_info.port, client->timeout_ms); if (ret == ASYNC_TRANS_CONNECT_FAIL) { ESP_LOGE(TAG, "Connection failed"); + if (strcasecmp(client->connection_info.scheme, "http") == 0) { + ESP_LOGE(TAG, "Asynchronous mode doesn't work for HTTP based connection"); + return ESP_ERR_INVALID_ARG; + } return ESP_ERR_HTTP_CONNECT; } else if (ret == ASYNC_TRANS_CONNECTING) { ESP_LOGD(TAG, "Connection not yet established"); diff --git a/components/esp_http_client/include/esp_http_client.h b/components/esp_http_client/include/esp_http_client.h index b3b40ca0dc..4e940a6d10 100644 --- a/components/esp_http_client/include/esp_http_client.h +++ b/components/esp_http_client/include/esp_http_client.h @@ -114,7 +114,7 @@ typedef struct { esp_http_client_transport_t transport_type; /*!< HTTP transport type, see `esp_http_client_transport_t` */ int buffer_size; /*!< HTTP buffer size (both send and receive) */ void *user_data; /*!< HTTP user_data context */ - bool is_async; /*!< Set asynchronous mode */ + bool is_async; /*!< Set asynchronous mode, only supported with HTTPS for now */ } esp_http_client_config_t; diff --git a/components/tcp_transport/transport.c b/components/tcp_transport/transport.c index 5c2f913fe9..f6fa311ae7 100644 --- a/components/tcp_transport/transport.c +++ b/components/tcp_transport/transport.c @@ -156,7 +156,7 @@ int esp_transport_connect(esp_transport_handle_t t, const char *host, int port, int esp_transport_connect_async(esp_transport_handle_t t, const char *host, int port, int timeout_ms) { int ret = -1; - if (t && t->_connect) { + if (t && t->_connect_async) { return t->_connect_async(t, host, port, timeout_ms); } return ret;