[socket] Dedupe fast_select hook logic into shared helper

Lift the lwip_sock resolve + event-callback hook sequence into
socket::fast_select_hook_fd() in socket.h so the USE_LWIP_FAST_SELECT
constructor blocks in lwip_sockets_impl.cpp and bsd_sockets_impl.cpp
stop drifting in lockstep. Both impls now collapse to a two-line call
site.
This commit is contained in:
J. Nick Koston
2026-04-10 20:59:12 -10:00
parent 4a9d3da962
commit 107915fe36
3 changed files with 15 additions and 14 deletions
@@ -14,13 +14,8 @@ BSDSocketImpl::BSDSocketImpl(int fd, bool monitor_loop) {
if (!monitor_loop || this->fd_ < 0)
return;
#ifdef USE_LWIP_FAST_SELECT
// Cache lwip_sock pointer (used by ready() for direct rcvevent reads) and hook the
// netconn event callback so the main loop is notified via FreeRTOS task notifications.
this->cached_sock_ = esphome_lwip_get_sock(this->fd_);
if (this->cached_sock_ != nullptr) {
esphome_lwip_hook_socket(this->cached_sock_);
this->loop_monitored_ = true;
}
this->cached_sock_ = fast_select_hook_fd(this->fd_);
this->loop_monitored_ = this->cached_sock_ != nullptr;
#else
this->loop_monitored_ = App.register_socket_fd(this->fd_);
#endif