Qore ServerSentEventHandler Module Reference 1.0
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
44class ServerSentEventHandler : public HttpServer::AbstractHttpSocketHandler, public Logger::LoggerWrapper {
45
46public:
48 const DefaultSocketSendTimeout = 30s;
49
51 const DefaultHeartbeatInterval = 20;
52
54 const DefaultHeartbeatMsg = ":hb\n\n";
55
57 const Options = ...;
58
59
61 const SseResponseHeader = ...;
62
63
65 const DataSerializationSupport = ...;
66
67
68protected:
70 RWLock rwl();
71
74
77
79 hash<string, ServerSentEventConnection> ch;
80
82 int heartbeat = DefaultHeartbeatInterval;
83
85 string heartbeat_msg = DefaultHeartbeatMsg;
86
87public:
88
89private:
91 string tlk = get_random_string(50);
92
93public:
94
96
107 constructor(*HttpServer::AbstractAuthenticator auth, *hash<auto> opts) ;
108
109
111 constructor(hash<auto> opts) ;
112
113
115
120
121
123
127 setHeartbeat(softint seconds);
128
129
131
135 setHeartbeat(date seconds);
136
137
139
170 hash<auto> handleRequest(hash<auto> cx, hash<auto> hdr, *data b);
171
172
174
176 *list<string> getConnectionIds();
177
178
180
196 bool startImpl(softstring lid, hash<auto> cx, hash<auto> hdr, Qore::Socket sock);
197
198
200
202 bool flushIo(ServerSentEventConnection conn, Socket sock);
203
204
206 string encodeMessage(hash<SseMessageInfo> msg);
207
208
210 static string serializeJson(auto v);
211
213 static string serializeDefault(auto v);
214
216 ServerSentEventConnection getConnectionImpl(Socket sock, hash<auto> cx, hash<auto> hdr, string cid);
217
218
220 ServerSentEventConnection doNewConnection(Socket sock, hash<auto> cx, hash<auto> hdr, string cid);
221
222
225
226
228
232 sendAll(hash<SseMessageInfo> msg);
233
234
236
242 sendOne(softstring id, hash<SseMessageInfo> msg);
243
244
246 stopOne(softstring id);
247
248
250 logInfo(string fmt, ...);
251
252
254 logError(string fmt, ...);
255
256
258 logWarn(string fmt, ...);
259
260
262 logDebug(string fmt, ...);
263
264
266protected:
268public:
269
270
272protected:
273 constructorInit(*hash<auto> opts);
274public:
275
276
277private:
278 bool flushIoIntern(ServerSentEventConnection conn, Socket sock, bool update_tld);
279public:
280
281};
282};
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.
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.
hash< auto > handleRequest(hash< auto > cx, hash< auto > hdr, *data b)
called by the HTTP server to handle incoming HTTP requests
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
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...
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
int getHeartbeat()
returns the connection heartbeat interval as a number of seconds
logWarn(string fmt,...)
Log to the logger.
bool flushIo(ServerSentEventConnection conn, Socket sock)
Flushes I/O in the connection queue.
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.
stopOne(softstring id)
stop given connection ID
the ServerSentEventHandler namespace contains all the objects in the ServerSentEventHandler module
Definition ServerSentEventConnection.qc.dox.h:26