DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
proto_handler.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 proto_handler.h
6 * @brief Layer 5 (Session) - per-protocol connection handler dispatch table.
7 *
8 * Every application protocol (HTTP, Telnet, SSH, and optional services such as
9 * MQTT or Modbus) registers one ProtoHandler. The session layer (server_tick)
10 * routes each connection event - and the main loop (DetWebServer::handle())
11 * polls each active slot - through this table by ConnProto, so a new protocol
12 * plugs in by registering a handler instead of editing the dispatchers.
13 *
14 * All callbacks are nullable, run on the main-loop task, and take the affected
15 * connection slot index. The built-in HTTP/Telnet/SSH handlers are registered
16 * lazily on first lookup, so dispatch works even before begin() (the native
17 * test harness drives server_tick() directly).
18 */
19
20#ifndef DETERMINISTICESPASYNCWEBSERVER_PROTO_HANDLER_H
21#define DETERMINISTICESPASYNCWEBSERVER_PROTO_HANDLER_H
22
23#include "ServerConfig.h"
24#include <stdint.h>
25
26/**
27 * @brief Per-protocol connection event/poll callbacks (Layer 5 dispatch vtable).
28 */
30{
31 void (*on_accept)(uint8_t slot); ///< EvtType::EVT_CONNECT: a new connection was accepted.
32 void (*on_data)(uint8_t slot); ///< EvtType::EVT_DATA: bytes are available in the slot's rx ring.
33 void (*on_close)(uint8_t slot); ///< EvtType::EVT_DISCONNECT / EvtType::EVT_ERROR: tear down slot state.
34 void (*on_poll)(uint8_t slot); ///< Called for an active slot each handle() loop (nullable).
35};
36
37/** @brief Register @p h for protocol @p proto (replaces any previous handler). */
38void proto_register(ConnProto proto, const ProtoHandler *h);
39
40/**
41 * @brief Register every built-in protocol's handler (the policy list).
42 *
43 * Defined in proto_builtins.cpp - the one place that knows which protocols exist.
44 * Each built-in's handler lives in its own module (http in presentation, ssh in
45 * ssh_conn, ...) behind a `*_proto_handler()` accessor; this installs each. The
46 * session dispatcher (session.cpp) calls this once (lazily, on first lookup) so it
47 * never names a protocol itself. Optional runtime-gated handlers (e.g. the SSH
48 * remote-forward listener) self-register at their own opt-in entry point instead.
49 */
51
52/**
53 * @brief Look up the handler for @p proto.
54 * @return the registered handler, or nullptr if @p proto is ConnProto::PROTO_NONE or has
55 * no registered handler (no implicit fallback; the event is dropped).
56 */
57const ProtoHandler *proto_get(ConnProto proto);
58
59#endif // DETERMINISTICESPASYNCWEBSERVER_PROTO_HANDLER_H
User-facing configuration for DeterministicESPAsyncWebServer.
ConnProto
Application protocol spoken on a listener port or connection slot.
void proto_register(ConnProto proto, const ProtoHandler *h)
Register h for protocol proto (replaces any previous handler).
Definition session.cpp:38
const ProtoHandler * proto_get(ConnProto proto)
Look up the handler for proto.
Definition session.cpp:44
void proto_register_builtins(void)
Register every built-in protocol's handler (the policy list).
Per-protocol connection event/poll callbacks (Layer 5 dispatch vtable).
void(* on_close)(uint8_t slot)
EvtType::EVT_DISCONNECT / EvtType::EVT_ERROR: tear down slot state.
void(* on_data)(uint8_t slot)
EvtType::EVT_DATA: bytes are available in the slot's rx ring.
void(* on_poll)(uint8_t slot)
Called for an active slot each handle() loop (nullable).
void(* on_accept)(uint8_t slot)
EvtType::EVT_CONNECT: a new connection was accepted.