mirror of
https://github.com/esphome/esphome.git
synced 2026-09-15 17:18:40 +00:00
[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.
This commit is contained in:
@@ -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<void *>(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<uint8_t *>(iov[i].iov_base), iov[i].iov_len);
|
||||
|
||||
@@ -202,7 +202,7 @@ class APIFrameHelper {
|
||||
if (sent == static_cast<ssize_t>(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<ssize_t>(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::Socket> socket_;
|
||||
|
||||
@@ -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<uint8_t *>(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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user