Loading...
Searching...
No Matches
ServerSentEventHandler.qc.dox.h
// -*- mode: c++; indent-tabs-mode: nil -*-
/* ServerSentEventHandler.qc Copyright 2025 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
namespace ServerSentEventHandler {
class ServerSentEventHandler : public HttpServer::AbstractHttpSocketHandler, public Logger::LoggerWrapper {
public:
const DefaultSocketSendTimeout = 30s;
const DefaultHeartbeatInterval = 20;
const DefaultHeartbeatMsg = ":hb\n\n";
const Options = ...;
const SseResponseHeader = ...;
const DataSerializationSupport = ...;
protected:
RWLock rwl();
string serialization;
code serializer;
hash<string, ServerSentEventConnection> ch;
int heartbeat = DefaultHeartbeatInterval;
string heartbeat_msg = DefaultHeartbeatMsg;
public:
private:
string tlk = get_random_string(50);
public:
constructor(*HttpServer::AbstractAuthenticator auth, *hash<auto> opts) ;
constructor(hash<auto> opts) ;
int getHeartbeat();
setHeartbeat(softint seconds);
setHeartbeat(date seconds);
hash<HttpResponseInfo> handleRequest(hash<auto> cx, hash<auto> hdr, *data b);
*list<string> getConnectionIds();
bool startImpl(softstring lid, hash<auto> cx, hash<auto> hdr, Qore::Socket sock);
bool flushIo(ServerSentEventConnection conn, Socket sock);
string encodeMessage(hash<SseMessageInfo> msg);
static string serializeJson(auto v);
static string serializeDefault(auto v);
ServerSentEventConnection getConnectionImpl(Socket sock, hash<auto> cx, hash<auto> hdr, string cid);
ServerSentEventConnection doNewConnection(Socket sock, hash<auto> cx, hash<auto> hdr, string cid);
connectionRegisteredImpl(ServerSentEventConnection conn);
deregisterConnectionImpl(ServerSentEventConnection conn);
sendAll(hash<SseMessageInfo> msg);
sendOne(softstring id, hash<SseMessageInfo> msg);
stopOne(softstring id);
logInfo(string fmt, ...);
logError(string fmt, ...);
logWarn(string fmt, ...);
logDebug(string fmt, ...);
protected:
registerNewConnectionIntern(string cid, ServerSentEventConnection rv);
public:
protected:
removeConnectionLocked(string cid);
public:
protected:
sendHeartbeatMsg(Socket sock);
public:
protected:
replayEventsSince(ServerSentEventConnection conn, auto id);
public:
protected:
constructorInit(*hash<auto> opts);
public:
private:
bool flushIoIntern(ServerSentEventConnection conn, Socket sock, bool update_tld);
public:
};
};
ServerSentEventHandler::ServerSentEventConnection
this class represents a connection to an HTTP client
Definition ServerSentEventConnection.qc.dox.h:37
ServerSentEventHandler::ServerSentEventHandler::constructor
constructor(*HttpServer::AbstractAuthenticator auth, *hash< auto > opts)
Create the object optionally with the given AbstractAuthenticator.
ServerSentEventHandler::ServerSentEventHandler::removeConnectionLocked
removeConnectionLocked(string cid)
Called when a connection is removed from the connection map.
ServerSentEventHandler::ServerSentEventHandler::setHeartbeat
setHeartbeat(date seconds)
sets the heartbeat interval as a number of seconds
ServerSentEventHandler::ServerSentEventHandler::sendOne
sendOne(softstring id, hash< SseMessageInfo > msg)
sends a message to the given connection ID
ServerSentEventHandler::ServerSentEventHandler::serializeDefault
static string serializeDefault(auto v)
Default value serialization.
ServerSentEventHandler::ServerSentEventHandler::constructorInit
constructorInit(*hash< auto > opts)
Common constructor initialization.
ServerSentEventHandler::ServerSentEventHandler::getConnectionImpl
ServerSentEventConnection getConnectionImpl(Socket sock, hash< auto > cx, hash< auto > hdr, string cid)
Called when a connection is established; the default implementation creates a ServerSentEventConnecti...
ServerSentEventHandler::ServerSentEventHandler::serialization
string serialization
The value of the serialization option.
Definition ServerSentEventHandler.qc.dox.h:73
ServerSentEventHandler::ServerSentEventHandler::sendHeartbeatMsg
sendHeartbeatMsg(Socket sock)
Send the default heartbeat message.
ServerSentEventHandler::ServerSentEventHandler::sendAll
sendAll(hash< SseMessageInfo > msg)
sends a message to all connected clients
ServerSentEventHandler::ServerSentEventHandler::logError
logError(string fmt,...)
Log to the logger.
ServerSentEventHandler::ServerSentEventHandler::logDebug
logDebug(string fmt,...)
Log to the logger.
ServerSentEventHandler::ServerSentEventHandler::startImpl
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...
ServerSentEventHandler::ServerSentEventHandler::rwl
RWLock rwl()
connection read-write lock
ServerSentEventHandler::ServerSentEventHandler::doNewConnection
ServerSentEventConnection doNewConnection(Socket sock, hash< auto > cx, hash< auto > hdr, string cid)
Called when a connection is established; registers the new connection internally.
ServerSentEventHandler::ServerSentEventHandler::serializeJson
static string serializeJson(auto v)
JSON value serialization.
ServerSentEventHandler::ServerSentEventHandler::constructor
constructor(hash< auto > opts)
Create the object optionally with the given optiond.
ServerSentEventHandler::ServerSentEventHandler::getConnectionIds
*list< string > getConnectionIds()
get list of socket connection ids
ServerSentEventHandler::ServerSentEventHandler::getHeartbeat
int getHeartbeat()
returns the connection heartbeat interval as a number of seconds
ServerSentEventHandler::ServerSentEventHandler::connectionRegisteredImpl
connectionRegisteredImpl(ServerSentEventConnection conn)
Called when the connection is registered; the default implementation does nothing.
ServerSentEventHandler::ServerSentEventHandler::handleRequest
hash< HttpResponseInfo > handleRequest(hash< auto > cx, hash< auto > hdr, *data b)
called by the HTTP server to handle incoming HTTP requests
ServerSentEventHandler::ServerSentEventHandler::logWarn
logWarn(string fmt,...)
Log to the logger.
ServerSentEventHandler::ServerSentEventHandler::flushIo
bool flushIo(ServerSentEventConnection conn, Socket sock)
Flushes I/O in the connection queue.
ServerSentEventHandler::ServerSentEventHandler::ch
hash< string, ServerSentEventConnection > ch
connection hash
Definition ServerSentEventHandler.qc.dox.h:79
ServerSentEventHandler::ServerSentEventHandler::registerNewConnectionIntern
registerNewConnectionIntern(string cid, ServerSentEventConnection rv)
Called while holding the write lock to register the new connection.
ServerSentEventHandler::ServerSentEventHandler::serializer
code serializer
Value serialization code.
Definition ServerSentEventHandler.qc.dox.h:76
ServerSentEventHandler::ServerSentEventHandler::setHeartbeat
setHeartbeat(softint seconds)
sets the heartbeat interval as a number of seconds
ServerSentEventHandler::ServerSentEventHandler::deregisterConnectionImpl
deregisterConnectionImpl(ServerSentEventConnection conn)
Called when the connection terminates; the default implementation does nothing.
ServerSentEventHandler::ServerSentEventHandler::replayEventsSince
replayEventsSince(ServerSentEventConnection conn, auto id)
Resend all events since the given event.
ServerSentEventHandler::ServerSentEventHandler::encodeMessage
string encodeMessage(hash< SseMessageInfo > msg)
Encode a message for sending.
ServerSentEventHandler::ServerSentEventHandler::logInfo
logInfo(string fmt,...)
Log to the logger.
ServerSentEventHandler::ServerSentEventHandler::stopOne
stopOne(softstring id)
stop given connection ID
ServerSentEventHandler
the ServerSentEventHandler namespace contains all the objects in the ServerSentEventHandler module
Definition ServerSentEventConnection.qc.dox.h:26