mirror of
https://github.com/esphome/esphome.git
synced 2025-09-11 14:08:45 +00:00
preen
This commit is contained in:
@@ -66,6 +66,17 @@ const char *api_error_to_str(APIError err) {
|
|||||||
return "UNKNOWN";
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Default implementation for loop - handles sending buffered data
|
||||||
|
APIError APIFrameHelper::loop() {
|
||||||
|
if (!this->tx_buf_.empty()) {
|
||||||
|
APIError err = try_send_tx_buf_();
|
||||||
|
if (err != APIError::OK && err != APIError::WOULD_BLOCK) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return APIError::OK; // Convert WOULD_BLOCK to OK to avoid connection termination
|
||||||
|
}
|
||||||
|
|
||||||
// Helper method to buffer data from IOVs
|
// Helper method to buffer data from IOVs
|
||||||
void APIFrameHelper::buffer_data_from_iov_(const struct iovec *iov, int iovcnt, uint16_t total_write_len) {
|
void APIFrameHelper::buffer_data_from_iov_(const struct iovec *iov, int iovcnt, uint16_t total_write_len) {
|
||||||
SendBuffer buffer;
|
SendBuffer buffer;
|
||||||
@@ -287,13 +298,8 @@ APIError APINoiseFrameHelper::loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this->tx_buf_.empty()) {
|
// Use base class implementation for buffer sending
|
||||||
APIError err = try_send_tx_buf_();
|
return APIFrameHelper::loop();
|
||||||
if (err != APIError::OK && err != APIError::WOULD_BLOCK) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return APIError::OK; // Convert WOULD_BLOCK to OK to avoid connection termination
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Read a packet into the rx_buf_. If successful, stores frame data in the frame parameter
|
/** Read a packet into the rx_buf_. If successful, stores frame data in the frame parameter
|
||||||
@@ -829,13 +835,8 @@ APIError APIPlaintextFrameHelper::loop() {
|
|||||||
if (state_ != State::DATA) {
|
if (state_ != State::DATA) {
|
||||||
return APIError::BAD_STATE;
|
return APIError::BAD_STATE;
|
||||||
}
|
}
|
||||||
if (!this->tx_buf_.empty()) {
|
// Use base class implementation for buffer sending
|
||||||
APIError err = try_send_tx_buf_();
|
return APIFrameHelper::loop();
|
||||||
if (err != APIError::OK && err != APIError::WOULD_BLOCK) {
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return APIError::OK; // Convert WOULD_BLOCK to OK to avoid connection termination
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Read a packet into the rx_buf_. If successful, stores frame data in the frame parameter
|
/** Read a packet into the rx_buf_. If successful, stores frame data in the frame parameter
|
||||||
|
@@ -74,7 +74,7 @@ class APIFrameHelper {
|
|||||||
}
|
}
|
||||||
virtual ~APIFrameHelper() = default;
|
virtual ~APIFrameHelper() = default;
|
||||||
virtual APIError init() = 0;
|
virtual APIError init() = 0;
|
||||||
virtual APIError loop() = 0;
|
virtual APIError loop();
|
||||||
virtual APIError read_packet(ReadPacketBuffer *buffer) = 0;
|
virtual APIError read_packet(ReadPacketBuffer *buffer) = 0;
|
||||||
bool can_write_without_blocking() { return state_ == State::DATA && tx_buf_.empty(); }
|
bool can_write_without_blocking() { return state_ == State::DATA && tx_buf_.empty(); }
|
||||||
std::string getpeername() { return socket_->getpeername(); }
|
std::string getpeername() { return socket_->getpeername(); }
|
||||||
|
Reference in New Issue
Block a user