|
KEEL 1.0.0
Minimal C11 HTTP client/server library built on epoll/kqueue/io_uring/poll
|
WebSocket client API. More...
#include <keel/allocator.h>#include <keel/event_ctx.h>#include <keel/tls.h>#include <keel/websocket.h>

Go to the source code of this file.
Data Structures | |
| struct | KlWsClientConfig |
| struct | KlWsClientCallbacks |
Macros | |
| #define | KL_WS_CLIENT_DEFAULT_TIMEOUT_MS 30000 |
| Default connect/handshake timeout in milliseconds. | |
| #define | KL_WS_CLIENT_RECV_BUF_SIZE 8192 |
| Receive buffer size in bytes. | |
| #define | KL_WS_CLIENT_DEFAULT_MAX_FRAME (16 * 1024 * 1024) |
| Default maximum frame size (16 MB). | |
| #define | KL_WS_CLIENT_KEY_B64_SIZE 25 |
| Base64-encoded key size (16 bytes -> 24 Base64 chars + NUL). | |
| #define | KL_WS_CLIENT_UPGRADE_BUF_INIT 512 |
| Initial upgrade response buffer size. | |
Typedefs | |
| typedef struct KlWsClientConn | KlWsClientConn |
Functions | |
| KlWsClientConn * | kl_ws_client_connect (KlEventCtx *ev, KlAllocator *alloc, const KlWsClientConfig *cfg, const char *url, const KlWsClientCallbacks *cbs, void *user_data) |
| Connect to a WebSocket server. | |
| int | kl_ws_client_send_text (KlWsClientConn *ws, const char *data, size_t len) |
| Send a text frame. | |
| int | kl_ws_client_send_binary (KlWsClientConn *ws, const char *data, size_t len) |
| Send a binary frame. | |
| int | kl_ws_client_send_ping (KlWsClientConn *ws, const char *data, size_t len) |
| Send a ping frame. | |
| void | kl_ws_client_close (KlWsClientConn *ws, uint16_t code, const char *reason, size_t reason_len) |
| Initiate close handshake. | |
| void | kl_ws_client_free (KlWsClientConn *ws) |
| Free all WebSocket client resources. | |
WebSocket client API.
Async WebSocket client driven by KlEventCtx watchers. Reuses the shared frame parser from websocket.h. Client frames are masked per RFC 6455 Section 5.3.
| #define KL_WS_CLIENT_DEFAULT_TIMEOUT_MS 30000 |
Default connect/handshake timeout in milliseconds.
| #define KL_WS_CLIENT_RECV_BUF_SIZE 8192 |
Receive buffer size in bytes.
| #define KL_WS_CLIENT_DEFAULT_MAX_FRAME (16 * 1024 * 1024) |
Default maximum frame size (16 MB).
| #define KL_WS_CLIENT_KEY_B64_SIZE 25 |
Base64-encoded key size (16 bytes -> 24 Base64 chars + NUL).
| #define KL_WS_CLIENT_UPGRADE_BUF_INIT 512 |
Initial upgrade response buffer size.
| typedef struct KlWsClientConn KlWsClientConn |
| KlWsClientConn * kl_ws_client_connect | ( | KlEventCtx * | ev, |
| KlAllocator * | alloc, | ||
| const KlWsClientConfig * | cfg, | ||
| const char * | url, | ||
| const KlWsClientCallbacks * | cbs, | ||
| void * | user_data | ||
| ) |
Connect to a WebSocket server.
Initiates a non-blocking TCP connect, optional TLS handshake, and WebSocket HTTP upgrade. Callbacks fire on the event loop thread.
| ev | Event context (standalone or &server->ev). |
| alloc | Allocator (must outlive the connection). |
| cfg | Configuration (NULL for defaults, timeout/TLS/limits). |
| url | WebSocket URL (ws:// or wss://). |
| cbs | Callbacks (on_open, on_message, on_close, on_error). |
| user_data | Opaque pointer passed to all callbacks. |
| int kl_ws_client_send_text | ( | KlWsClientConn * | ws, |
| const char * | data, | ||
| size_t | len | ||
| ) |
Send a text frame.
| int kl_ws_client_send_binary | ( | KlWsClientConn * | ws, |
| const char * | data, | ||
| size_t | len | ||
| ) |
Send a binary frame.
| int kl_ws_client_send_ping | ( | KlWsClientConn * | ws, |
| const char * | data, | ||
| size_t | len | ||
| ) |
Send a ping frame.
| void kl_ws_client_close | ( | KlWsClientConn * | ws, |
| uint16_t | code, | ||
| const char * | reason, | ||
| size_t | reason_len | ||
| ) |
Initiate close handshake.
| void kl_ws_client_free | ( | KlWsClientConn * | ws | ) |
Free all WebSocket client resources.