From 048636d6c32edf0c9bd489782a3d3b0591b4cf19 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 29 Mar 2026 12:13:36 -1000 Subject: [PATCH] [api] Use explicit names: write_raw_fast_, write_raw_buf_, write_raw_iov_ Avoids ambiguous overload resolution between const void* and const iovec* and makes each call site's intent clear. --- esphome/components/api/api_frame_helper.cpp | 6 +++--- esphome/components/api/api_frame_helper.h | 8 ++++---- esphome/components/api/api_frame_helper_noise.cpp | 4 ++-- esphome/components/api/api_frame_helper_plaintext.cpp | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/esphome/components/api/api_frame_helper.cpp b/esphome/components/api/api_frame_helper.cpp index 248e063045..f46693a4e8 100644 --- a/esphome/components/api/api_frame_helper.cpp +++ b/esphome/components/api/api_frame_helper.cpp @@ -113,16 +113,16 @@ APIError APIFrameHelper::drain_overflow_and_handle_errors_() { } // Single-buffer write path: wraps in iovec and delegates. -APIError APIFrameHelper::write_raw_(const void *data, uint16_t len, ssize_t sent) { +APIError APIFrameHelper::write_raw_buf_(const void *data, uint16_t len, ssize_t sent) { struct iovec iov = {const_cast(data), len}; - return this->write_raw_(&iov, 1, len, sent); + return this->write_raw_iov_(&iov, 1, len, sent); } // Handles partial writes, errors, and overflow buffering. // Called when the inline fast path in the header couldn't complete the write, // or directly from cold paths (handshake, error handling). // sent == -1 means either the fast path write returned -1, or there was overflow backlog. -APIError APIFrameHelper::write_raw_(const struct iovec *iov, int iovcnt, uint16_t total_write_len, ssize_t sent) { +APIError APIFrameHelper::write_raw_iov_(const struct iovec *iov, int iovcnt, uint16_t total_write_len, ssize_t sent) { #ifdef HELPER_LOG_PACKETS for (int i = 0; i < iovcnt; i++) { LOG_PACKET_SENDING(reinterpret_cast(iov[i].iov_base), iov[i].iov_len); diff --git a/esphome/components/api/api_frame_helper.h b/esphome/components/api/api_frame_helper.h index cba9d92c74..cc5c6ee569 100644 --- a/esphome/components/api/api_frame_helper.h +++ b/esphome/components/api/api_frame_helper.h @@ -202,7 +202,7 @@ class APIFrameHelper { if (sent == static_cast(len)) [[likely]] return APIError::OK; } - return this->write_raw_(data, len, sent); + return this->write_raw_buf_(data, len, sent); } inline APIError ESPHOME_ALWAYS_INLINE write_raw_fast_(const struct iovec *iov, int iovcnt, uint16_t total_write_len) { ssize_t sent = -1; @@ -211,12 +211,12 @@ class APIFrameHelper { if (sent == static_cast(total_write_len)) [[likely]] return APIError::OK; } - return this->write_raw_(iov, iovcnt, total_write_len, sent); + return this->write_raw_iov_(iov, iovcnt, total_write_len, sent); } // Out-of-line write paths: handle partial writes, errors, overflow buffering - APIError write_raw_(const void *data, uint16_t len, ssize_t sent = -1); - APIError write_raw_(const struct iovec *iov, int iovcnt, uint16_t total_write_len, ssize_t sent = -1); + APIError write_raw_buf_(const void *data, uint16_t len, ssize_t sent = -1); + APIError write_raw_iov_(const struct iovec *iov, int iovcnt, uint16_t total_write_len, ssize_t sent = -1); // Socket ownership (4 bytes on 32-bit, 8 bytes on 64-bit) std::unique_ptr socket_; diff --git a/esphome/components/api/api_frame_helper_noise.cpp b/esphome/components/api/api_frame_helper_noise.cpp index b1499c7557..424f450fd9 100644 --- a/esphome/components/api/api_frame_helper_noise.cpp +++ b/esphome/components/api/api_frame_helper_noise.cpp @@ -537,7 +537,7 @@ APIError APINoiseFrameHelper::write_frame_(const uint8_t *data, uint16_t len) { header[2] = (uint8_t) len; if (len == 0) { - return this->write_raw_(header, 3); + return this->write_raw_buf_(header, 3); } struct iovec iov[2]; iov[0].iov_base = header; @@ -545,7 +545,7 @@ APIError APINoiseFrameHelper::write_frame_(const uint8_t *data, uint16_t len) { iov[1].iov_base = const_cast(data); iov[1].iov_len = len; - return this->write_raw_(iov, 2, 3 + len); + return this->write_raw_iov_(iov, 2, 3 + len); } /** Initiate the data structures for the handshake. diff --git a/esphome/components/api/api_frame_helper_plaintext.cpp b/esphome/components/api/api_frame_helper_plaintext.cpp index f561acfff9..1d2ea5bcb8 100644 --- a/esphome/components/api/api_frame_helper_plaintext.cpp +++ b/esphome/components/api/api_frame_helper_plaintext.cpp @@ -219,11 +219,11 @@ APIError APIPlaintextFrameHelper::read_packet(ReadPacketBuffer *buffer) { "Bad indicator byte"; char msg[INDICATOR_MSG_SIZE]; memcpy_P(msg, MSG_PROGMEM, INDICATOR_MSG_SIZE); - this->write_raw_(msg, INDICATOR_MSG_SIZE); + this->write_raw_buf_(msg, INDICATOR_MSG_SIZE); #else static const char MSG[] = "\x00" "Bad indicator byte"; - this->write_raw_(MSG, INDICATOR_MSG_SIZE); + this->write_raw_buf_(MSG, INDICATOR_MSG_SIZE); #endif } return aerr;