FastLED 3.9.15
Loading...
Searching...
No Matches

◆ transitionTo()

void fl::HttpConnection::transitionTo ( ConnectionState newState,
u32 currentTimeMs )
private

Definition at line 161 of file connection.cpp.hpp.

161 {
162 mState = newState;
163
164 // Handle state-specific initialization
165 switch (newState) {
167 resetReconnectAttempts(); // Full reset on user disconnect
168 break;
169
171 // Starting connection attempt
172 break;
173
175 // Initialize data received timestamp (for timeout detection)
176 mLastDataReceivedMs = currentTimeMs;
177 // Initialize heartbeat timestamp to trigger immediate send on first check
178 // Subtract interval from currentTimeMs to ensure timeSince >= interval
179 if (mLastHeartbeatSentMs == 0) {
180 // Use wrapping arithmetic: currentTimeMs - interval
181 // Even if this underflows (currentTimeMs < interval), the unsigned
182 // subtraction in shouldSendHeartbeat will wrap correctly
183 mLastHeartbeatSentMs = currentTimeMs - mConfig.heartbeatIntervalMs;
184 }
185 break;
186
188 // Calculate backoff delay BEFORE incrementing attempts
190 mNextReconnectTimeMs = currentTimeMs + mReconnectDelayMs;
191 // Increment attempts for next reconnection
193 break;
194
196 resetReconnectAttempts(); // Full reset on close
197 break;
198 }
199}
u32 calculateBackoffDelay() const
ConnectionConfig mConfig
Definition connection.h:74
ConnectionState mState
Definition connection.h:75

References calculateBackoffDelay(), fl::CLOSED, fl::CONNECTED, fl::CONNECTING, fl::DISCONNECTED, mConfig, mLastDataReceivedMs, mLastHeartbeatSentMs, mNextReconnectTimeMs, mReconnectAttempts, mReconnectDelayMs, mState, fl::RECONNECTING, and resetReconnectAttempts().

Referenced by close(), connect(), disconnect(), onConnected(), and onDisconnected().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: