fix: Add config option to set timeout for posting events

Event posting to the event loop should not hinder the working of
HTTP Client or HTTP Server. This commit add a config option to set
the timeout for posting the events to the loop.

Closes https://github.com/espressif/esp-idf/issues/13641
This commit is contained in:
Harshit Malpani
2024-05-02 15:27:19 +05:30
parent 40ec44473c
commit 1ac2ebbeb9
9 changed files with 59 additions and 9 deletions

View File

@@ -18,4 +18,11 @@ menu "ESP HTTPS OTA"
- Non-encrypted communication channel with server
- Accepting firmware upgrade image from server with fake identity
config ESP_HTTPS_OTA_EVENT_POST_TIMEOUT
int "Time in millisecond to wait for posting event"
default 2000
help
This config option helps in setting the time in millisecond to wait for event to be posted to the
system default event loop. Set it to -1 if you need to set timeout to portMAX_DELAY.
endmenu

View File

@@ -194,9 +194,15 @@ static const char* ota_event_name_table[] = {
"ESP_HTTPS_OTA_ABORT",
};
#if CONFIG_ESP_HTTPS_OTA_EVENT_POST_TIMEOUT == -1
#define ESP_HTTPS_OTA_EVENT_POST_TIMEOUT portMAX_DELAY
#else
#define ESP_HTTPS_OTA_EVENT_POST_TIMEOUT pdMS_TO_TICKS(CONFIG_ESP_HTTPS_OTA_EVENT_POST_TIMEOUT)
#endif
static void esp_https_ota_dispatch_event(int32_t event_id, const void* event_data, size_t event_data_size)
{
if (esp_event_post(ESP_HTTPS_OTA_EVENT, event_id, event_data, event_data_size, portMAX_DELAY) != ESP_OK) {
if (esp_event_post(ESP_HTTPS_OTA_EVENT, event_id, event_data, event_data_size, ESP_HTTPS_OTA_EVENT_POST_TIMEOUT) != ESP_OK) {
ESP_LOGE(TAG, "Failed to post https_ota event: %s", ota_event_name_table[event_id]);
}
}