DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
session.cpp File Reference

Layer 5 (Session) - event queue processor implementation. More...

#include "session.h"
#include "../transport/listener.h"
#include "proto_handler.h"
#include "scratch.h"

Go to the source code of this file.

Classes

struct  SessionCtx
 

Functions

void proto_register (ConnProto proto, const ProtoHandler *h)
 Register h for protocol proto (replaces any previous handler).
 
const ProtoHandlerproto_get (ConnProto proto)
 Look up the handler for proto.
 
void server_tick (int worker_id)
 Drive the session layer for one Arduino loop iteration.
 

Detailed Description

Layer 5 (Session) - event queue processor implementation.

server_tick() is the only function here. Its bounded loop drains every active listener's FreeRTOS queue in one call so that the application layer always sees the most up-to-date state before checking http_pool[].

Events are routed to the correct protocol handler via TcpConn::proto. A slot must carry an explicit protocol (assigned from its listener on accept); ConnProto::PROTO_NONE and any unregistered protocol resolve to no handler and the event is dropped.

Definition in file session.cpp.

Function Documentation

◆ proto_register()

void proto_register ( ConnProto  proto,
const ProtoHandler h 
)

Register h for protocol proto (replaces any previous handler).

Definition at line 38 of file session.cpp.

References DETWS_PROTO_MAX, and SessionCtx::proto_handlers.

◆ proto_get()

const ProtoHandler * proto_get ( ConnProto  proto)

Look up the handler for proto.

Returns
the registered handler, or nullptr if proto is ConnProto::PROTO_NONE or has no registered handler (no implicit fallback; the event is dropped).

Definition at line 44 of file session.cpp.

References DETWS_PROTO_MAX, SessionCtx::proto_handlers, PROTO_HTTP, and proto_register_builtins().

Referenced by DetWebServer::service_once().

◆ server_tick()

void server_tick ( int  worker_id = 0)

Drive the session layer for one Arduino loop iteration.

Call this function from your loop() (or indirectly via DetWebServer::handle()). It performs three actions in order:

  1. Timeout sweep - calls DeterministicAsyncTCP::check_timeouts() to force-close connections that have been idle for > CONN_TIMEOUT_MS.
  2. Event drain - dequeues all pending TcpEvt records from the FreeRTOS queue. Each event is dispatched:
  3. Returns - upper layers may then inspect http_pool[] for ParseState::PARSE_COMPLETE slots and send responses.
Note
The event-drain loop is bounded by the queue depth (16 entries). Even in the absolute worst case this function executes in O(1).

Definition at line 91 of file session.cpp.

References Listener::active, DeterministicAsyncTCP::check_timeouts(), listener_pool, MAX_LISTENERS, and Listener::queue.

Referenced by DetWebServer::service_once().