mirror of
https://github.com/esphome/esphome.git
synced 2025-09-14 09:12:19 +01:00
preen
This commit is contained in:
@@ -160,7 +160,14 @@ void APIServer::loop() {
|
|||||||
// Process clients and remove disconnected ones in a single pass
|
// Process clients and remove disconnected ones in a single pass
|
||||||
if (!this->clients_.empty()) {
|
if (!this->clients_.empty()) {
|
||||||
// Check network connectivity once for all clients
|
// Check network connectivity once for all clients
|
||||||
bool network_connected = network::is_connected();
|
if (!network::is_connected()) {
|
||||||
|
// Network is down - disconnect all clients
|
||||||
|
for (auto &client : this->clients_) {
|
||||||
|
client->on_fatal_error();
|
||||||
|
ESP_LOGW(TAG, "%s: Network unavailable; disconnecting", client->get_client_combined_info().c_str());
|
||||||
|
}
|
||||||
|
return; // All clients will be marked for removal, cleanup will happen next loop
|
||||||
|
}
|
||||||
|
|
||||||
size_t client_index = 0;
|
size_t client_index = 0;
|
||||||
while (client_index < this->clients_.size()) {
|
while (client_index < this->clients_.size()) {
|
||||||
@@ -184,14 +191,8 @@ void APIServer::loop() {
|
|||||||
|
|
||||||
// Don't increment client_index since we need to process the swapped element
|
// Don't increment client_index since we need to process the swapped element
|
||||||
} else {
|
} else {
|
||||||
// Process active client only if network is connected
|
// Network is connected, process the client
|
||||||
if (network_connected) {
|
client->loop();
|
||||||
client->loop();
|
|
||||||
} else {
|
|
||||||
// Force disconnect when network is unavailable
|
|
||||||
client->on_fatal_error();
|
|
||||||
ESP_LOGW(TAG, "%s: Network unavailable; disconnecting", client->get_client_combined_info().c_str());
|
|
||||||
}
|
|
||||||
client_index++; // Move to next client
|
client_index++; // Move to next client
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user