84 const char *protocols);
156#define ws_is_alive(ws) (ws_get_status(ws) != WS_DISCONNECTED)
166#define ws_is_functional(ws) (ws_get_status(ws) == WS_CONNECTED)
196 const char base_url[],
197 const char ws_protocols[]);
CCORDcode
Definition: error.h:12
A stackful and modularized wrapper over the popular 'log.c' facilities.
Definition: logconf.h:217
Store logging information from log_http()
Definition: logconf.h:249
Opaque handler for WebSockets.
WebSockets handle initialization attributes.
Definition: websockets.h:142
struct logconf * conf
Definition: websockets.h:144
WebSockets callbacks.
Definition: websockets.h:75
void(* on_close)(void *data, struct websockets *ws, struct ws_info *info, enum ws_close_reason wscode, const char *reason, size_t len)
reports server closed the connection with the given reason.
Definition: websockets.h:130
void * data
user arbitrary data to be passed around callbacks
Definition: websockets.h:138
void(* on_pong)(void *data, struct websockets *ws, struct ws_info *info, const char *reason, size_t len)
reports PONG.
Definition: websockets.h:118
void(* on_text)(void *data, struct websockets *ws, struct ws_info *info, const char *text, size_t len)
Reports UTF-8 text messages.
Definition: websockets.h:93
void(* on_binary)(void *data, struct websockets *ws, struct ws_info *info, const void *mem, size_t len)
reports binary data.
Definition: websockets.h:100
void(* on_connect)(void *data, struct websockets *ws, struct ws_info *info, const char *protocols)
Called upon connection.
Definition: websockets.h:81
void(* on_ping)(void *data, struct websockets *ws, struct ws_info *info, const char *reason, size_t len)
reports PING.
Definition: websockets.h:111
Stores info on the latest transfer performed via websockets.
Definition: websockets.h:28
CCORDcode code
Definition: websockets.h:32
_Bool ws_multi_socket_run(struct websockets *ws, uint64_t *tstamp)
Reads/Write available data from WebSockets.
_Bool ws_send_text(struct websockets *ws, struct ws_info *info, const char text[], size_t len)
Send a text message of given size.
void ws_add_header(struct websockets *ws, const char field[], const char value[])
Add a header field/value pair.
ws_status
The WebSockets client status.
Definition: websockets.h:40
@ WS_DISCONNECTING
Definition: websockets.h:46
@ WS_CONNECTING
Definition: websockets.h:48
@ WS_DISCONNECTED
Definition: websockets.h:42
@ WS_CONNECTED
Definition: websockets.h:44
uint64_t ws_timestamp_update(struct websockets *ws)
Update the WebSockets event-loop concept of "now".
void ws_close(struct websockets *ws, const enum ws_close_reason code, const char reason[], const size_t len)
Thread-safe way to stop websockets connection.
_Bool ws_pong(struct websockets *ws, struct ws_info *info, const char reason[], size_t len)
Send a PONG (opcode 0xA) frame with reason as payload.
uint64_t ws_timestamp(struct websockets *ws)
The WebSockets event-loop concept of "now".
_Bool ws_ping(struct websockets *ws, struct ws_info *info, const char reason[], size_t len)
Send a PING (opcode 0x9) frame with reason as payload.
const char * ws_close_opcode_print(enum ws_close_reason opcode)
Returns a enum ws_close_reason opcode in a string format.
CURL * ws_start(struct websockets *ws)
Signals connecting state before entering the WebSockets event loop.
_Bool ws_easy_run(struct websockets *ws, uint64_t wait_ms, uint64_t *tstamp)
Reads/Write available data from WebSockets.
ws_close_reason
WebSockets CLOSE opcodes.
Definition: websockets.h:56
@ WS_CLOSE_REASON_INCONSISTENT_DATA
Definition: websockets.h:63
@ WS_CLOSE_REASON_ABRUPTLY
Definition: websockets.h:62
@ WS_CLOSE_REASON_TOO_BIG
Definition: websockets.h:65
@ WS_CLOSE_REASON_MISSING_EXTENSION
Definition: websockets.h:66
@ WS_CLOSE_REASON_PRIVATE_START
Definition: websockets.h:70
@ WS_CLOSE_REASON_UNEXPECTED_DATA
Definition: websockets.h:60
@ WS_CLOSE_REASON_NO_REASON
Definition: websockets.h:61
@ WS_CLOSE_REASON_GOING_AWAY
Definition: websockets.h:58
@ WS_CLOSE_REASON_PRIVATE_END
Definition: websockets.h:71
@ WS_CLOSE_REASON_POLICY_VIOLATION
Definition: websockets.h:64
@ WS_CLOSE_REASON_IANA_REGISTRY_START
Definition: websockets.h:68
@ WS_CLOSE_REASON_NORMAL
Definition: websockets.h:57
@ WS_CLOSE_REASON_IANA_REGISTRY_END
Definition: websockets.h:69
@ WS_CLOSE_REASON_PROTOCOL_ERROR
Definition: websockets.h:59
@ WS_CLOSE_REASON_SERVER_ERROR
Definition: websockets.h:67
_Bool ws_send_binary(struct websockets *ws, struct ws_info *info, const char msg[], size_t msglen)
Send a binary message of given size.
void ws_set_url(struct websockets *ws, const char base_url[], const char ws_protocols[])
Set the URL for the WebSockets handle to connect.
enum ws_status ws_get_status(struct websockets *ws)
Returns the WebSockets handle connection status.
void ws_cleanup(struct websockets *ws)
Free a WebSockets handle created with ws_init()
void ws_end(struct websockets *ws)
Cleanup and reset ws connection resources.
struct websockets * ws_init(struct ws_callbacks *cbs, CURLM *mhandle, struct ws_attr *attr)
Create a new (CURL-based) WebSockets handle.