55#ifndef DETERMINISTICESPASYNCWEBSERVER_WEBSOCKET_H
56#define DETERMINISTICESPASYNCWEBSERVER_WEBSOCKET_H
205 const uint8_t *payload, uint16_t len);
User-facing configuration for DeterministicESPAsyncWebServer.
#define WS_FRAME_SIZE
Maximum WebSocket frame payload in bytes.
#define MAX_WS_CONNS
Maximum simultaneous WebSocket connections.
WebSocket connection state stored in ws_pool[].
bool active
True when this entry is in use.
uint8_t len64_count
Bytes consumed from 64-bit length.
uint8_t mask_key[4]
Client masking key.
uint32_t payload_len
Expected payload byte count.
uint8_t ws_id
Index into ws_pool[] (set at init).
bool fin
FIN bit of the frame being parsed.
bool masked
True if client sent a masking key.
uint8_t slot_id
Owning TCP slot in conn_pool[].
uint32_t payload_idx
Bytes received so far.
WsParseState parse_state
Current frame parser state.
WsOpcode opcode
Opcode of the frame being parsed.
uint8_t buf[WS_FRAME_SIZE+1]
Unmasked payload, null-terminated.
Layer 4 (Transport) — TCP connection pool, ring buffers, and lwIP integration.
WsParseState
States of the WebSocket frame parser.
@ WS_LEN16_LO
Reading extended 16-bit length, low byte.
@ WS_HEADER1
Awaiting first header byte (FIN, RSV, opcode).
@ WS_MASK0
Reading masking key byte 0.
@ WS_FRAME_READY
Complete frame ready for dispatch.
@ WS_HEADER2
Awaiting second header byte (MASK, 7-bit length).
@ WS_MASK2
Reading masking key byte 2.
@ WS_LEN16_HI
Reading extended 16-bit length, high byte.
@ WS_ERROR
Protocol error; close frame has been queued.
@ WS_CLOSED
Connection closed; slot may be recycled.
@ WS_PAYLOAD
Accumulating payload bytes.
@ WS_MASK1
Reading masking key byte 1.
@ WS_MASK3
Reading masking key byte 3.
@ WS_LEN64
Consuming 8-byte 64-bit length (always rejected).
void ws_free(uint8_t slot_id)
Free the WsConn associated with a TCP slot.
bool ws_send_frame(WsConn *ws, WsOpcode opcode, const uint8_t *payload, uint16_t len)
Send a WebSocket frame to the client.
void ws_close(WsConn *ws, WsCloseCode code)
Send a Close frame and mark the slot WS_CLOSED.
WsOpcode
WebSocket frame opcodes.
@ WS_OP_TEXT
UTF-8 text payload.
@ WS_OP_CLOSE
Connection close.
@ WS_OP_CONTINUATION
Continuation frame (fragmentation – rejected).
@ WS_OP_PONG
Pong (echoed ping; ignored by library).
@ WS_OP_PING
Ping (auto-ponged by the library).
@ WS_OP_BINARY
Binary payload.
void ws_parse(WsConn *ws)
Drain the ring buffer for slot_id and feed bytes to the WS parser.
WsCloseCode
WebSocket close status codes (RFC 6455 §7.4.1).
@ WS_CLOSE_NORMAL
Normal closure.
@ WS_CLOSE_PROTOCOL
Protocol error.
@ WS_CLOSE_TOO_BIG
Payload too large for WS_FRAME_SIZE.
@ WS_CLOSE_GOING_AWAY
Endpoint going away.
@ WS_CLOSE_UNSUPPORTED
Unsupported data (e.g. fragmented message).
WsConn * ws_find(uint8_t slot_id)
Find the WsConn for a given TCP slot, or nullptr if none.
void ws_reset_frame(WsConn *ws)
Reset the frame parser back to WS_HEADER1, ready for the next frame.
WsConn * ws_alloc(uint8_t slot_id)
Allocate a WsConn slot and bind it to a TCP slot.
WsConn ws_pool[MAX_WS_CONNS]
Pool of WebSocket connection state, one per MAX_WS_CONNS.
void ws_init()
Initialise all WebSocket pool slots to inactive.