From 1490845dcf2e59ef04e0f827101c9cc514a919ff Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 10 Apr 2026 17:15:04 -1000 Subject: [PATCH] [esphome.ota] Use existing esphome_lwip_get_sock() instead of adding Socket accessor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit get_cached_sock() was a new public method that only OTA's fast-select wake filter would ever call. Drop it. The existing public C API already covers this: esphome_lwip_get_sock(fd) looks up a lwip_sock* from a file descriptor (it's exactly what BSDSocketImpl's own constructor calls to populate cached_sock_). OTA uses the public get_fd() + esphome_lwip_get_sock() chain instead — no new Socket accessor, no friend declarations, no layering concerns. The one-time lookup at setup is negligible. --- esphome/components/esphome/ota/ota_esphome.cpp | 4 +++- esphome/components/socket/bsd_sockets_impl.h | 9 --------- esphome/components/socket/lwip_sockets_impl.h | 7 ------- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/esphome/components/esphome/ota/ota_esphome.cpp b/esphome/components/esphome/ota/ota_esphome.cpp index af2a609642..1999b88ef4 100644 --- a/esphome/components/esphome/ota/ota_esphome.cpp +++ b/esphome/components/esphome/ota/ota_esphome.cpp @@ -78,7 +78,9 @@ void ESPHomeOTAComponent::setup() { // every RCVPLUS across all monitored sockets (API client data, mDNS, etc.) would // pay the inline hook's two volatile stores + memw barriers to mark OTA // pending-enable, even though OTA would just re-disable itself on the next tick. - esphome_fast_select_set_ota_listener_sock(this->server_->get_cached_sock()); + // Uses the existing public esphome_lwip_get_sock() lookup instead of adding a + // dedicated accessor on Socket — the lookup happens once at setup, not per event. + esphome_fast_select_set_ota_listener_sock(esphome_lwip_get_sock(this->server_->get_fd())); #endif } diff --git a/esphome/components/socket/bsd_sockets_impl.h b/esphome/components/socket/bsd_sockets_impl.h index ceb7556d9f..e520784702 100644 --- a/esphome/components/socket/bsd_sockets_impl.h +++ b/esphome/components/socket/bsd_sockets_impl.h @@ -118,15 +118,6 @@ class BSDSocketImpl { int get_fd() const { return this->fd_; } -#ifdef USE_LWIP_FAST_SELECT - // Cached lwip_sock pointer captured at construction. Used by OTA to register its - // listener netconn with the fast-select wake hook filter so the hook only fires on - // OTA-relevant events. Returns nullptr for non-monitored sockets. - struct lwip_sock *get_cached_sock() const { - return this->cached_sock_; - } -#endif - protected: int fd_{-1}; #ifdef USE_LWIP_FAST_SELECT diff --git a/esphome/components/socket/lwip_sockets_impl.h b/esphome/components/socket/lwip_sockets_impl.h index cda37b5dc6..942d0ccf85 100644 --- a/esphome/components/socket/lwip_sockets_impl.h +++ b/esphome/components/socket/lwip_sockets_impl.h @@ -84,13 +84,6 @@ class LwIPSocketImpl { int get_fd() const { return this->fd_; } -#ifdef USE_LWIP_FAST_SELECT - // See BSDSocketImpl::get_cached_sock() — same purpose, same semantics. - struct lwip_sock *get_cached_sock() const { - return this->cached_sock_; - } -#endif - protected: int fd_{-1}; #ifdef USE_LWIP_FAST_SELECT