From 31f5bbf62366d69a7cfb6b173ae9d61b5c5298a6 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 15 May 2025 12:52:25 -0500 Subject: [PATCH] cleanup --- esphome/components/api/api_frame_helper.cpp | 22 ++++----------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/esphome/components/api/api_frame_helper.cpp b/esphome/components/api/api_frame_helper.cpp index 9e2a59b7e6..8612cfb459 100644 --- a/esphome/components/api/api_frame_helper.cpp +++ b/esphome/components/api/api_frame_helper.cpp @@ -299,15 +299,8 @@ APIError APINoiseFrameHelper::try_read_frame_(ParsedFrame *frame) { } // Only check for available data when starting a new frame read - if (rx_header_buf_len_ == 0) { - ssize_t available = socket_->available(); - if (available == 0) { - return APIError::WOULD_BLOCK; - } else if (available == -1) { - state_ = State::FAILED; - HELPER_LOG("Socket available failed with errno %d", errno); - return APIError::SOCKET_READ_FAILED; - } + if (rx_header_buf_len_ == 0 && socket_->available() == 0) { + return APIError::WOULD_BLOCK; } // read header @@ -828,15 +821,8 @@ APIError APIPlaintextFrameHelper::try_read_frame_(ParsedFrame *frame) { } // Only check for available data when starting a new frame read - if (rx_header_buf_pos_ == 0) { - ssize_t available = socket_->available(); - if (available == 0) { - return APIError::WOULD_BLOCK; - } else if (available == -1) { - state_ = State::FAILED; - HELPER_LOG("Socket read_available failed with errno %d", errno); - return APIError::SOCKET_READ_FAILED; - } + if (rx_header_buf_pos_ == 0 && socket_->available() == 0) { + return APIError::WOULD_BLOCK; } // read header