From c01862a9eb0dd1f2c38b4d88f6569a2f4fa603c6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 5 Sep 2026 21:24:22 +0200 Subject: [PATCH] [mdns] Share one guard body between update and close Passing a member function pointer instead of a template keeps a single copy of the guard and one set of std::function handlers. --- esphome/components/mdns/mdns_esp8266.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/esphome/components/mdns/mdns_esp8266.cpp b/esphome/components/mdns/mdns_esp8266.cpp index d13aee5f1e8..f8ef014b099 100644 --- a/esphome/components/mdns/mdns_esp8266.cpp +++ b/esphome/components/mdns/mdns_esp8266.cpp @@ -19,25 +19,21 @@ namespace esphome::mdns { // from the main loop afterwards. class GuardedMDNSResponder : public ::esp8266::MDNSImplementation::MDNSResponder { public: - void update_guarded() { - this->run_guarded_([this]() { this->update(); }); - } - void close_guarded() { - this->run_guarded_([this]() { this->close(); }); - } + void update_guarded() { this->run_guarded_(&GuardedMDNSResponder::update); } + void close_guarded() { this->run_guarded_(&GuardedMDNSResponder::close); } private: - template void run_guarded_(F &&fn) { + void run_guarded_(bool (GuardedMDNSResponder::*fn)()) { UdpContext *ctx = this->m_pUDPContext; if (ctx == nullptr) { - fn(); + (this->*fn)(); return; } // Set every time: a restart replaces the context together with its stock handler ctx->onRx([this]() { this->on_rx_(); }); this->pending_rx_ = 0; this->in_loop_call_ = true; - fn(); + (this->*fn)(); // Still counting here, so packets arriving during a yield in the drain queue behind it while (this->pending_rx_ > 0) { this->pending_rx_--;