From 5bee336a76e1975d82b99d5ae8798b765003912e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 16 Mar 2026 12:31:36 -1000 Subject: [PATCH] Single enqueue_or_fail_ tail call in write_raw_ --- esphome/components/api/api_frame_helper.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/esphome/components/api/api_frame_helper.cpp b/esphome/components/api/api_frame_helper.cpp index 482f3aa0b9..12151ebacf 100644 --- a/esphome/components/api/api_frame_helper.cpp +++ b/esphome/components/api/api_frame_helper.cpp @@ -120,10 +120,11 @@ APIError APIFrameHelper::write_raw_(const struct iovec *iov, int iovcnt, uint16_ if (this->check_socket_write_err_(errno) != APIError::WOULD_BLOCK) return APIError::SOCKET_WRITE_FAILED; } + // If drain didn't fully clear, skip direct send and queue behind backlog } - // If no backlog (either drained or was empty), try to send directly if (this->overflow_buf_.empty()) { + // No backlog — try to send directly // Optimize for single iovec case (common for plaintext API) ssize_t sent = (iovcnt == 1) ? this->socket_->write(iov[0].iov_base, iov[0].iov_len) : this->socket_->writev(iov, iovcnt);