|
ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
|
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. | |
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.
|
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.
| cfg | Optional runtime config. Pass nullptr to use compile-time defaults (CONN_TIMEOUT_MS). |
Definition at line 819 of file tcp.cpp.
References CONN_FREE, conn_pool, conn_timeout_ms, CONN_TIMEOUT_MS, WebServerConfig::conn_timeout_ms, TcpConn::id, MAX_CONNS, and pc_conn_set_state().
Referenced by PC::begin().
|
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 838 of file tcp.cpp.
References CONN_ACTIVE, CONN_CLOSING, CONN_FREE, conn_pool, MAX_CONNS, pc_conn_abort(), pc_conn_detach(), pc_conn_set_state(), PC_OBS_TRANSITION, TcpConn::pcb, and TcpConn::state.
Referenced by PC::stop().
|
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 PC_WORKER_COUNT=1 every slot is owned by worker 0, so it sweeps the whole pool as before.
Definition at line 958 of file tcp.cpp.
References CONN_ACTIVE, CONN_CLOSING, CONN_FREE, conn_pool, conn_timeout_ms, EVT_ERROR, TcpConn::id, TcpConn::last_activity_ms, MAX_CONNS, TcpConn::owner, PC_CLOSING_TIMEOUT_MS, pc_conn_abort(), pc_conn_detach(), pc_conn_set_state(), pc_millis(), PC_OBS_TRANSITION, TcpConn::pcb, and TcpConn::state.
Referenced by server_tick().
|
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 228 of file tcp.h.
Referenced by check_timeouts(), and pool_init().