71static inline bool sse_append(
char *buf,
size_t n,
size_t *pos,
const char *src,
size_t len)
73 if (*pos + len > n - 1)
77 memcpy(buf + *pos, src, len);
82int pc_sse_format(
char *buf,
size_t n,
const char *data,
const char *event,
const char *
id)
96 if (event && (!sse_append(buf, n, &pos,
"event: ", 7) || !sse_append(buf, n, &pos, event, strnlen(event, n)) ||
97 !sse_append(buf, n, &pos,
"\n", 1)))
101 if (
id && (!sse_append(buf, n, &pos,
"id: ", 4) || !sse_append(buf, n, &pos,
id, strnlen(
id, n)) ||
102 !sse_append(buf, n, &pos,
"\n", 1)))
106 if (!sse_append(buf, n, &pos,
"data: ", 6) || !sse_append(buf, n, &pos, data, strnlen(data, n)) ||
107 !sse_append(buf, n, &pos,
"\n\n", 2))
118 if (!pc_conn_active(sse->
slot_id))
#define MAX_PATH_LEN
Maximum URL path length (including leading /).
#define SSE_BUF_SIZE
Output buffer size in bytes for a single SSE event.
SseConn * pc_sse_alloc(uint8_t slot_id, const char *path)
Allocate an SseConn and bind it to a TCP slot.
bool pc_sse_write(SseConn *sse, const char *data, const char *event, const char *id)
Write one SSE event record to a client.
void pc_sse_init()
Initialize all SSE pool slots to inactive.
int pc_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 pc_sse_pool[MAX_SSE_CONNS]
Pool of SSE connection state, one per MAX_SSE_CONNS.
void pc_sse_free(uint8_t slot_id)
Free the SseConn associated with a TCP slot.
SseConn * pc_sse_find(uint8_t slot_id)
Find the SseConn for a given TCP slot, or nullptr.
Layer 6 (Presentation) – Server-Sent Events connection pool.
SSE connection state stored in pc_sse_pool[].
uint8_t pc_sse_id
Index into pc_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 pc_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.