From 4593c6de37b52e7dcf387baa14e596ee72f23fed Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 27 May 2025 12:12:33 -0500 Subject: [PATCH 1/2] 8266 --- esphome/core/application.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/esphome/core/application.cpp b/esphome/core/application.cpp index c37d9c1a0f..045eb807b5 100644 --- a/esphome/core/application.cpp +++ b/esphome/core/application.cpp @@ -17,6 +17,8 @@ extern "C" { #include } +#elif defined(USE_SOCKET_IMPL_LWIP_SOCKETS) +#include #else #include #endif @@ -146,7 +148,13 @@ void Application::loop() { tv.tv_usec = (delay_time % 1000) * 1000; // Call select with timeout +#if defined(USE_ESP8266) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) + // Use lwip_select() on platforms with lwIP - it's faster + int ret = lwip_select(this->max_fd_ + 1, &this->read_fds_, nullptr, nullptr, &tv); +#else + // Use standard select() on other platforms int ret = ::select(this->max_fd_ + 1, &this->read_fds_, nullptr, nullptr, &tv); +#endif if (ret < 0) { if (errno == EINTR) { From f981f671f3d8d3e4b725abd097cce2992a9b8d79 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 27 May 2025 12:22:45 -0500 Subject: [PATCH 2/2] make sure we use lwip_select as its much faster --- esphome/core/application.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/esphome/core/application.cpp b/esphome/core/application.cpp index 045eb807b5..b67a96eec7 100644 --- a/esphome/core/application.cpp +++ b/esphome/core/application.cpp @@ -10,7 +10,12 @@ #if defined(FD_SETSIZE) && !defined(USE_SOCKET_IMPL_LWIP_TCP) #include #ifdef USE_ESP32 +// ESP32 with BSD sockets actually uses lwIP underneath +#ifdef USE_SOCKET_IMPL_BSD_SOCKETS +#include +#else #include +#endif #elif defined(USE_ESP8266) #include #include @@ -148,11 +153,14 @@ void Application::loop() { tv.tv_usec = (delay_time % 1000) * 1000; // Call select with timeout -#if defined(USE_ESP8266) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) +#if defined(USE_ESP8266) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS) || \ + (defined(USE_ESP32) && defined(USE_SOCKET_IMPL_BSD_SOCKETS)) // Use lwip_select() on platforms with lwIP - it's faster + // Note: On ESP32 with BSD sockets, select() is already mapped to lwip_select() via macros, + // but we explicitly call lwip_select() for clarity and to ensure we get the optimized version int ret = lwip_select(this->max_fd_ + 1, &this->read_fds_, nullptr, nullptr, &tv); #else - // Use standard select() on other platforms + // Use standard select() on other platforms (e.g., host/native builds) int ret = ::select(this->max_fd_ + 1, &this->read_fds_, nullptr, nullptr, &tv); #endif