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

@@ -6,8 +6,18 @@ menu "ESP HTTPS server"
help
Enable ESP HTTPS server component
config ESP_HTTPS_SERVER_EVENTS
bool "Enable ESP_HTTPS_SERVER_EVENT event type"
depends on ESP_HTTPS_SERVER_ENABLE
default y
help
This enables the ESP_HTTPS_SERVER_EVENT event type. Generating these eventes adds some overhead.
If you are not using this event type, you can disable it to save some memory.
config ESP_HTTPS_SERVER_EVENT_POST_TIMEOUT
int "Time in millisecond to wait for posting event"
depends on (ESP_HTTPS_SERVER_ENABLE && ESP_HTTPS_SERVER_EVENTS)
default 2000
help
This config option helps in setting the time in millisecond to wait for event to be posted to the

View File

@@ -18,6 +18,7 @@
extern "C" {
#endif
#if CONFIG_ESP_HTTPS_SERVER_EVENTS || __DOXYGEN__
ESP_EVENT_DECLARE_BASE(ESP_HTTPS_SERVER_EVENT);
typedef enum {
@@ -29,6 +30,7 @@ typedef enum {
HTTPS_SERVER_EVENT_DISCONNECTED, /*!< The connection has been disconnected */
HTTPS_SERVER_EVENT_STOP, /*!< This event occurs when HTTPS Server is stopped */
} esp_https_server_event_id_t;
#endif // CONFIG_ESP_HTTPS_SERVER_EVENTS || __DOXYGEN__
typedef enum {
HTTPD_SSL_TRANSPORT_SECURE, // SSL Enabled

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