From 26af1cf650ea442479b6d9c408cc88cfb40d2c88 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 15 May 2025 02:32:19 -0500 Subject: [PATCH] preen --- esphome/components/api/api_frame_helper.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/esphome/components/api/api_frame_helper.cpp b/esphome/components/api/api_frame_helper.cpp index 3eae8a58e7..efb0b3632d 100644 --- a/esphome/components/api/api_frame_helper.cpp +++ b/esphome/components/api/api_frame_helper.cpp @@ -84,7 +84,8 @@ APIError APIFrameHelper::write_raw_(const struct iovec *iov, int iovcnt) { } // Try to send any existing buffered data first - while (!this->tx_buf_.empty()) { + bool tx_buf_empty = this->tx_buf_.empty(); + while (!tx_buf_empty) { // Get the first buffer in the queue SendBuffer &front_buffer = this->tx_buf_.front(); @@ -110,12 +111,14 @@ APIError APIFrameHelper::write_raw_(const struct iovec *iov, int iovcnt) { } else { // Buffer completely sent, remove it from the queue this->tx_buf_.pop_front(); + // Update empty status for the loop condition + tx_buf_empty = this->tx_buf_.empty(); // Continue loop to try sending the next buffer } } // If we still have pending data, append the new data to the queue - if (!this->tx_buf_.empty()) { + if (!tx_buf_empty) { // Add new data as a new buffer SendBuffer buffer;