From 0d81306481ebd66e2dd6ab50cb66687bea2fd428 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 13 May 2025 21:07:10 -0500 Subject: [PATCH] cleanup --- esphome/components/api/api_connection.cpp | 32 ++++++++++++----------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 3443030a73..e911ece7eb 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -1538,23 +1538,25 @@ void APIConnection::subscribe_home_assistant_states(const SubscribeHomeAssistant bool APIConnection::try_to_clear_buffer(bool log_out_of_space) { if (this->remove_) return false; - if (!this->helper_->can_write_without_blocking()) { + if (this->helper_->can_write_without_blocking()) { delay(0); - APIError err = this->helper_->loop(); - if (err != APIError::OK) { - on_fatal_error(); - ESP_LOGW(TAG, "%s: Socket operation failed: %s errno=%d", this->client_combined_info_.c_str(), - api_error_to_str(err), errno); - return false; - } - if (!this->helper_->can_write_without_blocking()) { - if (log_out_of_space) { - ESP_LOGV(TAG, "Cannot send message because of TCP buffer space"); - } - delay(0); - return false; - } + return true; } + APIError err = this->helper_->loop(); + if (err != APIError::OK) { + on_fatal_error(); + ESP_LOGW(TAG, "%s: Socket operation failed: %s errno=%d", this->client_combined_info_.c_str(), + api_error_to_str(err), errno); + return false; + } + if (this->helper_->can_write_without_blocking()) { + return true; + } + if (log_out_of_space) { + ESP_LOGV(TAG, "Cannot send message because of TCP buffer space"); + } + delay(0); + return false; } bool APIConnection::send_buffer(ProtoWriteBuffer buffer, uint32_t message_type) { if (!this->try_to_clear_buffer(message_type != 29)) { // SubscribeLogsResponse