mirror of
https://github.com/esphome/esphome.git
synced 2025-09-14 09:12:19 +01:00
Optimize OTA loop to avoid unnecessary stack allocations
This commit is contained in:
@@ -82,7 +82,13 @@ void ESPHomeOTAComponent::dump_config() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESPHomeOTAComponent::loop() { this->handle_(); }
|
void ESPHomeOTAComponent::loop() {
|
||||||
|
// Skip handle_() call if no client connected and no incoming connections
|
||||||
|
// This optimization reduces idle loop overhead when OTA is not active
|
||||||
|
if (client_ != nullptr || (server_ && server_->ready())) {
|
||||||
|
this->handle_();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static const uint8_t FEATURE_SUPPORTS_COMPRESSION = 0x01;
|
static const uint8_t FEATURE_SUPPORTS_COMPRESSION = 0x01;
|
||||||
|
|
||||||
@@ -102,12 +108,10 @@ void ESPHomeOTAComponent::handle_() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (client_ == nullptr) {
|
if (client_ == nullptr) {
|
||||||
// Check if the server socket is ready before accepting
|
// We already checked server_->ready() in loop(), so we can accept directly
|
||||||
if (this->server_->ready()) {
|
struct sockaddr_storage source_addr;
|
||||||
struct sockaddr_storage source_addr;
|
socklen_t addr_len = sizeof(source_addr);
|
||||||
socklen_t addr_len = sizeof(source_addr);
|
client_ = server_->accept((struct sockaddr *) &source_addr, &addr_len);
|
||||||
client_ = server_->accept((struct sockaddr *) &source_addr, &addr_len);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (client_ == nullptr)
|
if (client_ == nullptr)
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user