From 4be95e274dc9300c79b14aab627c6a914eb715af Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 4 Apr 2026 10:55:25 -1000 Subject: [PATCH] Fix host platform: use POSIX socket APIs instead of lwip_* --- esphome/core/application.cpp | 22 +++++++++++----------- esphome/core/application.h | 8 ++++++-- esphome/core/wake.cpp | 6 +++--- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/esphome/core/application.cpp b/esphome/core/application.cpp index c04482c5d20..846c9963e5f 100644 --- a/esphome/core/application.cpp +++ b/esphome/core/application.cpp @@ -624,7 +624,7 @@ alignas(Application) char app_storage[sizeof(Application)] asm( void Application::setup_wake_loop_threadsafe_() { // Create UDP socket for wake notifications - this->wake_socket_fd_ = lwip_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + this->wake_socket_fd_ = ::socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (this->wake_socket_fd_ < 0) { ESP_LOGW(TAG, "Wake socket create failed: %d", errno); return; @@ -633,12 +633,12 @@ void Application::setup_wake_loop_threadsafe_() { // Bind to loopback with auto-assigned port struct sockaddr_in addr = {}; addr.sin_family = AF_INET; - addr.sin_addr.s_addr = lwip_htonl(INADDR_LOOPBACK); + addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); addr.sin_port = 0; // Auto-assign port - if (lwip_bind(this->wake_socket_fd_, (struct sockaddr *) &addr, sizeof(addr)) < 0) { + if (::bind(this->wake_socket_fd_, (struct sockaddr *) &addr, sizeof(addr)) < 0) { ESP_LOGW(TAG, "Wake socket bind failed: %d", errno); - lwip_close(this->wake_socket_fd_); + ::close(this->wake_socket_fd_); this->wake_socket_fd_ = -1; return; } @@ -647,30 +647,30 @@ void Application::setup_wake_loop_threadsafe_() { // Connecting a UDP socket allows using send() instead of sendto() for better performance struct sockaddr_in wake_addr; socklen_t len = sizeof(wake_addr); - if (lwip_getsockname(this->wake_socket_fd_, (struct sockaddr *) &wake_addr, &len) < 0) { + if (::getsockname(this->wake_socket_fd_, (struct sockaddr *) &wake_addr, &len) < 0) { ESP_LOGW(TAG, "Wake socket address failed: %d", errno); - lwip_close(this->wake_socket_fd_); + ::close(this->wake_socket_fd_); this->wake_socket_fd_ = -1; return; } // Connect to self (loopback) - allows using send() instead of sendto() // After connect(), no need to store wake_addr - the socket remembers it - if (lwip_connect(this->wake_socket_fd_, (struct sockaddr *) &wake_addr, sizeof(wake_addr)) < 0) { + if (::connect(this->wake_socket_fd_, (struct sockaddr *) &wake_addr, sizeof(wake_addr)) < 0) { ESP_LOGW(TAG, "Wake socket connect failed: %d", errno); - lwip_close(this->wake_socket_fd_); + ::close(this->wake_socket_fd_); this->wake_socket_fd_ = -1; return; } // Set non-blocking mode - int flags = lwip_fcntl(this->wake_socket_fd_, F_GETFL, 0); - lwip_fcntl(this->wake_socket_fd_, F_SETFL, flags | O_NONBLOCK); + int flags = ::fcntl(this->wake_socket_fd_, F_GETFL, 0); + ::fcntl(this->wake_socket_fd_, F_SETFL, flags | O_NONBLOCK); // Register with application's select() loop if (!this->register_socket_fd(this->wake_socket_fd_)) { ESP_LOGW(TAG, "Wake socket register failed"); - lwip_close(this->wake_socket_fd_); + ::close(this->wake_socket_fd_); this->wake_socket_fd_ = -1; return; } diff --git a/esphome/core/application.h b/esphome/core/application.h index 7e01a533dd1..f4df256a2dc 100644 --- a/esphome/core/application.h +++ b/esphome/core/application.h @@ -26,7 +26,11 @@ #ifdef USE_SOCKET_SELECT_SUPPORT #include -#include +#include +#include +#include +#include +#include #endif #ifdef USE_RUNTIME_STATS #include "esphome/components/runtime_stats/runtime_stats.h" @@ -793,7 +797,7 @@ inline void Application::drain_wake_notifications_() { // Multiple wake events may have triggered multiple writes, so drain until EWOULDBLOCK // We control both ends of this loopback socket (always write 1 byte per wake), // so no error checking needed - any errors indicate catastrophic system failure - while (lwip_recvfrom(this->wake_socket_fd_, buffer, sizeof(buffer), 0, nullptr, nullptr) > 0) { + while (::recvfrom(this->wake_socket_fd_, buffer, sizeof(buffer), 0, nullptr, nullptr) > 0) { // Just draining, no action needed - wake has already occurred } } diff --git a/esphome/core/wake.cpp b/esphome/core/wake.cpp index cc2b4734f7f..46fbcb3c135 100644 --- a/esphome/core/wake.cpp +++ b/esphome/core/wake.cpp @@ -87,13 +87,13 @@ void wakeable_delay(uint32_t ms) { // === Host (UDP loopback socket) === #ifdef USE_SOCKET_SELECT_SUPPORT #include "esphome/core/application.h" -#include +#include void wake_loop_threadsafe() { - // Wakes up lwip_select() in main loop by writing to connected loopback socket + // Wakes up select() in main loop by writing to connected loopback socket if (App.wake_socket_fd_ >= 0) { const char dummy = 1; - lwip_send(App.wake_socket_fd_, &dummy, 1, 0); + ::send(App.wake_socket_fd_, &dummy, 1, 0); } } #endif // USE_SOCKET_SELECT_SUPPORT