DeterministicESPAsyncWebServer 1.2.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
transport.h File Reference

Layer 4 (Transport) — TCP connection pool, ring buffers, and lwIP integration. More...

#include "DetWebServerConfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#include "lwip/tcp.h"
#include <Arduino.h>

Go to the source code of this file.

Classes

struct  TcpConn
 A single TCP connection context. More...
 
struct  TcpEvt
 Event record posted from lwIP callbacks to the main-loop task. More...
 
class  DeterministicAsyncTCP
 Static-only facade over the raw lwIP TCP API. More...
 

Enumerations

enum  ConnState { CONN_FREE , CONN_ACTIVE , CONN_CLOSING }
 Lifecycle state of a connection pool slot. More...
 
enum  EvtType { EVT_CONNECT , EVT_DATA , EVT_DISCONNECT , EVT_ERROR }
 Type of connection event posted to the FreeRTOS event queue. More...
 

Variables

TcpConn conn_pool [MAX_CONNS]
 Static pool of connection contexts. Defined in transport.cpp.
 

Detailed Description

Layer 4 (Transport) — TCP connection pool, ring buffers, and lwIP integration.

Defines the static connection pool and the FreeRTOS event queue used to pass connection events from lwIP callbacks (running in tcpip_thread) to the Arduino main-loop task.

Concurrency model

Context Reads Writes
lwIP callbacks rx_head (to check full) rx_buffer[], rx_head
Arduino loop rx_buffer[], rx_tail rx_tail

rx_head and rx_tail are volatile to prevent the compiler from caching them across the inter-task boundary. The single-producer / single-consumer ring buffer design guarantees correctness without a mutex as long as writes to each index are atomic (true for 32-bit Xtensa).

Backpressure When the ring buffer is full, tcp_recved() is called with only the bytes actually copied — not p->tot_len. This shrinks the TCP receive window and applies backpressure to the sender rather than silently dropping data.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file transport.h.

Enumeration Type Documentation

◆ ConnState

enum ConnState

Lifecycle state of a connection pool slot.

Transitions:

  • CONN_FREE → CONN_ACTIVE : accept callback fires.
  • CONN_ACTIVE → CONN_FREE : graceful close, error, or timeout.
  • CONN_ACTIVE → CONN_CLOSING : (reserved for future half-close support).
Enumerator
CONN_FREE 

Slot is available; no PCB is attached.

CONN_ACTIVE 

Live connection; PCB is valid.

CONN_CLOSING 

FIN sent; waiting for final ACK (reserved).

Definition at line 54 of file transport.h.

◆ EvtType

enum EvtType

Type of connection event posted to the FreeRTOS event queue.

Enumerator
EVT_CONNECT 

New connection accepted.

EVT_DATA 

Data received; bytes are already in the ring buffer.

EVT_DISCONNECT 

Remote peer closed the connection gracefully.

EVT_ERROR 

lwIP reported an error (PCB may already be freed).

Definition at line 90 of file transport.h.

Variable Documentation

◆ conn_pool