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

Static-only facade over the raw lwIP TCP API. More...

#include <transport.h>

Static Public Member Functions

static int32_t init (uint16_t port, const WebServerConfig *cfg=nullptr)
 Initialise the TCP stack, create the event queue, and begin listening.
 
static void stop ()
 Stop the server: abort all connections, close the listener, free the queue.
 
static void check_timeouts ()
 Scan the pool and force-close connections idle for > conn_timeout_ms.
 
static size_t heap_needed ()
 Always returns 0 — the library makes no heap allocations.
 
static bool heap_available ()
 Always returns true — no heap allocation means no pre-flight needed.
 

Static Public Attributes

static QueueHandle_t queue = nullptr
 FreeRTOS queue handle shared between lwIP callbacks and server_tick().
 
static uint32_t conn_timeout_ms = CONN_TIMEOUT_MS
 Runtime connection-idle timeout in milliseconds.
 

Detailed Description

Static-only facade over the raw lwIP TCP API.

All state is class-level (no instances). Initialises the connection pool, the FreeRTOS event queue, and the lwIP listening PCB once per boot via init(). The lwIP callbacks (lowlevel_accept_cb, lowlevel_recv_cb, …) are private implementation details in transport.cpp.

Definition at line 124 of file transport.h.

Member Function Documentation

◆ init()

int32_t DeterministicAsyncTCP::init ( uint16_t  port,
const WebServerConfig cfg = nullptr 
)
static

Initialise the TCP stack, create the event queue, and begin listening.

Checks whether enough heap is available before attempting queue creation. Zeroes the connection pool and stores the runtime config.

Parameters
portTCP port to bind and listen on.
cfgOptional runtime config. Pass nullptr to use defaults.
Returns
Positive value on success; negative value whose absolute value is the number of heap bytes needed when initialisation fails.

Definition at line 62 of file transport.cpp.

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

Referenced by DetWebServer::begin().

◆ stop()

void DeterministicAsyncTCP::stop ( )
static

Stop the server: abort all connections, close the listener, free the queue.

Safe to call from the main-loop task. After stop() returns, init() may be called again to restart.

Definition at line 103 of file transport.cpp.

References CONN_ACTIVE, CONN_FREE, conn_pool, MAX_CONNS, TcpConn::pcb, queue, and TcpConn::state.

Referenced by DetWebServer::stop().

◆ check_timeouts()

void DeterministicAsyncTCP::check_timeouts ( )
static

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

Called at the start of every server_tick() call, before the 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 CONN_FREE and pcb cleared before tcp_abort() is called, so any in-flight lwIP callback for that PCB will see slot->state != CONN_ACTIVE and exit without touching the slot.

Definition at line 135 of file transport.cpp.

References CONN_ACTIVE, CONN_FREE, conn_pool, conn_timeout_ms, EVT_ERROR, TcpConn::last_activity_ms, MAX_CONNS, TcpConn::pcb, and TcpConn::state.

Referenced by server_tick().

◆ heap_needed()

size_t DeterministicAsyncTCP::heap_needed ( )
static

Always returns 0 — the library makes no heap allocations.

The event queue is backed by statically-allocated BSS storage (_queue_struct + _queue_storage in transport.cpp). Retained for API compatibility with code that calls it before begin().

Definition at line 52 of file transport.cpp.

Referenced by DetWebServer::heap_needed().

◆ heap_available()

bool DeterministicAsyncTCP::heap_available ( )
static

Always returns true — no heap allocation means no pre-flight needed.

Retained for API compatibility. Safe to call or omit.

Definition at line 57 of file transport.cpp.

Referenced by DetWebServer::heap_available().

Member Data Documentation

◆ queue

QueueHandle_t DeterministicAsyncTCP::queue = nullptr
static

FreeRTOS queue handle shared between lwIP callbacks and server_tick().

Events are posted from tcpip_thread context via xQueueSend() (not the ISR variant) because lwIP callbacks run in a task, not a hardware ISR. Queue depth is EVT_QUEUE_DEPTH, sized for MAX_CONNS * 4 event bursts. Backed by a static BSS array; no heap is allocated.

Definition at line 170 of file transport.h.

Referenced by init(), server_tick(), and stop().

◆ 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 init() time. Defaults to CONN_TIMEOUT_MS if no config is supplied.

Definition at line 178 of file transport.h.

Referenced by check_timeouts(), and init().


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