mirror of
https://github.com/esphome/esphome.git
synced 2026-02-28 18:04:19 -07:00
[socket] Remove legacy aliases, fix NETCONN count, add comments
- Remove SOCKET_TCP/SOCKET_UDP aliases, use SocketType.UDP everywhere - Fix MEMP_NUM_NETCONN to include listening_tcp (listeners need netconns) - Add comment on listening_tcp minimum (not all components register yet) - Add comment on MAX_LISTENING_SOCKETS_TCP (BK-specific, RTL/LN use MEMP_NUM_TCP_PCB_LISTEN directly) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -326,7 +326,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.)
|
||||
listening_tcp = max(raw_tcp_listen, 2) # at least 2 (api + ota)
|
||||
# Not all components register yet, so ensure a minimum of 2 (api + ota baseline).
|
||||
listening_tcp = max(raw_tcp_listen, 2)
|
||||
|
||||
# TCP_SND_BUF: ESPAsyncWebServer allocates malloc(tcp_sndbuf()) per
|
||||
# response chunk. At 10×MSS=14.6KB (BK default) this causes OOM (#14095).
|
||||
@@ -356,7 +357,8 @@ def _configure_lwip(config: dict) -> None:
|
||||
# Socket counts — auto-calculated from component registrations
|
||||
f"MAX_SOCKETS_TCP={tcp_sockets}",
|
||||
f"MAX_SOCKETS_UDP={udp_sockets}",
|
||||
# Listening sockets — auto-calculated from component registrations
|
||||
# Listening sockets — BK SDK uses this to derive MEMP_NUM_TCP_PCB_LISTEN;
|
||||
# RTL/LN don't use it, but we set MEMP_NUM_TCP_PCB_LISTEN explicitly below.
|
||||
f"MAX_LISTENING_SOCKETS_TCP={listening_tcp}",
|
||||
# Queued segment limits — derived from 4×MSS buffer size
|
||||
f"TCP_SND_QUEUELEN={tcp_snd_queuelen}",
|
||||
@@ -366,8 +368,8 @@ def _configure_lwip(config: dict) -> None:
|
||||
f"MEMP_NUM_TCP_PCB_LISTEN={listening_tcp}", # BK: =MAX_LISTENING, RTL: 5, LN: 3
|
||||
# UDP PCB pool — includes wifi.lwip_internal (DHCP + DNS)
|
||||
f"MEMP_NUM_UDP_PCB={udp_sockets}", # BK: 25, RTL/LN: 7 via LT
|
||||
# Netconn pool — listening sockets are already counted in tcp_sockets
|
||||
f"MEMP_NUM_NETCONN={tcp_sockets + udp_sockets}",
|
||||
# Netconn pool — each socket (active + listening) needs a netconn
|
||||
f"MEMP_NUM_NETCONN={tcp_sockets + udp_sockets + listening_tcp}",
|
||||
# Netbuf pool
|
||||
"MEMP_NUM_NETBUF=4", # BK: 16, RTL: 2 (opt.h), LN: 8
|
||||
# Inbound message pool
|
||||
|
||||
@@ -56,7 +56,7 @@ def _consume_mdns_sockets(config: ConfigType) -> ConfigType:
|
||||
from esphome.components import socket
|
||||
|
||||
# mDNS needs 2 sockets (IPv4 + IPv6 multicast)
|
||||
socket.consume_sockets(2, "mdns", socket.SOCKET_UDP)(config)
|
||||
socket.consume_sockets(2, "mdns", socket.SocketType.UDP)(config)
|
||||
return config
|
||||
|
||||
|
||||
|
||||
@@ -38,10 +38,6 @@ class SocketType(StrEnum):
|
||||
TCP_LISTEN = "tcp_listen"
|
||||
|
||||
|
||||
# Legacy aliases
|
||||
SOCKET_TCP = SocketType.TCP
|
||||
SOCKET_UDP = SocketType.UDP
|
||||
|
||||
_SOCKET_TYPE_KEYS = {
|
||||
SocketType.TCP: KEY_SOCKET_CONSUMERS_TCP,
|
||||
SocketType.UDP: KEY_SOCKET_CONSUMERS_UDP,
|
||||
@@ -134,7 +130,7 @@ def require_wake_loop_threadsafe() -> None:
|
||||
CORE.data[KEY_WAKE_LOOP_THREADSAFE_REQUIRED] = True
|
||||
cg.add_define("USE_WAKE_LOOP_THREADSAFE")
|
||||
# Consume 1 socket for the shared wake notification socket
|
||||
consume_sockets(1, "socket.wake_loop_threadsafe", SOCKET_UDP)({})
|
||||
consume_sockets(1, "socket.wake_loop_threadsafe", SocketType.UDP)({})
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
|
||||
@@ -73,7 +73,7 @@ def _consume_udp_sockets(config: ConfigType) -> ConfigType:
|
||||
|
||||
# UDP uses up to 2 sockets: 1 broadcast + 1 listen
|
||||
# Whether each is used depends on code generation, so register worst case
|
||||
socket.consume_sockets(2, "udp", socket.SOCKET_UDP)(config)
|
||||
socket.consume_sockets(2, "udp", socket.SocketType.UDP)(config)
|
||||
return config
|
||||
|
||||
|
||||
|
||||
@@ -284,7 +284,7 @@ def _consume_wifi_sockets(config: ConfigType) -> ConfigType:
|
||||
|
||||
# lwIP allocates UDP PCBs for DHCP client and DNS resolver internally.
|
||||
# These are not application sockets but consume MEMP_NUM_UDP_PCB pool entries.
|
||||
socket.consume_sockets(2, "wifi.lwip_internal", socket.SOCKET_UDP)(config)
|
||||
socket.consume_sockets(2, "wifi.lwip_internal", socket.SocketType.UDP)(config)
|
||||
return config
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user