DeterministicESPAsyncWebServer v6.27.1
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 "../transport/tcp.h"
22#include "freertos/FreeRTOS.h"
23#include "freertos/queue.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 * - `EvtType::EVT_CONNECT / EvtType::EVT_DISCONNECT / EvtType::EVT_ERROR` → http_reset()
38 * - `EvtType::EVT_DATA` → http_parse()
39 *
40 * 3. **Returns** - upper layers may then inspect http_pool[] for
41 * ParseState::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(int worker_id = 0);
47
48// ---------------------------------------------------------------------------
49// Forward declarations for Layer 6 functions used by server_tick()
50// ---------------------------------------------------------------------------
51
52/*
53 * 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 * Initialize a slot for a freshly-accepted HTTP connection (Layer 6 forward decl).
61 * Resets the parser and (keep-alive) the per-connection request tally.
62 * @param slot_id Connection slot to open.
63 * @see http_conn_open in presentation.h
64 */
65void http_conn_open(uint8_t slot_id);
66
67/*
68 * Advance the HTTP parser for a slot (Layer 6 forward decl).
69 * @param slot_id Connection slot to parse.
70 * @see http_parse in presentation.h
71 */
72void http_parse(uint8_t slot_id);
73
74#endif
void http_reset(uint8_t slot_id)
Reset the HTTP parser for a connection slot.
void http_parse(uint8_t slot_id)
Drain the transport ring buffer and advance the HTTP parser.
void http_conn_open(uint8_t slot_id)
Initialize a slot for a freshly-accepted HTTP connection.
void server_tick(int worker_id=0)
Drive the session layer for one Arduino loop iteration.
Definition session.cpp:91