Orca
A bot framework that is easy to reason about, easy to debug, and easy to use.
|
File containing internal functions and datatypes for WebSockets client. More...
#include "logconf.h"
Go to the source code of this file.
Classes | |
struct | ws_callbacks |
Enumerations | |
enum | ws_status { WS_DISCONNECTED = 0, WS_CONNECTED, WS_DISCONNECTING, WS_CONNECTING } |
The WebSockets client status. More... | |
enum | ws_user_cmd { WS_USER_CMD_NONE, WS_USER_CMD_EXIT } |
enum | ws_close_reason { WS_CLOSE_REASON_NORMAL = 1000, WS_CLOSE_REASON_GOING_AWAY = 1001, WS_CLOSE_REASON_PROTOCOL_ERROR = 1002, WS_CLOSE_REASON_UNEXPECTED_DATA = 1003, WS_CLOSE_REASON_NO_REASON = 1005, WS_CLOSE_REASON_ABRUPTLY = 1006, WS_CLOSE_REASON_INCONSISTENT_DATA = 1007, WS_CLOSE_REASON_POLICY_VIOLATION = 1008, WS_CLOSE_REASON_TOO_BIG = 1009, WS_CLOSE_REASON_MISSING_EXTENSION = 1010, WS_CLOSE_REASON_SERVER_ERROR = 1011, WS_CLOSE_REASON_IANA_REGISTRY_START = 3000, WS_CLOSE_REASON_IANA_REGISTRY_END = 3999, WS_CLOSE_REASON_PRIVATE_START = 4000, WS_CLOSE_REASON_PRIVATE_END = 4999 } |
Functions | |
struct websockets * | ws_init (struct ws_callbacks *cbs, struct logconf *config) |
Create a new (CURL-based) WebSockets handle. More... | |
void | ws_cleanup (struct websockets *ws) |
Free a WebSockets handle created with ws_init() More... | |
void | ws_set_url (struct websockets *ws, const char base_url[], const char ws_protocols[]) |
Set the URL for the WebSockets handle to connect. More... | |
bool | ws_send_text (struct websockets *ws, char text[], size_t len) |
Send a text message of given size. More... | |
void | ws_start (struct websockets *ws) |
Signals connecting state before entering the WebSockets event loop. More... | |
void | ws_perform (struct websockets *ws, _Bool *is_running, uint64_t wait_ms) |
Reads/Write available data from WebSockets. More... | |
uint64_t | ws_timestamp (struct websockets *ws) |
The WebSockets handle concept of "now". More... | |
enum ws_status | ws_get_status (struct websockets *ws) |
Returns the WebSockets handle connection status. More... | |
char * | ws_close_opcode_print (enum ws_close_reason opcode) |
Returns a enum ws_close_reason opcode in a string format. More... | |
bool | ws_is_alive (struct websockets *ws) |
Check if a WebSockets connection is alive. More... | |
bool | ws_is_functional (struct websockets *ws) |
Check if WebSockets connection is active. More... | |
void | ws_exit_event_loop (struct websockets *ws) |
bool | ws_same_thread (struct websockets *ws) |
File containing internal functions and datatypes for WebSockets client.
enum ws_status |
The WebSockets client status.
void ws_cleanup | ( | struct websockets * | ws | ) |
char* ws_close_opcode_print | ( | enum ws_close_reason | opcode | ) |
Returns a enum ws_close_reason opcode in a string format.
opcode | the opcode to be converted to string |
enum ws_status ws_get_status | ( | struct websockets * | ws | ) |
Returns the WebSockets handle connection status.
ws | the WebSockets handle created with ws_init() |
struct websockets* ws_init | ( | struct ws_callbacks * | cbs, |
struct logconf * | config | ||
) |
Create a new (CURL-based) WebSockets handle.
cbs | set of functions to call back when server report events. |
config | optional pointer to a pre-initialized logconf |
bool ws_is_alive | ( | struct websockets * | ws | ) |
Check if a WebSockets connection is alive.
ws | the WebSockets handle created with ws_init() |
bool ws_is_functional | ( | struct websockets * | ws | ) |
Check if WebSockets connection is active.
ws | the WebSockets handle created with ws_init() |
void ws_perform | ( | struct websockets * | ws, |
_Bool * | is_running, | ||
uint64_t | wait_ms | ||
) |
Reads/Write available data from WebSockets.
Helper over curl_multi_perform()
ws | the WebSockets handle created with ws_init() |
is_running | receives true if the client is running and false otherwise |
wait_ms | limit amount in milliseconds to wait for until activity |
bool ws_send_text | ( | struct websockets * | ws, |
char | text[], | ||
size_t | len | ||
) |
Send a text message of given size.
Text messages do not need to include the null terminator (\0), they will be read up to len.
ws | the WebSockets handle created with ws_init() |
text | the pointer to memory (linear) to send. |
len | the length in bytes of text. |
void ws_set_url | ( | struct websockets * | ws, |
const char | base_url[], | ||
const char | ws_protocols[] | ||
) |
Set the URL for the WebSockets handle to connect.
ws | the WebSockets handle created with ws_init() |
base_url | the URL to connect, such as ws://echo.websockets.org |
ws_protocols | NULL or something like "chat", "superchat",... |
void ws_start | ( | struct websockets * | ws | ) |
Signals connecting state before entering the WebSockets event loop.
ws | the WebSockets handle created with ws_init() |
uint64_t ws_timestamp | ( | struct websockets * | ws | ) |
The WebSockets handle concept of "now".
ws | the WebSockets handle created with ws_init() |