Merge branch 'bugfix/esp_http_client_async_crash' into 'master'

esp_http_client: Fix crash in async mode

See merge request idf/esp-idf!3551
This commit is contained in:
Ivan Grokhotkov 2018-11-05 12:30:04 +08:00
commit ee0dea3d0d
3 changed files with 6 additions and 2 deletions

View File

@ -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); 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) { if (ret == ASYNC_TRANS_CONNECT_FAIL) {
ESP_LOGE(TAG, "Connection failed"); 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; return ESP_ERR_HTTP_CONNECT;
} else if (ret == ASYNC_TRANS_CONNECTING) { } else if (ret == ASYNC_TRANS_CONNECTING) {
ESP_LOGD(TAG, "Connection not yet established"); ESP_LOGD(TAG, "Connection not yet established");

View File

@ -114,7 +114,7 @@ typedef struct {
esp_http_client_transport_t transport_type; /*!< HTTP transport type, see `esp_http_client_transport_t` */ 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) */ int buffer_size; /*!< HTTP buffer size (both send and receive) */
void *user_data; /*!< HTTP user_data context */ 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; } esp_http_client_config_t;

View File

@ -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 esp_transport_connect_async(esp_transport_handle_t t, const char *host, int port, int timeout_ms)
{ {
int ret = -1; int ret = -1;
if (t && t->_connect) { if (t && t->_connect_async) {
return t->_connect_async(t, host, port, timeout_ms); return t->_connect_async(t, host, port, timeout_ms);
} }
return ret; return ret;