DeterministicESPAsyncWebServer 1.2.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
session.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file session.h
6 * @brief Layer 5 (Session) — event queue dispatcher and session lifecycle.
7 *
8 * The session layer is the bridge between the interrupt-driven transport
9 * layer and the application-layer HTTP handler. It processes all pending
10 * events from the FreeRTOS queue in a single bounded loop, ensuring that
11 * `server_tick()` has a deterministic worst-case execution time of
12 * O(queue_depth + MAX_CONNS).
13 *
14 * @author Douglas Quigg (dstroy0)
15 * @date 2026
16 */
17
18#ifndef DETERMINISTICESPASYNCWEBSERVER_SESSION_H
19#define DETERMINISTICESPASYNCWEBSERVER_SESSION_H
20
21#include "freertos/FreeRTOS.h"
22#include "freertos/queue.h"
23#include "transport.h"
24#include <Arduino.h>
25
26/**
27 * @brief Drive the session layer for one Arduino loop iteration.
28 *
29 * Call this function from your `loop()` (or indirectly via
30 * DetWebServer::handle()). It performs three actions in order:
31 *
32 * 1. **Timeout sweep** — calls DeterministicAsyncTCP::check_timeouts()
33 * to force-close connections that have been idle for > CONN_TIMEOUT_MS.
34 *
35 * 2. **Event drain** — dequeues all pending TcpEvt records from the
36 * FreeRTOS queue. Each event is dispatched:
37 * - `EVT_CONNECT / EVT_DISCONNECT / EVT_ERROR` → http_reset()
38 * - `EVT_DATA` → http_parse()
39 *
40 * 3. **Returns** — upper layers may then inspect http_pool[] for
41 * PARSE_COMPLETE slots and send responses.
42 *
43 * @note The event-drain loop is bounded by the queue depth (16 entries).
44 * Even in the absolute worst case this function executes in O(1).
45 */
46void server_tick();
47
48// ---------------------------------------------------------------------------
49// Forward declarations for Layer 6 functions used by server_tick()
50// ---------------------------------------------------------------------------
51
52/**
53 * @brief Reset a presentation-layer parser slot (Layer 6 forward decl).
54 * @param slot_id Connection slot to reset.
55 * @see http_reset in presentation.h
56 */
57void http_reset(uint8_t slot_id);
58
59/**
60 * @brief Advance the HTTP parser for a slot (Layer 6 forward decl).
61 * @param slot_id Connection slot to parse.
62 * @see http_parse in presentation.h
63 */
64void http_parse(uint8_t slot_id);
65
66#endif
void http_reset(uint8_t slot_id)
Reset a presentation-layer parser slot (Layer 6 forward decl).
void http_parse(uint8_t slot_id)
Advance the HTTP parser for a slot (Layer 6 forward decl).
void server_tick()
Drive the session layer for one Arduino loop iteration.
Definition session.cpp:15
Layer 4 (Transport) — TCP connection pool, ring buffers, and lwIP integration.