feat(esp_http_server): Make HTTP(S)_SERVER_EVENT events optional

Make it possible to disable http(s) server events. This improves
performance of the server, as http server creates events on every signle
read or write to the socket.
This commit is contained in:
Jimmy Wennlund
2025-03-17 11:01:04 +01:00
parent a6e7046c30
commit bd85dad2cf
9 changed files with 52 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2018-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -23,6 +23,7 @@ typedef struct httpd_ssl_transport_ctx {
httpd_ssl_ctx_t *global_ctx;
} httpd_ssl_transport_ctx_t;
#ifdef CONFIG_ESP_HTTPS_SERVER_EVENTS
ESP_EVENT_DEFINE_BASE(ESP_HTTPS_SERVER_EVENT);
#if CONFIG_ESP_HTTPS_SERVER_EVENT_POST_TIMEOUT == -1
@@ -31,7 +32,6 @@ ESP_EVENT_DEFINE_BASE(ESP_HTTPS_SERVER_EVENT);
#define ESP_HTTPS_SERVER_EVENT_POST_TIMEOUT pdMS_TO_TICKS(CONFIG_ESP_HTTPS_SERVER_EVENT_POST_TIMEOUT)
#endif
static void http_dispatch_event_to_event_loop(int32_t event_id, const void* event_data, size_t event_data_size)
{
esp_err_t err = esp_event_post(ESP_HTTPS_SERVER_EVENT, event_id, event_data, event_data_size, ESP_HTTPS_SERVER_EVENT_POST_TIMEOUT);
@@ -39,6 +39,9 @@ static void http_dispatch_event_to_event_loop(int32_t event_id, const void* even
ESP_LOGE(TAG, "Failed to post http_client event: %"PRId32", error: %s", event_id, esp_err_to_name(err));
}
}
#else // CONFIG_ESP_HTTPS_SERVER_EVENTS
#define http_dispatch_event_to_event_loop(event_id, event_data, event_data_size) do {} while (0)
#endif // CONFIG_ESP_HTTPS_SERVER_EVENTS
/**
* SSL socket close handler