132#define ws_is_alive(ws) (ws_get_status(ws) != WS_DISCONNECTED)
142#define ws_is_functional(ws) (ws_get_status(ws) == WS_CONNECTED)
Main logging context structure.
Definition: logmod.h:240
Opaque handler for WebSockets.
WebSockets callbacks.
Definition: websockets.h:67
void(* on_binary)(void *data, struct websockets *ws, const void *mem, size_t len)
reports binary data.
Definition: websockets.h:86
void * data
user arbitrary data to be passed around callbacks
Definition: websockets.h:120
void(* on_text)(void *data, struct websockets *ws, const char *text, size_t len)
Reports UTF-8 text messages.
Definition: websockets.h:80
void(* on_connect)(void *data, struct websockets *ws)
Called upon connection.
Definition: websockets.h:71
void(* on_close)(void *data, struct websockets *ws, enum ws_close_reason wscode, const char *reason, size_t len)
reports server closed the connection with the given reason.
Definition: websockets.h:113
void(* on_ping)(void *data, struct websockets *ws, const char *reason, size_t len)
reports PING.
Definition: websockets.h:96
void(* on_pong)(void *data, struct websockets *ws, const char *reason, size_t len)
reports PONG.
Definition: websockets.h:102
void ws_set_url(struct websockets *ws, const char base_url[])
Set the URL for the WebSockets handle to connect.
_Bool ws_multi_socket_run(struct websockets *ws, uint64_t *tstamp)
Reads/Write available data from WebSockets.
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:32
@ WS_DISCONNECTING
Definition: websockets.h:38
@ WS_CONNECTING
Definition: websockets.h:40
@ WS_DISCONNECTED
Definition: websockets.h:34
@ WS_CONNECTED
Definition: websockets.h:36
uint64_t ws_timestamp_update(struct websockets *ws)
Update the WebSockets event-loop concept of "now".
_Bool ws_pong(struct websockets *ws, const char reason[], size_t len)
Send a PONG (opcode 0xA) frame with reason as payload.
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_ping(struct websockets *ws, const char reason[], size_t len)
Send a PING (opcode 0x9) frame with reason as payload.
uint64_t ws_timestamp(struct websockets *ws)
The WebSockets event-loop concept of "now".
_Bool ws_send_binary(struct websockets *ws, const char msg[], size_t msglen)
Send a binary message of given size.
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.
struct websockets * ws_init(struct ws_callbacks *cbs, CURLM *mhandle, struct logmod *logmod, FILE *fp)
Create a new (CURL-based) WebSockets handle.
_Bool ws_easy_run(struct websockets *ws, uint64_t wait_ms, uint64_t *tstamp)
Reads/Write available data from WebSockets.
_Bool ws_send_text(struct websockets *ws, const char text[], size_t len)
Send a text message of given size.
ws_close_reason
WebSockets CLOSE opcodes.
Definition: websockets.h:48
@ WS_CLOSE_REASON_INCONSISTENT_DATA
Definition: websockets.h:55
@ WS_CLOSE_REASON_ABRUPTLY
Definition: websockets.h:54
@ WS_CLOSE_REASON_TOO_BIG
Definition: websockets.h:57
@ WS_CLOSE_REASON_MISSING_EXTENSION
Definition: websockets.h:58
@ WS_CLOSE_REASON_PRIVATE_START
Definition: websockets.h:62
@ WS_CLOSE_REASON_UNEXPECTED_DATA
Definition: websockets.h:52
@ WS_CLOSE_REASON_NO_REASON
Definition: websockets.h:53
@ WS_CLOSE_REASON_GOING_AWAY
Definition: websockets.h:50
@ WS_CLOSE_REASON_PRIVATE_END
Definition: websockets.h:63
@ WS_CLOSE_REASON_POLICY_VIOLATION
Definition: websockets.h:56
@ WS_CLOSE_REASON_IANA_REGISTRY_START
Definition: websockets.h:60
@ WS_CLOSE_REASON_NORMAL
Definition: websockets.h:49
@ WS_CLOSE_REASON_IANA_REGISTRY_END
Definition: websockets.h:61
@ WS_CLOSE_REASON_PROTOCOL_ERROR
Definition: websockets.h:51
@ WS_CLOSE_REASON_SERVER_ERROR
Definition: websockets.h:59
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.