DeterministicESPAsyncWebServer 1.2.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
session.cpp
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.cpp
6 * @brief Layer 5 (Session) — event queue processor implementation.
7 *
8 * server_tick() is the only function here. Its bounded loop drains the
9 * entire FreeRTOS queue in one call so that the application layer always
10 * sees the most up-to-date state before checking http_pool[].
11 */
12
13#include "session.h"
14
16{
17 /*
18 * Check timeouts BEFORE draining events. This ensures that a slot
19 * freed by a timeout is already in CONN_FREE state if a coincident
20 * EVT_DISCONNECT or EVT_ERROR is dequeued in the same tick, the
21 * http_reset() call for that event is then a clean no-op.
22 */
24
25 TcpEvt evt;
26 while (xQueueReceive(DeterministicAsyncTCP::queue, &evt, 0) == pdTRUE)
27 {
28 switch (evt.type)
29 {
30 case EVT_CONNECT:
31 case EVT_DISCONNECT:
32 case EVT_ERROR:
33 /* Reset the HTTP parser so the slot is ready for its next request. */
35 break;
36
37 case EVT_DATA:
38 /* Advance the parser; may transition slot to PARSE_COMPLETE. */
40 break;
41 }
42 }
43}
static void check_timeouts()
Scan the pool and force-close connections idle for > conn_timeout_ms.
static QueueHandle_t queue
FreeRTOS queue handle shared between lwIP callbacks and server_tick().
Definition transport.h:170
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 server_tick()
Drive the session layer for one Arduino loop iteration.
Definition session.cpp:15
Layer 5 (Session) — event queue dispatcher and session lifecycle.
Event record posted from lwIP callbacks to the main-loop task.
Definition transport.h:105
EvtType type
What happened.
Definition transport.h:106
uint8_t slot_id
Which connection slot is affected.
Definition transport.h:107
@ EVT_CONNECT
New connection accepted.
Definition transport.h:92
@ EVT_DISCONNECT
Remote peer closed the connection gracefully.
Definition transport.h:94
@ EVT_ERROR
lwIP reported an error (PCB may already be freed).
Definition transport.h:95
@ EVT_DATA
Data received; bytes are already in the ring buffer.
Definition transport.h:93