DeterministicESPAsyncWebServer v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
netadapt.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file netadapt.cpp
6 * @brief Network adaptation decision core (see netadapt.h).
7 */
8
10
11#if DETWS_ENABLE_NETADAPT
12
13uint32_t detws_netadapt_window(uint32_t free_heap, uint32_t reserve, uint32_t min_win, uint32_t max_win)
14{
15 uint32_t ceil_win = max_win < min_win ? min_win : max_win;
16 if (free_heap <= reserve)
17 return min_win; // no spare heap: stay at the floor
18
19 // A quarter of the heap above the reserve - leaves headroom for TX buffers, TLS, app state.
20 uint32_t win = (free_heap - reserve) / 4;
21 if (win < min_win)
22 win = min_win;
23 if (win > ceil_win)
24 win = ceil_win;
25 return win;
26}
27
28bool detws_netadapt_dhcp_fallback(uint32_t elapsed_ms, uint32_t attempts, uint32_t timeout_ms, uint32_t max_attempts)
29{
30 if (elapsed_ms >= timeout_ms)
31 return true;
32 if (max_attempts > 0 && attempts >= max_attempts)
33 return true;
34 return false;
35}
36
37#endif // DETWS_ENABLE_NETADAPT
Network adaptation decisions: TCP window sizing by free RAM + DHCP->static fallback (DETWS_ENABLE_NET...