SharkSSL C/C++ Reference
TLS, cryptography, certificates, and PSA integration
WsClientLib.h
Go to the documentation of this file.
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * SharkSSL Embedded SSL/TLS Stack
10 ****************************************************************************
11 * PROGRAM MODULE
12 *
13 * $Id: WsClientLib.h 6673 2026-10-29 16:58:52Z wini $
14 *
15 * COPYRIGHT: Real Time Logic LLC, 2014 - 2026
16 *
17 * This software is copyrighted by and is the sole property of Real
18 * Time Logic LLC. All rights, title, ownership, or other interests in
19 * the software remain the property of Real Time Logic LLC. This
20 * software may only be used in accordance with the terms and
21 * conditions stipulated in the corresponding license agreement under
22 * which the software has been supplied. Any unauthorized use,
23 * duplication, transmission, distribution, or disclosure of this
24 * software is expressly forbidden.
25 *
26 * This Copyright notice may not be removed or modified without prior
27 * written consent of Real Time Logic LLC.
28 *
29 * Real Time Logic LLC. reserves the right to modify this software
30 * without notice.
31 *
32 * http://realtimelogic.com
33 * http://sharkssl.com
34 ****************************************************************************
35 *
36 */
37
38#ifndef _WsClientLib_h
39#define _WsClientLib_h
40
41
42#include "selib.h"
43
44#ifdef _DOXYGEN
45/* For documentation purposes */
46#define WSC_DUAL
47#endif
48
67#define WSOP_Text 0x81
69#define WSOP_Binary 0x82
71#define WSOP_Close 0x88
73#define WSOP_Ping 0x89
75#define WSOP_Pong 0x8A
76 /* end group WebSocketOpcodes */
78
80#define WSC_TLS_AUTH_FAILED -105
81
82
83
87typedef struct
88{
89#ifdef WSC_DUAL
91 U8* recBuf;
98#endif
107
108 /* Begin private */
109 U8* overflowPtr; /* Set if: consumed more data from stream than frame len */
110 int overflowLen; /* overflowPtr len is used internally in wsRawRead */
111 int frameHeaderIx; /* Cursor used when reading frameHeader from socket */
112 U8 frameHeader[4]; /*[0] FIN+opcode, [1] Payload len, [2-3] Ext payload len*/
113 /* End private */
114
117} WscState;
118
119
120#ifdef __cplusplus
121extern "C" {
122#endif
123
124
162int wscProtocolHandshake(WscState* wss,U32 tmo, const char* host,
163 const char* path,const char* origin);
164
165
173int wscSendBin(WscState* wss, U8* buf, int len);
174
182int wscSendCtrl(WscState* wss, U8 opCode, const U8* buf,int len);
183
189int wscClose(WscState* wss, int statusCode);
190
191
217int wscRead(WscState* wss, U8 **buf, U32 timeout);
218
219#ifdef __cplusplus
220}
221#endif
222 /* end group WsClientLib */
224
225#endif
struct SharkSslCon SharkSslCon
SharkSslCon is an opaque handle returned by function SharkSsl_createCon.
Definition: SharkSSL.h:496
int wscProtocolHandshake(WscState *wss, U32 tmo, const char *host, const char *path, const char *origin)
Upgrades (morphs) an HTTPS request/response pair to a WebSocket connection.
int wscSendCtrl(WscState *wss, U8 opCode, const U8 *buf, int len)
Sends a WebSocket control frame.
int wscRead(WscState *wss, U8 **buf, U32 timeout)
Wait for WebSocket frames sent by the server.
int wscClose(WscState *wss, int statusCode)
Sends a WebSocket close control frame to the server and closes the connection.
int wscSendBin(WscState *wss, U8 *buf, int len)
Sends binary data to server.
#define SOCKET
Infinite wait time option for socket read functions.
Definition: selib.h:103
WebSocket Client State Information, initialize using: WscState wss={0}; however, several members must...
Definition: WsClientLib.h:88
int sendBufLen
The send buffer length must be set to the sendBuf length.
Definition: WsClientLib.h:97
U8 * recBuf
The receive buffer must be set when not in secure mode.
Definition: WsClientLib.h:91
U8 * sendBuf
The send buffer must be set when not in secure mode.
Definition: WsClientLib.h:93
U8 isTimeout
Set when the read function returns due to a timeout.
Definition: WsClientLib.h:116
int bytesRead
Read frame data until: frameLen - bytesRead = 0.
Definition: WsClientLib.h:106
SOCKET * sock
The SOCKET object must be set.
Definition: WsClientLib.h:102
int frameLen
The WebSocket frame length.
Definition: WsClientLib.h:104
int frameHeaderIx
Definition: WsClientLib.h:111
int overflowLen
Definition: WsClientLib.h:110
int recBufLen
The receive buffer length must be set to the recBuf length.
Definition: WsClientLib.h:95
SharkSslCon * scon
The SharkSslCon object must be set when using secure mode.
Definition: WsClientLib.h:100
U8 * overflowPtr
Definition: WsClientLib.h:109