mirror of
https://github.com/esphome/esphome.git
synced 2026-02-28 09:54:19 -07:00
[socket] Add MIN_TCP_LISTEN_SOCKETS constant for consistency
- Clarify MIN_TCP_SOCKETS comment: covers minimal configs (api-only); when web_server is present its 5 sockets push past the minimum. - Add MIN_TCP_LISTEN_SOCKETS = 2 alongside MIN_TCP/MIN_UDP for consistency instead of hardcoding the value in libretiny. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -316,6 +316,7 @@ def _configure_lwip(config: dict) -> None:
|
||||
socket.get_socket_counts() with minimums of 8 TCP / 6 UDP.
|
||||
"""
|
||||
from esphome.components.socket import (
|
||||
MIN_TCP_LISTEN_SOCKETS,
|
||||
MIN_TCP_SOCKETS,
|
||||
MIN_UDP_SOCKETS,
|
||||
get_socket_counts,
|
||||
@@ -328,8 +329,8 @@ def _configure_lwip(config: dict) -> None:
|
||||
tcp_sockets = max(MIN_TCP_SOCKETS, raw_tcp)
|
||||
udp_sockets = max(MIN_UDP_SOCKETS, raw_udp)
|
||||
# Listening sockets — registered by components (api, ota, web_server_base, etc.)
|
||||
# Not all components register yet, so ensure a minimum of 2 (api + ota baseline).
|
||||
listening_tcp = max(raw_tcp_listen, 2)
|
||||
# Not all components register yet, so ensure a minimum for baseline operation.
|
||||
listening_tcp = max(MIN_TCP_LISTEN_SOCKETS, raw_tcp_listen)
|
||||
|
||||
# TCP_SND_BUF: ESPAsyncWebServer allocates malloc(tcp_sndbuf()) per
|
||||
# response chunk. At 10×MSS=14.6KB (BK default) this causes OOM (#14095).
|
||||
|
||||
@@ -21,12 +21,14 @@ KEY_SOCKET_CONSUMERS_TCP = "socket_consumers_tcp"
|
||||
KEY_SOCKET_CONSUMERS_UDP = "socket_consumers_udp"
|
||||
KEY_SOCKET_CONSUMERS_TCP_LISTEN = "socket_consumers_tcp_listen"
|
||||
|
||||
# Recommended minimum socket counts to ensure headroom.
|
||||
# Recommended minimum socket counts.
|
||||
# Platforms should apply these (or their own) on top of get_socket_counts().
|
||||
# TCP: api(3) = 3 base, +5 headroom for ota-transfer/web_server/other.
|
||||
# UDP: dhcp(1) + dns(1) + mdns(2) + wake_loop(1) = 5 base, +1 headroom.
|
||||
# These cover minimal configs (e.g. api-only without web_server).
|
||||
# When web_server is present, its 5 registered sockets push past the TCP minimum.
|
||||
MIN_TCP_SOCKETS = 8
|
||||
MIN_UDP_SOCKETS = 6
|
||||
# Minimum listening sockets — at least api + ota baseline.
|
||||
MIN_TCP_LISTEN_SOCKETS = 2
|
||||
|
||||
# Wake loop threadsafe support tracking
|
||||
KEY_WAKE_LOOP_THREADSAFE_REQUIRED = "wake_loop_threadsafe_required"
|
||||
|
||||
Reference in New Issue
Block a user