66int sse_format(
char *buf,
size_t n,
const char *data,
const char *event,
const char *
id)
77 pos += snprintf(buf + pos, (
size_t)(rem - pos),
"event: %s\n", event);
79 pos += snprintf(buf + pos, (
size_t)(rem - pos),
"id: %s\n",
id);
81 pos += snprintf(buf + pos, (
size_t)(rem - pos),
"data: %s\n\n", data);
83 if (pos <= 0 || pos >= rem)
90 if (!det_conn_active(sse->
slot_id))
94 int pos =
sse_format(buf,
sizeof(buf), data, event,
id);
#define MAX_PATH_LEN
Maximum URL path length (including leading /).
#define MAX_SSE_CONNS
Maximum simultaneous SSE connections.
#define SSE_BUF_SIZE
Output buffer size in bytes for a single SSE event.
void sse_init()
Initialize all SSE pool slots to inactive.
bool sse_write(SseConn *sse, const char *data, const char *event, const char *id)
Write one SSE event record to a client.
SseConn sse_pool[MAX_SSE_CONNS]
Pool of SSE connection state, one per MAX_SSE_CONNS.
SseConn * sse_find(uint8_t slot_id)
Find the SseConn for a given TCP slot, or nullptr.
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).
SseConn * sse_alloc(uint8_t slot_id, const char *path)
Allocate an SseConn and bind it to a TCP slot.
void sse_free(uint8_t slot_id)
Free the SseConn associated with a TCP slot.
Layer 6 (Presentation) – Server-Sent Events connection pool.
SSE connection state stored in sse_pool[].
uint8_t sse_id
Index into sse_pool[] (set at init).
bool active
True when this entry is in use.
uint8_t slot_id
Owning TCP slot in conn_pool[].
bool det_conn_send(uint8_t slot, const void *data, u16_t len)
Send len bytes on connection slot (copies data; TLS-aware).
Layer 4 (Transport) - TCP connection pool, ring buffers, and lwIP integration.