|
DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
|
Layer 6 (Presentation) – Server-Sent Events connection pool. More...
Go to the source code of this file.
Classes | |
| struct | SseConn |
| SSE connection state stored in sse_pool[]. More... | |
Functions | |
| void | sse_init () |
| Initialize all SSE pool slots to inactive. | |
| SseConn * | sse_alloc (uint8_t slot_id, const char *path) |
| Allocate an SseConn and bind it to a TCP slot. | |
| SseConn * | sse_find (uint8_t slot_id) |
| Find the SseConn for a given TCP slot, or nullptr. | |
| void | sse_free (uint8_t slot_id) |
| Free the SseConn associated with a TCP slot. | |
| int | sse_format (char *buf, size_t n, const char *data, const char *event, const char *id) |
| Format one SSE event record into a caller buffer (no transport). | |
| bool | sse_write (SseConn *sse, const char *data, const char *event, const char *id) |
| Write one SSE event record to a client. | |
Variables | |
| SseConn | sse_pool [MAX_SSE_CONNS] |
| Pool of SSE connection state, one per MAX_SSE_CONNS. | |
Layer 6 (Presentation) – Server-Sent Events connection pool.
SSE (WHATWG HTML Living Standard, Server-sent events; the W3C EventSource API) is a long-lived HTTP GET response with Content-Type: text/event-stream. After the initial headers the connection stays open indefinitely; the server pushes newline-delimited event records at any time.
Event record format (WHATWG HTML, Server-sent events)
Each SseConn occupies one TCP slot from conn_pool[] for the lifetime of the subscription. The total number of simultaneous SSE connections is capped at MAX_SSE_CONNS.
Definition in file sse.h.
| void sse_init | ( | ) |
Initialize all SSE pool slots to inactive.
Called once from DetWebServer::begin().
Definition at line 16 of file sse.cpp.
References MAX_SSE_CONNS, SseConn::sse_id, and sse_pool.
Referenced by DetWebServer::begin(), and DetWebServer::stop().
| SseConn * sse_alloc | ( | uint8_t | slot_id, |
| const char * | path | ||
| ) |
Allocate an SseConn and bind it to a TCP slot.
| slot_id | TCP slot that just received the SSE subscription request. |
| path | URL path the client subscribed to (stored for broadcast). |
Definition at line 25 of file sse.cpp.
References SseConn::active, MAX_PATH_LEN, MAX_SSE_CONNS, SseConn::path, SseConn::slot_id, SseConn::sse_id, and sse_pool.
| SseConn * sse_find | ( | uint8_t | slot_id | ) |
Find the SseConn for a given TCP slot, or nullptr.
| slot_id | TCP connection slot index. |
Definition at line 43 of file sse.cpp.
References MAX_SSE_CONNS, and sse_pool.
Referenced by DetWebServer::http_poll_slot().
| void sse_free | ( | uint8_t | slot_id | ) |
Free the SseConn associated with a TCP slot.
| slot_id | TCP connection slot index. |
Definition at line 53 of file sse.cpp.
References MAX_SSE_CONNS, SseConn::sse_id, and sse_pool.
| int sse_format | ( | char * | buf, |
| size_t | n, | ||
| const char * | data, | ||
| const char * | event, | ||
| const char * | id | ||
| ) |
Format one SSE event record into a caller buffer (no transport).
Emits event: <event>\n (if event), id: <id>\n (if id), then data: <data>\n\n per the WHATWG event-stream format. data must not be nullptr. Pure: no connection state, so it is unit-testable and benchable on its own; sse_write() wraps it with the det_conn_send() I/O.
| buf | Destination buffer. |
| n | Size of buf. |
| data | Event data (required). |
| event | Event name (optional). |
| id | Event ID (optional). |
Definition at line 66 of file sse.cpp.
Referenced by sse_write().
| bool sse_write | ( | SseConn * | sse, |
| const char * | data, | ||
| const char * | event, | ||
| const char * | id | ||
| ) |
Write one SSE event record to a client.
Formats and sends event: ...\nid: ...\ndata: ...\n\n. Any optional field may be nullptr to omit it. data must not be nullptr.
The caller must flush the connection afterwards (det_conn_flush()) if immediate delivery is needed.
| sse | SSE connection. |
| data | Event data (required). |
| event | Event name (optional). |
| id | Event ID (optional). |
Definition at line 88 of file sse.cpp.
References det_conn_send(), SseConn::slot_id, SSE_BUF_SIZE, and sse_format().
|
extern |
Pool of SSE connection state, one per MAX_SSE_CONNS.
Definition at line 14 of file sse.cpp.
Referenced by sse_alloc(), sse_find(), sse_free(), and sse_init().