cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
websocket.h
Go to the documentation of this file.
1
4#ifndef __CWIST_WEBSOCKET_H__
5#define __CWIST_WEBSOCKET_H__
6
7#include <cwist/http.h>
8#include <stdint.h>
9#include <stdbool.h>
10
11typedef struct cwist_websocket {
12 int fd;
13 bool is_closed;
15
24
25typedef struct cwist_ws_frame {
26 bool fin;
28 uint8_t *payload;
29 size_t payload_len;
31
37
43
47int cwist_websocket_send(cwist_websocket *ws, cwist_ws_opcode_t opcode, const uint8_t *data,
48 size_t len);
49
54
59
64
65#endif
http.h interface.
struct cwist_websocket cwist_websocket
struct cwist_ws_frame cwist_ws_frame
cwist_websocket * cwist_websocket_upgrade(cwist_http_request *req, int client_fd)
Upgrade a standard HTTP request to a WebSocket connection.
Definition websocket.c:119
cwist_ws_frame * cwist_websocket_receive(cwist_websocket *ws)
Receive a frame, blocking until data arrives or the socket closes.
Definition websocket.c:217
cwist_ws_opcode_t
Definition websocket.h:13
@ CWIST_WS_FRAME_PING
Definition websocket.h:18
@ CWIST_WS_FRAME_BINARY
Definition websocket.h:16
@ CWIST_WS_FRAME_CONTINUATION
Definition websocket.h:14
@ CWIST_WS_FRAME_CLOSE
Definition websocket.h:17
@ CWIST_WS_FRAME_PONG
Definition websocket.h:19
@ CWIST_WS_FRAME_TEXT
Definition websocket.h:15
void cwist_websocket_close(cwist_websocket *ws)
Close the WebSocket connection.
Definition websocket.c:512
int cwist_websocket_send(cwist_websocket *ws, cwist_ws_opcode_t opcode, const uint8_t *data, size_t len)
Send a frame with the specified opcode and payload.
Definition websocket.c:398
void cwist_websocket_frame_destroy(cwist_ws_frame *frame)
Destroy a frame.
Definition websocket.c:436
void cwist_websocket_destroy(cwist_websocket *ws)
Destroy the WebSocket context.
Definition websocket.c:523
cwist_ws_opcode_t opcode
Definition websocket.h:37
size_t payload_len
Definition websocket.h:39
uint8_t * payload
Definition websocket.h:38