File syn_websocket.h¶
FileList > net > syn_websocket.h
Go to the source code of this file
WebSocket protocol support on httpd.
#include "../common/syn_defs.h"#include "../port/syn_port_socket.h"#include "../pt/syn_pt.h"#include "../sched/syn_task.h"#include "syn_httpd.h"
Classes¶
| Type | Name |
|---|---|
| struct | SYN_WebsocketSession WebSocket session context. |
Public Types¶
| Type | Name |
|---|---|
| enum | SYN_WebsocketState WebSocket connection states. |
Public Functions¶
| Type | Name |
|---|---|
| SYN_Status | syn_websocket_send (SYN_WebsocketSession * ws, uint8_t opcode, const void * data, size_t len) Send a frame over WebSocket. |
| SYN_PT_Status | syn_websocket_task (SYN_PT * pt, SYN_Task * task) Background task for polling active WebSockets. |
| SYN_Status | syn_websocket_upgrade (const SYN_HttpdRequest * req, SYN_HttpdResponse * resp, SYN_WebsocketSession * ws, void(*)(const uint8_t *payload, size_t len, uint8_t opcode, void *ctx) on_message, void * ctx) Handle upgrading a connection in an httpd route handler to WebSocket. |
Public Types Documentation¶
enum SYN_WebsocketState¶
WebSocket connection states.
Public Functions Documentation¶
function syn_websocket_send¶
Send a frame over WebSocket.
SYN_Status syn_websocket_send (
SYN_WebsocketSession * ws,
uint8_t opcode,
const void * data,
size_t len
)
Formats a WebSocket packet header and writes the payload to the socket.
Parameters:
wsWebSocket session context.opcodeFrame type opcode (e.g., text, binary, ping).dataPayload data to send.lenLength of payload in bytes.
Returns:
SYN_OK on success, or socket error code.
function syn_websocket_task¶
Background task for polling active WebSockets.
Parameters:
ptCooperative protothread state tracker.taskScheduler task control block.
Returns:
PT_WAITING or PT_EXITED status.
function syn_websocket_upgrade¶
Handle upgrading a connection in an httpd route handler to WebSocket.
SYN_Status syn_websocket_upgrade (
const SYN_HttpdRequest * req,
SYN_HttpdResponse * resp,
SYN_WebsocketSession * ws,
void(*)(const uint8_t *payload, size_t len, uint8_t opcode, void *ctx) on_message,
void * ctx
)
Performs handshake, sends 101 status, sets upgraded = true on the response.
Parameters:
reqIncoming HTTP upgrade request.respHTTP response interface to write upgrade headers to.wsWebSocket session context to initialize.on_messageHandled frame callback function.ctxUser context pointer passed through to callback.
Returns:
SYN_OK on successful handshake, SYN_ERROR on negotiation failure.
The documentation for this class was generated from the following file src/syntropic/net/syn_websocket.h