ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
proto_handler.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - 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 Core server - per-protocol connection handler dispatch table.
7 *
8 * Every application protocol (HTTP, Telnet, SSH, and optional services such as
9 * MQTT or Modbus) implements one ProtoHandler and registers it with the session
10 * layer, which owns the registry and the storage behind it: the server tick
11 * (server_tick) routes each connection event - and the main loop (handle())
12 * polls each active slot - through ::Protocols by ProtoConn, so a new protocol
13 * plugs in by registering a handler instead of editing the dispatchers.
14 *
15 * This file declares the callback record and nothing else. Registering a handler
16 * means opening, closing and tracking the lifetime of a connection, which is the
17 * session layer's job and not the server's - so ::Protocols is published by
18 * network_drivers/session/session.h, beside the SessionCtx field it writes.
19 *
20 * All callbacks are nullable, run on the main-loop task, and take the affected
21 * connection slot index. The built-in HTTP/Telnet/SSH handlers are registered
22 * lazily on first lookup, so dispatch works even before begin() (the native
23 * test harness drives server_tick() directly).
24 */
25
26#ifndef PROTOCORE_PROTO_HANDLER_H
27#define PROTOCORE_PROTO_HANDLER_H
28
29#include "protocore_config.h"
30
32
33/**
34 * @brief Per-protocol connection event/poll callbacks (the server's dispatch vtable).
35 */
36typedef struct ProtoHandler
37{
38 void (*on_accept)(uint8_t slot); ///< EvtType::EVT_CONNECT: a new connection was accepted.
39 void (*on_data)(uint8_t slot); ///< EvtType::EVT_DATA: bytes are available in the slot's rx ring.
40 void (*on_close)(uint8_t slot); ///< EvtType::EVT_DISCONNECT: the peer closed normally.
41 /// EvtType::EVT_ERROR: the connection was aborted, not closed. RFC 9293 sec 3.6 MUST-12 - "the
42 /// local application MUST be informed whether it closed normally or was aborted" - so the two
43 /// arrive separately. Null falls back to on_close, which cannot tell them apart.
44 void (*on_abort)(uint8_t slot);
45 void (*on_poll)(uint8_t slot); ///< Called for an active slot each handle() loop (nullable).
47
48/**
49 * @brief Install every handler the build compiled in. Defined in server/protocore_builtins.c, the
50 * policy list: this layer owns the mechanism and names no protocol.
51 */
53
55
56#endif // PROTOCORE_PROTO_HANDLER_H
void protocore_register_builtins(void)
Install every handler the build compiled in. Defined in server/protocore_builtins....
Per-protocol connection event/poll callbacks (the server's dispatch vtable).
void(* on_close)(uint8_t slot)
void(* on_data)(uint8_t slot)
EvtType::EVT_DATA: bytes are available in the slot's rx ring.
void(* on_abort)(uint8_t slot)
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.
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
Definition types.h:96
#define PROTOCORE_END_DECLS
Definition types.h:97