ProtoCore v0.0.2
Deterministic, zero-heap network stack for embedded targets
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 PC_ENABLE_NETADAPT
12
13uint32_t pc_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 {
18 return min_win; // no spare heap: stay at the floor
19 }
20
21 // A quarter of the heap above the reserve - leaves headroom for TX buffers, TLS, app state.
22 uint32_t win = (free_heap - reserve) / 4;
23 if (win < min_win)
24 {
25 win = min_win;
26 }
27 if (win > ceil_win)
28 {
29 win = ceil_win;
30 }
31 return win;
32}
33
34bool pc_netadapt_dhcp_fallback(uint32_t elapsed_ms, uint32_t attempts, uint32_t timeout_ms, uint32_t max_attempts)
35{
36 if (elapsed_ms >= timeout_ms)
37 {
38 return true;
39 }
40 if (max_attempts > 0 && attempts >= max_attempts)
41 {
42 return true;
43 }
44 return false;
45}
46
47#endif // PC_ENABLE_NETADAPT
Network adaptation decisions: TCP window sizing by free RAM + DHCP->static fallback (PC_ENABLE_NETADA...