16 #ifndef TW_WEBSOCKET_H
17 #define TW_WEBSOCKET_H
28 struct http_parser_settings;
35 typedef int (*ws_cb) (
struct twWs * ws);
36 typedef int (*ws_data_cb) (
struct twWs * ws,
const char *at,
size_t length);
41 #define WS_TLS_CONN(a) (twTlsClient *)a->connection
129 int twWs_Create(
char * host, uint16_t port,
char * resource,
char * api_key,
char * gatewayName,
130 uint32_t messageChunkSize, uint16_t frameSize,
twWs ** entity);
struct twWs twWs
Websocket entity structure definition.
int twWs_RegisterBinaryMessageCallback(twWs *ws, ws_data_cb cb)
Registers a function to be called when the websocket receives a complete binary message.
Definition: twWebsocket.c:531
ws_data_cb on_ws_binaryMessage
Definition: twWebsocket.h:91
Definition: twWebsocket.h:54
Definition: twWebsocket.h:59
int twWs_Create(char *host, uint16_t port, char *resource, char *api_key, char *gatewayName, uint32_t messageChunkSize, uint16_t frameSize, twWs **entity)
Creates a new websocket struct and the underlying dependent components.
Definition: twWebsocket.c:124
int32_t bytesNeeded
Definition: twWebsocket.h:68
int twWs_RegisterPongCallback(twWs *ws, ws_data_cb cb)
Registers a function to be called when the websocket receives a Pong message.
Definition: twWebsocket.c:558
char twWs_IsConnected(twWs *ws)
Gets the connection status of a websocket entity structure.
Definition: twWebsocket.c:449
#define TW_MUTEX
For Linux builds a TW_MUTEX is a pthread_mutex_t.
Definition: twLinux-openssl.h:81
uint32_t sessionId
Definition: twWebsocket.h:83
signed char isConnected
Definition: twWebsocket.h:89
uint16_t frameSize
Definition: twWebsocket.h:70
char * gatewayType
Definition: twWebsocket.h:80
int twWs_SendPing(twWs *ws, char *msg)
Send a Ping message over the websocket.
Definition: twWebsocket.c:875
int twWs_Disconnect(twWs *ws, enum close_status code, char *reason)
Disconnect a websocket connection from the server.
Definition: twWebsocket.c:453
Wrappers for OS-specific functionality.
unsigned char * security_key
Definition: twWebsocket.h:82
Definition: twWebsocket.h:55
ws_cb on_ws_connected
Definition: twWebsocket.h:90
char * frameBufferPtr
Definition: twWebsocket.h:72
int twWs_RegisterPingCallback(twWs *ws, ws_data_cb cb)
Registers a function to be called when the websocket receives a Ping message.
Definition: twWebsocket.c:549
struct twTlsClient * connection
Definition: twWebsocket.h:66
Definition: twWebsocket.h:56
Definition: twWebsocket.h:52
int twWs_RegisterCloseCallback(twWs *ws, ws_data_cb cb)
Registers a function to be called when the websocket is closed by the server.
Definition: twWebsocket.c:522
uint32_t messageChunkSize
Definition: twWebsocket.h:67
uint16_t port
Definition: twWebsocket.h:76
signed char connect_state
Definition: twWebsocket.h:88
Definition: twWebsocket.h:47
int twWs_SendMessage(twWs *ws, char *buf, uint32_t length, char isText)
Send a message over the websocket.
Definition: twWebsocket.c:815
char read_state
Definition: twWebsocket.h:69
Common definitions for C SDK.
Definition: twWebsocket.h:48
int twWs_RegisterConnectCallback(twWs *ws, ws_cb cb)
Registers a function to be called when the websocket is successfully connected.
Definition: twWebsocket.c:513
ws_data_cb on_ws_close
Definition: twWebsocket.h:95
Definition: twWebsocket.h:49
Definition: twWebsocket.h:57
int twWs_Receive(twWs *ws, uint32_t timeout)
Check the websocket for data and drive the state machine of the websocket.
Definition: twWebsocket.c:568
Definition: twWebsocket.h:58
close_status
Websocket close reasoning enumeration.
Definition: twWebsocket.h:46
ws_data_cb on_ws_pong
Definition: twWebsocket.h:94
char * api_key
Definition: twWebsocket.h:77
int twWs_SendPong(twWs *ws, char *msg)
Send a Pong message over the websocket.
Definition: twWebsocket.c:885
char * resource
Definition: twWebsocket.h:84
int twWs_RegisterTextMessageCallback(twWs *ws, ws_data_cb cb)
Registers a function to be called when the websocket receives a complete text message.
Definition: twWebsocket.c:540
ws_data_cb on_ws_textMessage
Definition: twWebsocket.h:92
TW_MUTEX sendMessageMutex
Definition: twWebsocket.h:85
TW_MUTEX recvMutex
Definition: twWebsocket.h:87
unsigned char ws_header[64]
Definition: twWebsocket.h:73
TW_MUTEX sendFrameMutex
Definition: twWebsocket.h:86
Definition: twWebsocket.h:53
TLS client structure definition.
Definition: twTls.h:34
Websocket entity structure definition.
Definition: twWebsocket.h:65
Definition: twWebsocket.h:50
int twWs_Delete(twWs *ws)
Frees all memory associated with a twWs structure and all its owned substructures.
Definition: twWebsocket.c:205
char * gatewayName
Definition: twWebsocket.h:78
ws_data_cb on_ws_ping
Definition: twWebsocket.h:93
char * host
Definition: twWebsocket.h:75
int twWs_Connect(twWs *ws, uint32_t timeout)
Establishes a websocket connection to the server.
Definition: twWebsocket.c:228
Definition: twWebsocket.h:51
char * frameBuffer
Definition: twWebsocket.h:71
unsigned char * headerPtr
Definition: twWebsocket.h:74