mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Websocket client: avoid deadlock if stop called from event handler
This commit is contained in:
parent
85e3c733ff
commit
d28f1682fc
@ -77,6 +77,7 @@ typedef enum {
|
|||||||
|
|
||||||
struct esp_websocket_client {
|
struct esp_websocket_client {
|
||||||
esp_event_loop_handle_t event_handle;
|
esp_event_loop_handle_t event_handle;
|
||||||
|
TaskHandle_t task_handle;
|
||||||
esp_transport_list_handle_t transport_list;
|
esp_transport_list_handle_t transport_list;
|
||||||
esp_transport_handle_t transport;
|
esp_transport_handle_t transport;
|
||||||
websocket_config_storage_t *config;
|
websocket_config_storage_t *config;
|
||||||
@ -584,7 +585,7 @@ esp_err_t esp_websocket_client_start(esp_websocket_client_handle_t client)
|
|||||||
ESP_LOGE(TAG, "The client has started");
|
ESP_LOGE(TAG, "The client has started");
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
if (xTaskCreate(esp_websocket_client_task, "websocket_task", client->config->task_stack, client, client->config->task_prio, NULL) != pdTRUE) {
|
if (xTaskCreate(esp_websocket_client_task, "websocket_task", client->config->task_stack, client, client->config->task_prio, &client->task_handle) != pdTRUE) {
|
||||||
ESP_LOGE(TAG, "Error create websocket task");
|
ESP_LOGE(TAG, "Error create websocket task");
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
@ -601,6 +602,15 @@ esp_err_t esp_websocket_client_stop(esp_websocket_client_handle_t client)
|
|||||||
ESP_LOGW(TAG, "Client was not started");
|
ESP_LOGW(TAG, "Client was not started");
|
||||||
return ESP_FAIL;
|
return ESP_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* A running client cannot be stopped from the websocket task/event handler */
|
||||||
|
TaskHandle_t running_task = xTaskGetCurrentTaskHandle();
|
||||||
|
if (running_task == client->task_handle) {
|
||||||
|
ESP_LOGE(TAG, "Client cannot be stopped from websocket task");
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
client->run = false;
|
client->run = false;
|
||||||
xEventGroupWaitBits(client->status_bits, STOPPED_BIT, false, true, portMAX_DELAY);
|
xEventGroupWaitBits(client->status_bits, STOPPED_BIT, false, true, portMAX_DELAY);
|
||||||
client->state = WEBSOCKET_STATE_UNKNOW;
|
client->state = WEBSOCKET_STATE_UNKNOW;
|
||||||
|
@ -124,6 +124,9 @@ esp_err_t esp_websocket_client_start(esp_websocket_client_handle_t client);
|
|||||||
/**
|
/**
|
||||||
* @brief Close the WebSocket connection
|
* @brief Close the WebSocket connection
|
||||||
*
|
*
|
||||||
|
* Notes:
|
||||||
|
* - Cannot be called from the websocket event handler
|
||||||
|
*
|
||||||
* @param[in] client The client
|
* @param[in] client The client
|
||||||
*
|
*
|
||||||
* @return esp_err_t
|
* @return esp_err_t
|
||||||
@ -136,6 +139,9 @@ esp_err_t esp_websocket_client_stop(esp_websocket_client_handle_t client);
|
|||||||
* It is the opposite of the esp_websocket_client_init function and must be called with the same handle as input that a esp_websocket_client_init call returned.
|
* It is the opposite of the esp_websocket_client_init function and must be called with the same handle as input that a esp_websocket_client_init call returned.
|
||||||
* This might close all connections this handle has used.
|
* This might close all connections this handle has used.
|
||||||
*
|
*
|
||||||
|
* Notes:
|
||||||
|
* - Cannot be called from the websocket event handler
|
||||||
|
*
|
||||||
* @param[in] client The client
|
* @param[in] client The client
|
||||||
*
|
*
|
||||||
* @return esp_err_t
|
* @return esp_err_t
|
||||||
|
Loading…
x
Reference in New Issue
Block a user