DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
DeterministicAsyncTCP Class Reference

Static-only facade managing the shared TCP connection pool. More...

#include <tcp.h>

Static Public Member Functions

static void pool_init (const WebServerConfig *cfg=nullptr)
 Initialize the connection pool and store the runtime config.
 
static void stop ()
 Abort all active connections and reset the pool to ConnState::CONN_FREE.
 
static void check_timeouts (int worker_id=0)
 Scan the pool and force-close connections idle for > conn_timeout_ms.
 

Static Public Attributes

static uint32_t conn_timeout_ms = CONN_TIMEOUT_MS
 Runtime connection-idle timeout in milliseconds.
 

Detailed Description

Static-only facade managing the shared TCP connection pool.

All state is class-level (no instances). pool_init() initializes the connection pool and the runtime timeout config once per boot (or per restart cycle). Listening sockets and per-listener queues are owned by the listener layer (see listener.h); this class only manages the shared conn_pool[] and the idle-timeout sweep.

Definition at line 169 of file tcp.h.

Member Function Documentation

◆ pool_init()

void DeterministicAsyncTCP::pool_init ( const WebServerConfig cfg = nullptr)
static

Initialize the connection pool and store the runtime config.

Zeroes all connection slots and sets conn_timeout_ms from cfg. Call this before calling listener_add() for each port.

Parameters
cfgOptional runtime config. Pass nullptr to use compile-time defaults (CONN_TIMEOUT_MS).

Definition at line 608 of file tcp.cpp.

References CONN_FREE, conn_pool, conn_timeout_ms, CONN_TIMEOUT_MS, WebServerConfig::conn_timeout_ms, TcpConn::id, MAX_CONNS, and TcpConn::state.

Referenced by DetWebServer::begin().

◆ stop()

void DeterministicAsyncTCP::stop ( )
static

Abort all active connections and reset the pool to ConnState::CONN_FREE.

Does not touch listener PCBs or listener queues - call listener_stop_all() before this if you also want to close the listening sockets. Safe to call from the main-loop task.

Definition at line 625 of file tcp.cpp.

References CONN_ACTIVE, CONN_CLOSING, CONN_FREE, conn_pool, det_conn_abort(), det_conn_detach(), DETWS_OBS_TRANSITION, MAX_CONNS, TcpConn::pcb, and TcpConn::state.

Referenced by DetWebServer::stop().

◆ check_timeouts()

void DeterministicAsyncTCP::check_timeouts ( int  worker_id = 0)
static

Scan the pool and force-close connections idle for > conn_timeout_ms.

Called at the start of every server_tick() call, before any event queue is drained. Uses tcp_abort() (not tcp_close()) because the connection has already timed out and a graceful FIN is not warranted.

A timed-out slot has its state set to ConnState::CONN_FREE and pcb cleared before tcp_abort() is called, so any in-flight lwIP callback for that PCB will see slot->state != ConnState::CONN_ACTIVE and exit without touching the slot.

Only sweeps slots owned by worker_id, so each worker reaps just its own connections (no cross-worker writes). At DETWS_WORKER_COUNT=1 every slot is owned by worker 0, so it sweeps the whole pool as before.

Definition at line 727 of file tcp.cpp.

References CONN_ACTIVE, CONN_CLOSING, CONN_FREE, conn_pool, conn_timeout_ms, det_conn_abort(), det_conn_detach(), DETWS_CLOSING_TIMEOUT_MS, detws_millis(), DETWS_OBS_TRANSITION, EVT_ERROR, TcpConn::last_activity_ms, MAX_CONNS, TcpConn::owner, TcpConn::pcb, and TcpConn::state.

Referenced by server_tick().

Member Data Documentation

◆ conn_timeout_ms

uint32_t DeterministicAsyncTCP::conn_timeout_ms = CONN_TIMEOUT_MS
static

Runtime connection-idle timeout in milliseconds.

Loaded from WebServerConfig::conn_timeout_ms at pool_init() time. Defaults to CONN_TIMEOUT_MS if no config is supplied.

Definition at line 216 of file tcp.h.

Referenced by check_timeouts(), and pool_init().


The documentation for this class was generated from the following files: