Qore ServerSentEventHandler Module Reference 1.0.2
Loading...
Searching...
No Matches
ServerSentEventHandler.qc.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* ServerSentEventHandler.qc Copyright 2025 Qore Technologies, s.r.o.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23*/
24
26namespace ServerSentEventHandler {
28
45
46public:
49
52
54 const DefaultHeartbeatMsg = ":hb\n\n";
55
57 const Options = ...;
58
59
61 const SseResponseHeader = ...;
62
63
66
67
68protected:
70 RWLock rwl();
71
74
77
79 hash<string, ServerSentEventConnection> ch;
80
83
86
87public:
88
89private:
91 string tlk = get_random_string(50);
92
93public:
94
96
108
109
111 constructor(hash<auto> opts) ;
112
113
115
118
119
121
123 setHeartbeat(softint seconds);
124
125
127
129 setHeartbeat(date seconds);
130
131
133
164 hash<HttpResponseInfo> handleRequest(hash<auto> cx, hash<auto> hdr, *data b);
165
166
168
170 *list<string> getConnectionIds();
171
172
174
190 bool startImpl(softstring lid, hash<auto> cx, hash<auto> hdr, Qore::Socket sock);
191
192
194
196 bool flushIo(ServerSentEventConnection conn, Socket sock);
197
198
200 string encodeMessage(hash<SseMessageInfo> msg);
201
202
204 static string serializeJson(auto v);
205
207 static string serializeDefault(auto v);
208
210 ServerSentEventConnection getConnectionImpl(Socket sock, hash<auto> cx, hash<auto> hdr, string cid);
211
212
214 ServerSentEventConnection doNewConnection(Socket sock, hash<auto> cx, hash<auto> hdr, string cid);
215
216
219
220
223
224
226
230 sendAll(hash<SseMessageInfo> msg);
231
232
234
240 sendOne(softstring id, hash<SseMessageInfo> msg);
241
242
244 stopOne(softstring id);
245
246
248 logInfo(string fmt, ...);
249
250
252 logError(string fmt, ...);
253
254
256 logWarn(string fmt, ...);
257
258
260 logDebug(string fmt, ...);
261
262
264protected:
266public:
267
268
270protected:
272public:
273
274
276protected:
278public:
279
280
282protected:
284public:
285
286
288protected:
290public:
291
292
294protected:
295 constructorInit(*hash<auto> opts);
296public:
297
298
299private:
300 bool flushIoIntern(ServerSentEventConnection conn, Socket sock, bool update_tld);
301public:
302
303};
304};
this class represents a connection to an HTTP client
Definition ServerSentEventConnection.qc.dox.h:37
constructor(*HttpServer::AbstractAuthenticator auth, *hash< auto > opts)
Create the object optionally with the given AbstractAuthenticator.
int heartbeat
heartbeat interval in seconds
Definition ServerSentEventHandler.qc.dox.h:82
removeConnectionLocked(string cid)
Called when a connection is removed from the connection map.
setHeartbeat(date seconds)
sets the heartbeat interval as a number of seconds
sendOne(softstring id, hash< SseMessageInfo > msg)
sends a message to the given connection ID
static string serializeDefault(auto v)
Default value serialization.
string getHeartbeatMessage(ServerSentEventConnection conn)
Returns the heartbeat message to send.
const DefaultHeartbeatMsg
default heartbeat message; this is a short comment to be used as a heartbeat message
Definition ServerSentEventHandler.qc.dox.h:54
constructorInit(*hash< auto > opts)
Common constructor initialization.
ServerSentEventConnection getConnectionImpl(Socket sock, hash< auto > cx, hash< auto > hdr, string cid)
Called when a connection is established; the default implementation creates a ServerSentEventConnecti...
string serialization
The value of the serialization option.
Definition ServerSentEventHandler.qc.dox.h:73
sendHeartbeatMsg(ServerSentEventConnection conn, Socket sock)
Send the default heartbeat message.
sendAll(hash< SseMessageInfo > msg)
sends a message to all connected clients
logError(string fmt,...)
Log to the logger.
logDebug(string fmt,...)
Log to the logger.
bool startImpl(softstring lid, hash< auto > cx, hash< auto > hdr, Qore::Socket sock)
Called from the HTTP server after the handleRequest() method indicates that a dedicated connection sh...
string tlk
Thread-local key for I/O check.
Definition ServerSentEventHandler.qc.dox.h:91
string heartbeat_msg
heartbeat message returned by getHeartbeatMessage()
Definition ServerSentEventHandler.qc.dox.h:85
RWLock rwl()
connection read-write lock
ServerSentEventConnection doNewConnection(Socket sock, hash< auto > cx, hash< auto > hdr, string cid)
Called when a connection is established; registers the new connection internally.
static string serializeJson(auto v)
JSON value serialization.
constructor(hash< auto > opts)
Create the object optionally with the given optiond.
*list< string > getConnectionIds()
get list of socket connection ids
const Options
known constructor options
Definition ServerSentEventHandler.qc.dox.h:57
connectionRegisteredImpl(ServerSentEventConnection conn)
Called when the connection is registered; the default implementation does nothing.
hash< HttpResponseInfo > handleRequest(hash< auto > cx, hash< auto > hdr, *data b)
called by the HTTP server to handle incoming HTTP requests
logWarn(string fmt,...)
Log to the logger.
bool flushIo(ServerSentEventConnection conn, Socket sock)
Flushes I/O in the connection queue.
const SseResponseHeader
Response header to SSE requests.
Definition ServerSentEventHandler.qc.dox.h:61
registerNewConnectionIntern(string cid, ServerSentEventConnection conn)
Called while holding the write lock to register the new connection.
const DefaultSocketSendTimeout
default socket send timeout
Definition ServerSentEventHandler.qc.dox.h:48
const DataSerializationSupport
Data serialization support.
Definition ServerSentEventHandler.qc.dox.h:65
const DefaultHeartbeatInterval
default heartbeat interval in seconds
Definition ServerSentEventHandler.qc.dox.h:51
hash< string, ServerSentEventConnection > ch
connection hash
Definition ServerSentEventHandler.qc.dox.h:79
code serializer
Value serialization code.
Definition ServerSentEventHandler.qc.dox.h:76
setHeartbeat(softint seconds)
sets the heartbeat interval as a number of seconds
deregisterConnectionImpl(ServerSentEventConnection conn)
Called when the connection terminates; the default implementation does nothing.
replayEventsSince(ServerSentEventConnection conn, auto id)
Resend all events since the given event.
string encodeMessage(hash< SseMessageInfo > msg)
Encode a message for sending.
logInfo(string fmt,...)
Log to the logger.
int getHeartbeat(ServerSentEventConnection conn)
returns the connection heartbeat interval as a number of seconds
stopOne(softstring id)
stop given connection ID
the ServerSentEventHandler namespace contains all the objects in the ServerSentEventHandler module
Definition ServerSentEventConnection.qc.dox.h:26