Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
WebSocketServer.h
Go to the documentation of this file.
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Application Server
10 *
11 ****************************************************************************
12 * HEADER
13 *
14 * $Id: WebSocketServer.h 6056 2026-09-20 05:09:33Z wini $
15 *
16 * COPYRIGHT: Real Time Logic LLC, 2015 - 2026
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
41#ifndef _WebSocketServer_h
42#define _WebSocketServer_h
43
44#include <DynBuffer.h>
45
46
76struct WSS;
77struct WSSCB;
78
89typedef void (*WSSCB_Frame)(
90 struct WSSCB* o,struct WSS* wss,void* data,int len,int text);
91
92
103typedef void (*WSSCB_Ping)(struct WSSCB* o,struct WSS* wss,void* data,int len);
104
105
115typedef void (*WSSCB_Close)(struct WSSCB* o,struct WSS* wss,int status);
116
122typedef struct WSSCB
123{
124#ifdef __cplusplus
130 WSSCB(WSSCB_Frame frameFp, WSSCB_Close closeFp, WSSCB_Ping pingFp=0);
131#endif
132 WSSCB_Frame frameFp;
133 WSSCB_Close closeFp;
134 WSSCB_Ping pingFp;
136
137
144#define WSSCB_constructor(o, frame, close, ping) \
145 (o)->frameFp=frame,(o)->closeFp=close,(o)->pingFp=ping
146
147#ifdef __cplusplus
149 WSSCB_Frame frameFp, WSSCB_Close closeFp, WSSCB_Ping pingFp) {
150 WSSCB_constructor(this, frameFp, closeFp, pingFp);
151}
152#endif
153
154
157typedef struct WSS
158{
159#ifdef __cplusplus
169 WSS(WSSCB* cb, SoDisp* disp, int startSize, int expandSize);
170
174 ~WSS();
175
184 int upgrade(HttpRequest* req);
185
192 int connect(HttpConnection* con);
193
201 int write(const void* data, int len, bool isTxt);
202
211 int close(int statusCode=1000);
212
217 bool isValid();
218
219#endif
220 SoDispCon super;
221 DynBuffer db;
222 WSSCB* cb;
223 int endOfPacketIx;
225
226
227#ifdef __cplusplus
228extern "C" {
229#endif
233BA_API void WSS_constructor(
234 WSS* o, WSSCB* cb, SoDisp* disp, int startSize, int expandSize);
238BA_API void WSS_destructor(WSS* o);
242BA_API int WSS_upgrade(WSS* o, HttpRequest* req);
246BA_API int WSS_connect(WSS* o, HttpConnection* con);
257BA_API int WSS_rawWrite(WSS* o, const void* data, int len, int opCode);
261#define WSS_write(o, data, len, isTxt) WSS_rawWrite(o, data, len, isTxt?1:2)
265BA_API int WSS_close(WSS* o, int statusCode);
269#define WSS_isValid(o) SoDispCon_isValid((SoDispCon*)o)
270#ifdef __cplusplus
271}
272
273inline WSS::WSS(WSSCB* cb, SoDisp* disp, int startSize, int expandSize) {
274 WSS_constructor(this, cb, disp, startSize, expandSize);
275}
276inline WSS::~WSS() {
277 WSS_destructor(this);
278}
279inline int WSS::upgrade(HttpRequest* req) {
280 return WSS_upgrade(this, req);
281}
282inline int WSS::connect(HttpConnection* con) {
283 return WSS_connect(this, con);
284}
285inline int WSS::write(const void* data, int len, bool isTxt) {
286 return WSS_write(this, data, len,isTxt);
287}
288inline int WSS::close(int statusCode) {
289 return WSS_close(this, statusCode);
290}
291inline bool WSS::isValid() {
292 return WSS_isValid(this) ? true : false; }
293#endif
294
295 /* end of WebSockets */
297
298#endif
struct WSSCB WSSCB
WebSocket Server Connection Callback Interface: provides an interface between your application and th...
BA_API void WSS_destructor(WSS *o)
Close the transport and free receive storage, without a WebSocket close handshake or close callback.
WSSCB(WSSCB_Frame frameFp, WSSCB_Close closeFp, WSSCB_Ping pingFp=0)
Provide your callback event functions.
Definition: WebSocketServer.h:148
BA_API int WSS_rawWrite(WSS *o, const void *data, int len, int opCode)
Send one final server frame with a caller-selected opcode.
bool isValid()
Check the local transport handle.
Definition: WebSocketServer.h:291
BA_API int WSS_upgrade(WSS *o, HttpRequest *req)
Perform the server handshake and take over the request's connection.
#define WSSCB_constructor(o, frame, close, ping)
Initialize callback storage.
Definition: WebSocketServer.h:144
BA_API void WSS_constructor(WSS *o, WSSCB *cb, SoDisp *disp, int startSize, int expandSize)
Initialize an unconnected WebSocket object.
int close(int statusCode=1000)
Attempt to send a close frame, then close the transport immediately.
Definition: WebSocketServer.h:288
~WSS()
Close the transport and free receive storage, without a WebSocket close handshake or close callback.
Definition: WebSocketServer.h:276
int write(const void *data, int len, bool isTxt)
Send one complete, unmasked server frame using blocking transport writes.
Definition: WebSocketServer.h:285
struct WSS WSS
WebSocket Server (WSS)
BA_API int WSS_connect(WSS *o, HttpConnection *con)
Take an HTTP connection after its WebSocket handshake is complete.
void(* WSSCB_Ping)(struct WSSCB *o, struct WSS *wss, void *data, int len)
Optional notification after the internal pong send attempt succeeds.
Definition: WebSocketServer.h:103
void(* WSSCB_Frame)(struct WSSCB *o, struct WSS *wss, void *data, int len, int text)
Receive a complete unfragmented text or binary frame.
Definition: WebSocketServer.h:89
#define WSS_isValid(o)
Check the local transport handle.
Definition: WebSocketServer.h:269
WSS(WSSCB *cb, SoDisp *disp, int startSize, int expandSize)
Initialize an unconnected WebSocket object.
Definition: WebSocketServer.h:273
void(* WSSCB_Close)(struct WSSCB *o, struct WSS *wss, int status)
Notify closure after the underlying connection has been closed.
Definition: WebSocketServer.h:115
int connect(HttpConnection *con)
Take an HTTP connection after its WebSocket handshake is complete.
Definition: WebSocketServer.h:282
#define WSS_write(o, data, len, isTxt)
Send one complete, unmasked server frame using blocking transport writes.
Definition: WebSocketServer.h:261
BA_API int WSS_close(WSS *o, int statusCode)
Attempt to send a close frame, then close the transport immediately.
int upgrade(HttpRequest *req)
Perform the server handshake and take over the request's connection.
Definition: WebSocketServer.h:279
A dynamic buffer.
Definition: DynBuffer.h:68
Contains information about the physical socket connection.
Definition: HttpConnection.h:80
The HttpServer creates an HttpRequest object when the HttpServer parses a client request.
Definition: HttpServer.h:950
Contains information about the physical socket connection.
Definition: SoDispCon.h:120
The SoDisp dispatches any socket connection that contains data by calling the SoDispCon::execute memb...
Definition: SoDisp.h:91
WebSocket Server Connection Callback Interface: provides an interface between your application and th...
Definition: WebSocketServer.h:123
WebSocket Server (WSS)
Definition: WebSocketServer.h:158