From a59559038670261daa137f6fac01cfee504c681b Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 7 Sep 2026 16:14:21 +0200 Subject: [PATCH] [api] Inline the connect grace predicate One caller and a two term body: inlined it is 48 bytes smaller on ESP8266 than the out of line function plus its call. --- esphome/components/api/api_connection.cpp | 6 ------ esphome/components/api/api_connection.h | 6 +++++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/esphome/components/api/api_connection.cpp b/esphome/components/api/api_connection.cpp index 313783863e..da4b7d7702 100644 --- a/esphome/components/api/api_connection.cpp +++ b/esphome/components/api/api_connection.cpp @@ -77,8 +77,6 @@ static constexpr uint32_t KEEPALIVE_DISCONNECT_TIMEOUT = (KEEPALIVE_TIMEOUT_MS * // WiFi (-70 dBm+), TCP retransmissions push real-world handshake times to // 28-30s. See https://github.com/esphome/esphome/issues/14999 static constexpr uint32_t HANDSHAKE_TIMEOUT_MS = 60000; -// How long a new connection holds off the spare ephemeral refill -static constexpr uint32_t CONNECT_GRACE_MS = 1000; static constexpr auto ESPHOME_VERSION_REF = StringRef::from_lit(ESPHOME_VERSION); @@ -252,10 +250,6 @@ void APIConnection::begin_iterator_(ActiveIterator type) { } } -bool APIConnection::is_still_connecting(uint32_t now) { - return !this->is_authenticated() && now - this->last_traffic_ < CONNECT_GRACE_MS; -} - void APIConnection::loop() { if (this->flags_.next_close) { // requested a disconnect - don't close socket here, let APIServer::loop() do it diff --git a/esphome/components/api/api_connection.h b/esphome/components/api/api_connection.h index 206778282e..12463dd5ae 100644 --- a/esphome/components/api/api_connection.h +++ b/esphome/components/api/api_connection.h @@ -316,12 +316,16 @@ class APIConnection final : public APIServerConnectionBase { void on_noise_encryption_set_key_request(const NoiseEncryptionSetKeyRequest &msg); #endif + // How long a new connection holds off the spare ephemeral refill + static constexpr uint32_t CONNECT_GRACE_MS = 1000; bool is_authenticated() { return static_cast(this->flags_.connection_state) == ConnectionState::AUTHENTICATED; } // Unauthenticated and within its grace period; an older unauthenticated // connection is a stale half open client and no longer counts - bool is_still_connecting(uint32_t now); + bool is_still_connecting(uint32_t now) { + return !this->is_authenticated() && now - this->last_traffic_ < CONNECT_GRACE_MS; + } bool is_connection_setup() { return static_cast(this->flags_.connection_state) == ConnectionState::CONNECTED || this->is_authenticated();