mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
feat(mbedtls): Add configuration to control dynamic buffer strategy in mbedtls
Problem: 1. In low-memory scenarios, the dynamic buffer feature can fail due to memory fragmentation. 2. It requires a contiguous 16KB heap chunk, but continuous allocation and deallocation of the RX buffer can lead to fragmentation. 3. If another component allocates memory between these operations, it can break up the available 16KB block, causing allocation failure. Solution: 1. Introduce configurable strategy for using dynamic buffers in TLS connections. 2. For example, convert RX buffers to static after the TLS handshake. 3. Allow users to select the strategy via a new field in the esp_http_client_cfg_t structure. 4. The strategy can be controlled independently for each TLS session.
This commit is contained in:
@@ -51,4 +51,13 @@ menu "Example Configuration"
|
||||
help
|
||||
Select ethernet interface to pass the OTA data.
|
||||
endchoice
|
||||
|
||||
config EXAMPLE_TLS_DYN_BUF_RX_STATIC
|
||||
bool "Use static rx buffer for dynamic buffer after TLS handshake"
|
||||
depends on MBEDTLS_DYNAMIC_BUFFER
|
||||
default n
|
||||
help
|
||||
This converts the dynamic RX buffer to static allocation after the TLS handshake
|
||||
is complete. This reduces memory fragmentation by avoiding repeated dynamic
|
||||
allocations during data transfer.
|
||||
endmenu
|
||||
|
||||
@@ -101,6 +101,12 @@ void simple_ota_example_task(void *pvParameter)
|
||||
#ifdef CONFIG_EXAMPLE_FIRMWARE_UPGRADE_BIND_IF
|
||||
.if_name = &ifr,
|
||||
#endif
|
||||
#if CONFIG_EXAMPLE_TLS_DYN_BUF_RX_STATIC
|
||||
/* This part applies static buffer strategy for rx dynamic buffer.
|
||||
* This is to avoid frequent allocation and deallocation of dynamic buffer.
|
||||
*/
|
||||
.tls_dyn_buf_strategy = HTTP_TLS_DYN_BUF_RX_STATIC,
|
||||
#endif /* CONFIG_EXAMPLE_TLS_DYN_BUF_RX_STATIC */
|
||||
};
|
||||
|
||||
#ifdef CONFIG_EXAMPLE_FIRMWARE_UPGRADE_URL_FROM_STDIN
|
||||
|
||||
Reference in New Issue
Block a user