This commit is contained in:
J. Nick Koston
2025-05-13 21:04:07 -05:00
parent dcdc2a30c5
commit 7cf1db1382
2 changed files with 12 additions and 7 deletions

View File

@@ -153,7 +153,7 @@ void APIConnection::loop() {
return;
}
if (this->can_write_without_blocking()) {
if (this->try_to_send_buffer(true)) {
this->deferred_message_queue_.process_queue();
}
@@ -1535,7 +1535,7 @@ NoiseEncryptionSetKeyResponse APIConnection::noise_encryption_set_key(const Nois
void APIConnection::subscribe_home_assistant_states(const SubscribeHomeAssistantStatesRequest &msg) {
state_subs_at_ = 0;
}
bool APIConnection::send_buffer(ProtoWriteBuffer buffer, uint32_t message_type) {
bool APIConnection::try_to_send_buffer(bool log_out_of_space) {
if (this->remove_)
return false;
if (!this->helper_->can_write_without_blocking()) {
@@ -1548,14 +1548,18 @@ bool APIConnection::send_buffer(ProtoWriteBuffer buffer, uint32_t message_type)
return false;
}
if (!this->helper_->can_write_without_blocking()) {
// SubscribeLogsResponse
if (message_type != 29) {
if (log_out_of_space) {
ESP_LOGV(TAG, "Cannot send message because of TCP buffer space");
}
delay(0);
return false;
}
}
}
bool APIConnection::send_buffer(ProtoWriteBuffer buffer, uint32_t message_type) {
if (!this->try_to_send_buffer(message_type != 29)) { // SubscribeLogsResponse
return false;
}
APIError err = this->helper_->write_packet(message_type, buffer.get_buffer()->data(), buffer.get_buffer()->size());
if (err == APIError::WOULD_BLOCK)

View File

@@ -411,6 +411,7 @@ class APIConnection : public APIServerConnection {
this->proto_write_buffer_.reserve(reserve_size);
return {&this->proto_write_buffer_};
}
bool try_to_send_buffer(bool log_out_of_space);
bool send_buffer(ProtoWriteBuffer buffer, uint32_t message_type) override;
/**
@@ -440,7 +441,7 @@ class APIConnection : public APIServerConnection {
template<typename EntityT> bool send_state_(EntityT *entity, bool (APIConnection::*try_send_func)(EntityT *)) {
if (!this->state_subscription_)
return false;
if (this->can_write_without_blocking() && (this->*try_send_func)(entity)) {
if (this->try_to_send_buffer() && (this->*try_send_func)(entity)) {
return true;
}
this->deferred_message_queue_.defer(entity, reinterpret_cast<send_message_t>(try_send_func));
@@ -470,7 +471,7 @@ class APIConnection : public APIServerConnection {
Args... args) {
if (!this->state_subscription_)
return false;
if (this->can_write_without_blocking() && (this->*try_send_state_func)(entity, state, args...)) {
if (this->try_to_send_buffer() && (this->*try_send_state_func)(entity, state, args...)) {
return true;
}
this->deferred_message_queue_.defer(entity, reinterpret_cast<send_message_t>(try_send_entity_func));
@@ -485,7 +486,7 @@ class APIConnection : public APIServerConnection {
* @param try_send_func The function that tries to send the info
*/
template<typename EntityT> void send_info_(EntityT *entity, bool (APIConnection::*try_send_func)(EntityT *)) {
if (this->can_write_without_blocking() && (this->*try_send_func)(entity)) {
if (this->try_to_send_buffer() && (this->*try_send_func)(entity)) {
return;
}
this->deferred_message_queue_.defer(entity, reinterpret_cast<send_message_t>(try_send_func));