67 const char *event,
const char *
id)
78 int rem = (int)
sizeof(buf);
80 if (event && pos < rem)
81 pos += snprintf(buf + pos, (
size_t)(rem - pos),
"event: %s\n", event);
83 pos += snprintf(buf + pos, (
size_t)(rem - pos),
"id: %s\n",
id);
85 pos += snprintf(buf + pos, (
size_t)(rem - pos),
"data: %s\n\n", data);
87 if (pos <= 0 || pos >= rem)
90 tcp_write(conn->
pcb, buf, (u16_t)pos, TCP_WRITE_FLAG_COPY);
#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()
Initialise 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.
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[].
A single TCP connection context.
volatile ConnState state
Lifecycle state; volatile for inter-task visibility.
struct tcp_pcb * pcb
lwIP PCB; null when slot is free.
TcpConn conn_pool[MAX_CONNS]
Static pool of connection contexts. Defined in transport.cpp.
@ CONN_ACTIVE
Live connection; PCB is valid.