Barracuda Application Server C/C++ Reference
NO
WebSocketServer.h
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Application Server
10 *
11 ****************************************************************************
12 * HEADER
13 *
14 * $Id: WebSocketServer.h 5392 2023-02-21 15:56:50Z wini $
15 *
16 * COPYRIGHT: Real Time Logic LLC, 2015 - 2023
17 *
18 * This software is copyrighted by and is the sole property of Real
19 * Time Logic LLC. All rights, title, ownership, or other interests in
20 * the software remain the property of Real Time Logic LLC. This
21 * software may only be used in accordance with the terms and
22 * conditions stipulated in the corresponding license agreement under
23 * which the software has been supplied. Any unauthorized use,
24 * duplication, transmission, distribution, or disclosure of this
25 * software is expressly forbidden.
26 *
27 * This Copyright notice may not be removed or modified without prior
28 * written consent of Real Time Logic LLC.
29 *
30 * Real Time Logic LLC. reserves the right to modify this software
31 * without notice.
32 *
33 * http://www.realtimelogic.com
34 ****************************************************************************
35 *
36 *
37 */
38
39#ifndef _WebSocketServer_h
40#define _WebSocketServer_h
41
42#include <DynBuffer.h>
43
44
73struct WSS;
74struct WSSCB;
75
85typedef void (*WSSCB_Frame)(
86 struct WSSCB* o,struct WSS* wss,void* data,int len,int text);
87
88
96typedef void (*WSSCB_Ping)(struct WSSCB* o,struct WSS* wss,void* data,int len);
97
98
109typedef void (*WSSCB_Close)(struct WSSCB* o,struct WSS* wss,int status);
110
116typedef struct WSSCB
117{
118#ifdef __cplusplus
124 WSSCB(WSSCB_Frame frameFp, WSSCB_Close closeFp, WSSCB_Ping pingFp=0);
125#endif
126 WSSCB_Frame frameFp;
127 WSSCB_Close closeFp;
128 WSSCB_Ping pingFp;
130
131
132#define WSSCB_constructor(o, frame, close, ping) \
133 (o)->frameFp=frame,(o)->closeFp=close,(o)->pingFp=ping
134
135#ifdef __cplusplus
137 WSSCB_Frame frameFp, WSSCB_Close closeFp, WSSCB_Ping pingFp) {
138 WSSCB_constructor(this, frameFp, closeFp, pingFp);
139}
140#endif
141
142
145typedef struct WSS
146{
147#ifdef __cplusplus
158 WSS(WSSCB* cb, SoDisp* disp, int startSize, int expandSize);
159
162 ~WSS();
163
174 int upgrade(HttpRequest* req);
175
182 int connect(HttpConnection* con);
183
189 int write(const void* data, int len, bool isTxt);
190
196 int close(int statusCode=1000);
197
200 bool isValid();
201
202#endif
203 SoDispCon super;
204 DynBuffer db;
205 WSSCB* cb;
206 int endOfPacketIx;
208
209
210#ifdef __cplusplus
211extern "C" {
212#endif
213BA_API void WSS_constructor(
214 WSS* o, WSSCB* cb, SoDisp* disp, int startSize, int expandSize);
215BA_API void WSS_destructor(WSS* o);
216BA_API int WSS_upgrade(WSS* o, HttpRequest* req);
217BA_API int WSS_connect(WSS* o, HttpConnection* con);
218BA_API int WSS_rawWrite(WSS* o, const void* data, int len, int opCode);
219#define WSS_write(o, data, len, isTxt) WSS_rawWrite(o, data, len, isTxt?1:2)
220BA_API int WSS_close(WSS* o, int statusCode);
221#define WSS_isValid(o) SoDispCon_isValid((SoDispCon*)o)
222#ifdef __cplusplus
223}
224
225inline WSS::WSS(WSSCB* cb, SoDisp* disp, int startSize, int expandSize) {
226 WSS_constructor(this, cb, disp, startSize, expandSize);
227}
228inline WSS::~WSS() {
229 WSS_destructor(this);
230}
231inline int WSS::upgrade(HttpRequest* req) {
232 return WSS_upgrade(this, req);
233}
234inline int WSS::connect(HttpConnection* con) {
235 return WSS_connect(this, con);
236}
237inline int WSS::write(const void* data, int len, bool isTxt) {
238 return WSS_write(this, data, len,isTxt);
239}
240inline int WSS::close(int statusCode) {
241 return WSS_close(this, statusCode);
242}
243inline bool WSS::isValid() {
244 return WSS_isValid(this) ? true : false; }
245#endif
246
247 /* end of WebSockets */
249
250#endif
struct WSSCB WSSCB
WebSocket Server Connection Callback Interface: provides an interface between your application and th...
WSSCB(WSSCB_Frame frameFp, WSSCB_Close closeFp, WSSCB_Ping pingFp=0)
Provide your callback event functions.
Definition: WebSocketServer.h:136
bool isValid()
Returns true if the WebSocket connection is valid.
Definition: WebSocketServer.h:243
int close(int statusCode=1000)
Gracefully close the WebSocket connection by sending WebSocket status code N to the client prior to c...
Definition: WebSocketServer.h:240
~WSS()
destructor.
Definition: WebSocketServer.h:228
int write(const void *data, int len, bool isTxt)
Write/send a WebSocket frame.
Definition: WebSocketServer.h:237
struct WSS WSS
WebSocket Server (WSS)
void(* WSSCB_Ping)(struct WSSCB *o, struct WSS *wss, void *data, int len)
Optional webSocket callback: the function is called when the client sends a ping message.
Definition: WebSocketServer.h:96
void(* WSSCB_Frame)(struct WSSCB *o, struct WSS *wss, void *data, int len, int text)
WebSocket callback: a WebSocket frame is received.
Definition: WebSocketServer.h:85
WSS(WSSCB *cb, SoDisp *disp, int startSize, int expandSize)
Create and initialize a WebSocket Server instance.
Definition: WebSocketServer.h:225
void(* WSSCB_Close)(struct WSSCB *o, struct WSS *wss, int status)
WebSocket callback: the client closed the connection or the connection closed unexpectedly.
Definition: WebSocketServer.h:109
int connect(HttpConnection *con)
Upgrades (morphs) an HTTP request to a persistent WebSocket connection.
Definition: WebSocketServer.h:234
int upgrade(HttpRequest *req)
Upgrades an HTTP server request to a persistent WebSocket connection.
Definition: WebSocketServer.h:231
A dynamic buffer.
Definition: DynBuffer.h:60
Contains information about the physical socket connection.
Definition: HttpConnection.h:76
The HttpServer creates an HttpRequest object when the HttpServer parses a client request.
Definition: HttpServer.h:808
Contains information about the physical socket connection.
Definition: SoDispCon.h:112
The SoDisp dispatches any socket connection that contains data by calling the SoDispCon::execute memb...
Definition: SoDisp.h:86
WebSocket Server Connection Callback Interface: provides an interface between your application and th...
Definition: WebSocketServer.h:117
WebSocket Server (WSS)
Definition: WebSocketServer.h:146