From 428371d685e6da782d8d4c87b9015caddcff2a93 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 15 May 2025 03:51:08 -0500 Subject: [PATCH] preen --- esphome/components/api/api_frame_helper.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/esphome/components/api/api_frame_helper.cpp b/esphome/components/api/api_frame_helper.cpp index 53b8c8f01f..05fa4ba87b 100644 --- a/esphome/components/api/api_frame_helper.cpp +++ b/esphome/components/api/api_frame_helper.cpp @@ -67,21 +67,17 @@ const char *api_error_to_str(APIError err) { // Helper method to buffer data from IOVs void APIFrameHelper::buffer_data_from_iov_(const struct iovec *iov, int iovcnt, size_t total_write_len) { - // Add new data to the buffer queue SendBuffer buffer; buffer.data.reserve(total_write_len); - for (int i = 0; i < iovcnt; i++) { const uint8_t *data = reinterpret_cast(iov[i].iov_base); buffer.data.insert(buffer.data.end(), data, data + iov[i].iov_len); } - this->tx_buf_.push_back(std::move(buffer)); } -// Common implementation for writing raw data to socket +// This method writes data to socket or buffers it APIError APIFrameHelper::write_raw_(const struct iovec *iov, int iovcnt) { - // This method writes data to socket or buffers it // Returns APIError::OK if successful (or would block, but data has been buffered) // Returns APIError::SOCKET_WRITE_FAILED if socket write failed, and sets state to FAILED @@ -100,14 +96,10 @@ APIError APIFrameHelper::write_raw_(const struct iovec *iov, int iovcnt) { // Try to send any existing buffered data first if there is any if (!this->tx_buf_.empty()) { APIError send_result = try_send_tx_buf_(); - // If real error occurred (not just WOULD_BLOCK), return it if (send_result != APIError::OK && send_result != APIError::WOULD_BLOCK) { return send_result; } - // At this point, either we succeeded in sending all buffers (tx_buf_ is now empty), - // or we got WOULD_BLOCK (some buffers remain). In either case, we need to check - // if the buffer is empty before proceeding to direct sending. // If there is still data in the buffer, we can't send, buffer // the new data and return