SNode.C
Loading...
Searching...
No Matches
SubProtocol.h
Go to the documentation of this file.
1/*
2 * SNode.C - a slim toolkit for network communication
3 * Copyright (C) Volker Christian <me@vchrist.at>
4 * 2020, 2021, 2022, 2023, 2024, 2025
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published
8 * by the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef WEB_WEBSOCKET_SERVER_SUBSPROTOCOL_H
21#define WEB_WEBSOCKET_SERVER_SUBSPROTOCOL_H
22
23#include "web/websocket/SubProtocol.h"
24
25namespace web::websocket::server {
26 class SocketContextUpgrade;
27} // namespace web::websocket::server
28
29// IWYU pragma: no_include "web/websocket/SubProtocol.hpp"
30
31#ifndef DOXYGEN_SHOULD_SKIP_THIS
32
33#include <cstddef>
34#include <functional>
35#include <string>
36
37#endif /* DOXYGEN_SHOULD_SKIP_THIS */
38
39namespace web::websocket::server {
40
42 private:
43 using Super = web::websocket::SubProtocol<web::websocket::server::SocketContextUpgrade>;
44
45 protected:
46 SubProtocol(SubProtocolContext* subProtocolContext, const std::string& name, int pingInterval = 0, int maxFlyingPings = 3);
47
48 public:
50
51 /* Facade (API) to WSServerContext -> WSTransmitter to be used from SubProtocol-Subclasses */
52 using Super::sendMessage;
53
54 using Super::sendMessageEnd;
57
58 using Super::sendClose;
59
60 void subscribe(const std::string& group);
61
62 void sendBroadcast(const char* message, std::size_t messageLength, bool excludeSelf = false);
63 void sendBroadcast(const std::string& message, bool excludeSelf = false);
64
65 void sendBroadcastStart(const char* message, std::size_t messageLength, bool excludeSelf = false);
66 void sendBroadcastStart(const std::string& message, bool excludeSelf = false);
67
68 void sendBroadcastFrame(const char* message, std::size_t messageLength, bool excludeSelf = false);
69 void sendBroadcastFrame(const std::string& message, bool excludeSelf = false);
70
71 void sendBroadcastEnd(const char* message, std::size_t messageLength, bool excludeSelf = false);
72 void sendBroadcastEnd(const std::string& message, bool excludeSelf = false);
73
74 void forEachClient(const std::function<void(const SubProtocol*)>& sendToClient, bool excludeSelf = false);
75
76 private:
77 std::string group;
78
79 template <typename RequestT, typename ResponseT, typename SubProtocolT>
80 friend class web::websocket::SocketContextUpgrade;
81
82 friend class GroupsManager;
83 };
84
85} // namespace web::websocket::server
86
87extern template class web::websocket::SubProtocol<web::websocket::server::SocketContextUpgrade>;
88
89#endif // WEB_WEBSOCKET_SERVER_SUBSPROTOCOL_H
Echo(web::websocket::SubProtocolContext *socketContextUpgradeBase, const std::string &name)
Definition Echo.cpp:36
void onMessageError(uint16_t errnum) override
Definition Echo.cpp:69
void onMessageStart(int opCode) override
Definition Echo.cpp:47
void onMessageData(const char *chunk, std::size_t chunkLen) override
Definition Echo.cpp:51
friend class web::websocket::SocketContextUpgrade
Definition SubProtocol.h:57
void forEachClient(const std::function< void(const SubProtocol *)> &sendToClient, bool excludeSelf=false)
void sendBroadcastFrame(const char *message, std::size_t messageLength, bool excludeSelf=false)
void sendBroadcast(const char *message, std::size_t messageLength, bool excludeSelf=false)
void sendBroadcastStart(const char *message, std::size_t messageLength, bool excludeSelf=false)
void sendBroadcastEnd(const char *message, std::size_t messageLength, bool excludeSelf=false)
#define MAX_FLYING_PINGS
Definition Echo.cpp:31
#define PING_INTERVAL
Definition Echo.cpp:32