mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-28 09:47:26 +02:00
feat(websocket): add events for begin/end thread
Add events to signal the start and end of the websocket thread handler, only once each per client.
This commit is contained in:
@ -970,6 +970,7 @@ static void esp_websocket_client_task(void *pv)
|
||||
|
||||
client->state = WEBSOCKET_STATE_INIT;
|
||||
xEventGroupClearBits(client->status_bits, STOPPED_BIT | CLOSE_FRAME_SENT_BIT);
|
||||
esp_websocket_client_dispatch_event(client, WEBSOCKET_EVENT_BEGIN, NULL, 0);
|
||||
int read_select = 0;
|
||||
while (client->run) {
|
||||
if (xSemaphoreTakeRecursive(client->lock, lock_timeout) != pdPASS) {
|
||||
@ -1104,6 +1105,7 @@ static void esp_websocket_client_task(void *pv)
|
||||
}
|
||||
}
|
||||
|
||||
esp_websocket_client_dispatch_event(client, WEBSOCKET_EVENT_FINISH, NULL, 0);
|
||||
esp_transport_close(client->transport);
|
||||
xEventGroupSetBits(client->status_bits, STOPPED_BIT);
|
||||
client->state = WEBSOCKET_STATE_UNKNOW;
|
||||
|
@ -25,6 +25,9 @@ static void websocket_event_handler(void *handler_args, esp_event_base_t base, i
|
||||
{
|
||||
esp_websocket_event_data_t *data = (esp_websocket_event_data_t *)event_data;
|
||||
switch (event_id) {
|
||||
case WEBSOCKET_EVENT_BEGIN:
|
||||
ESP_LOGI(TAG, "WEBSOCKET_EVENT_BEGIN");
|
||||
break;
|
||||
case WEBSOCKET_EVENT_CONNECTED:
|
||||
ESP_LOGI(TAG, "WEBSOCKET_EVENT_CONNECTED");
|
||||
break;
|
||||
@ -59,6 +62,9 @@ static void websocket_event_handler(void *handler_args, esp_event_base_t base, i
|
||||
log_error_if_nonzero("captured as transport's socket errno", data->error_handle.esp_transport_sock_errno);
|
||||
}
|
||||
break;
|
||||
case WEBSOCKET_EVENT_FINISH:
|
||||
ESP_LOGI(TAG, "WEBSOCKET_EVENT_FINISH");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,6 +74,9 @@ static void websocket_event_handler(void *handler_args, esp_event_base_t base, i
|
||||
{
|
||||
esp_websocket_event_data_t *data = (esp_websocket_event_data_t *)event_data;
|
||||
switch (event_id) {
|
||||
case WEBSOCKET_EVENT_BEGIN:
|
||||
ESP_LOGI(TAG, "WEBSOCKET_EVENT_BEGIN");
|
||||
break;
|
||||
case WEBSOCKET_EVENT_CONNECTED:
|
||||
ESP_LOGI(TAG, "WEBSOCKET_EVENT_CONNECTED");
|
||||
break;
|
||||
@ -122,6 +125,9 @@ static void websocket_event_handler(void *handler_args, esp_event_base_t base, i
|
||||
log_error_if_nonzero("captured as transport's socket errno", data->error_handle.esp_transport_sock_errno);
|
||||
}
|
||||
break;
|
||||
case WEBSOCKET_EVENT_FINISH:
|
||||
ESP_LOGI(TAG, "WEBSOCKET_EVENT_FINISH");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,8 @@ typedef enum {
|
||||
WEBSOCKET_EVENT_DATA, /*!< When receiving data from the server, possibly multiple portions of the packet */
|
||||
WEBSOCKET_EVENT_CLOSED, /*!< The connection has been closed cleanly */
|
||||
WEBSOCKET_EVENT_BEFORE_CONNECT, /*!< The event occurs before connecting */
|
||||
WEBSOCKET_EVENT_BEGIN, /*!< The event occurs once after thread creation, before event loop */
|
||||
WEBSOCKET_EVENT_FINISH, /*!< The event occurs once after event loop, before thread destruction */
|
||||
WEBSOCKET_EVENT_MAX
|
||||
} esp_websocket_event_id_t;
|
||||
|
||||
|
Reference in New Issue
Block a user