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

Layer 5 (Session) - event queue dispatcher and session lifecycle. More...

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

Go to the source code of this file.

Functions

void server_tick (int worker_id=0)
 Drive the session layer for one Arduino loop iteration.
 
void http_reset (uint8_t slot_id)
 Reset the HTTP parser for a connection slot.
 
void http_conn_open (uint8_t slot_id)
 Initialize a slot for a freshly-accepted HTTP connection.
 
void http_parse (uint8_t slot_id)
 Drain the transport ring buffer and advance the HTTP parser.
 

Detailed Description

Layer 5 (Session) - event queue dispatcher and session lifecycle.

The session layer is the bridge between the interrupt-driven transport layer and the application-layer HTTP handler. It processes all pending events from the FreeRTOS queue in a single bounded loop, ensuring that server_tick() has a deterministic worst-case execution time of O(queue_depth + MAX_CONNS).

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file session.h.

Function Documentation

◆ server_tick()

void server_tick ( int  worker_id = 0)

Drive the session layer for one Arduino loop iteration.

Call this function from your loop() (or indirectly via DetWebServer::handle()). It performs three actions in order:

  1. Timeout sweep - calls DeterministicAsyncTCP::check_timeouts() to force-close connections that have been idle for > CONN_TIMEOUT_MS.
  2. Event drain - dequeues all pending TcpEvt records from the FreeRTOS queue. Each event is dispatched:
  3. Returns - upper layers may then inspect http_pool[] for ParseState::PARSE_COMPLETE slots and send responses.
Note
The event-drain loop is bounded by the queue depth (16 entries). Even in the absolute worst case this function executes in O(1).

Definition at line 91 of file session.cpp.

References Listener::active, DeterministicAsyncTCP::check_timeouts(), listener_pool, MAX_LISTENERS, and Listener::queue.

Referenced by DetWebServer::service_once().

◆ http_reset()

void http_reset ( uint8_t  slot_id)

Reset the HTTP parser for a connection slot.

Delegates to http_parser_reset() for the slot's request struct. Silently ignores out-of-range slot IDs.

Parameters
slot_idIndex into conn_pool / http_pool (0 … MAX_CONNS-1).

Definition at line 40 of file presentation.cpp.

References http_parser_reset(), http_pool, MAX_CONNS, and HttpReq::slot_id.

Referenced by DetWebServer::begin(), http_conn_open(), DetWebServer::http_poll_slot(), DetWebServer::redirect(), DetWebServer::send(), DetWebServer::send_chunked(), DetWebServer::send_empty(), DetWebServer::send_template(), and DetWebServer::stop().

◆ http_conn_open()

void http_conn_open ( uint8_t  slot_id)

Initialize a slot for a freshly-accepted HTTP connection.

Resets the HTTP parser (like http_reset()) and, when keep-alive is enabled, zeroes the slot's persistent request counter. The session layer calls this on EvtType::EVT_CONNECT; http_reset() is used for the lighter inter-request reset that must not clear the counter. With keep-alive off this is identical to http_reset().

Parameters
slot_idIndex into conn_pool / http_pool (0 … MAX_CONNS-1).

Definition at line 65 of file presentation.cpp.

References http_reset(), and MAX_CONNS.

◆ http_parse()

void http_parse ( uint8_t  slot_id)

Drain the transport ring buffer and advance the HTTP parser.

Reads all available bytes from the slot's transport ring buffer and feeds each byte to http_parser_feed(). Stops early if the parser reaches a terminal state (ParseState::PARSE_COMPLETE, ParseState::PARSE_ERROR, ParseState::PARSE_ENTITY_TOO_LARGE, ParseState::PARSE_URI_TOO_LONG).

Silently ignores out-of-range slot IDs.

Parameters
slot_idConnection slot to parse.

Definition at line 76 of file presentation.cpp.

References http_parser_feed(), http_pool, MAX_CONNS, PARSE_COMPLETE, PARSE_ENTITY_TOO_LARGE, PARSE_ERROR, HttpReq::parse_state, PARSE_URI_TOO_LONG, and ws_find().

Referenced by DetWebServer::http_poll_slot().