DeterministicESPAsyncWebServer 1.2.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
presentation.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 presentation.cpp
6 * @brief Layer 6 (Presentation) — wires the transport ring buffer to the HTTP parser.
7 *
8 * This file is now a thin adapter. The HTTP parsing logic lives in
9 * http_parser.cpp. This layer only knows about:
10 * - The transport ring buffer (conn_pool[slot].rx_buffer / rx_head / rx_tail)
11 * - Slot-indexed helpers that the session and application layers expect
12 *
13 * The slot-indexed `http_reset()` pre-stamps slot_id then delegates to
14 * `http_parser_reset()`. The slot-indexed `http_parse()` drains all
15 * available bytes from the ring buffer through `http_parser_feed()` and
16 * stops as soon as the parser reaches any terminal state.
17 */
18
19#include "presentation.h"
20
21void http_reset(uint8_t slot_id)
22{
23 if (slot_id >= MAX_CONNS)
24 return;
25 http_pool[slot_id].slot_id = slot_id; // ensure slot_id is correct before reset reads it
27}
28
29void http_parse(uint8_t slot_id)
30{
31 if (slot_id >= MAX_CONNS)
32 return;
33
34 TcpConn *tcp = &conn_pool[slot_id];
35 HttpReq *req = &http_pool[slot_id];
36
37 while (tcp->rx_tail != tcp->rx_head)
38 {
39 switch (req->parse_state)
40 {
41 case PARSE_COMPLETE:
42 case PARSE_ERROR:
45 return; // terminal state — drain nothing further
46 default:
47 break;
48 }
49
50 uint8_t byte = tcp->rx_buffer[tcp->rx_tail];
51 tcp->rx_tail = (tcp->rx_tail + 1) % RX_BUF_SIZE;
52 http_parser_feed(req, byte);
53 }
54}
#define RX_BUF_SIZE
Ring-buffer capacity in bytes per connection slot.
#define MAX_CONNS
Maximum simultaneous TCP connections.
void http_parser_reset(HttpReq *req)
Reset a parser context to the initial (PARSE_METHOD) state.
void http_parser_feed(HttpReq *p, uint8_t byte)
Feed one byte to the parser state machine.
HttpReq http_pool[MAX_CONNS]
Pool of parser contexts, one per transport slot.
@ PARSE_COMPLETE
Full request parsed; ready for dispatch.
Definition http_parser.h:63
@ PARSE_URI_TOO_LONG
Path exceeds MAX_PATH_LEN → 414.
Definition http_parser.h:66
@ PARSE_ENTITY_TOO_LARGE
Content-Length > BODY_BUF_SIZE → 413.
Definition http_parser.h:65
@ PARSE_ERROR
Unrecoverable parse failure → 400.
Definition http_parser.h:64
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.
Layer 6 (Presentation) — wires the transport ring buffer to the HTTP parser.
Fully-parsed HTTP/1.1 request.
ParseState parse_state
Current parser state.
uint8_t slot_id
Transport slot index (set by presentation layer).
A single TCP connection context.
Definition transport.h:69
volatile size_t rx_tail
Consumer read index (main-loop context).
Definition transport.h:77
uint8_t rx_buffer[RX_BUF_SIZE]
Ring buffer storage.
Definition transport.h:75
volatile size_t rx_head
Producer write index (lwIP context).
Definition transport.h:76
TcpConn conn_pool[MAX_CONNS]
Static pool of connection contexts. Defined in transport.cpp.
Definition transport.cpp:25