SNode.C
Loading...
Searching...
No Matches
SubProtocolContext.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_SOCKETCONTEXTUPGRADEBASE_H
21#define WEB_WEBSOCKET_SOCKETCONTEXTUPGRADEBASE_H
22
23#include "web/websocket/Receiver.h"
24#include "web/websocket/Transmitter.h"
25
26namespace core::socket::stream {
27 class SocketConnection;
28}
29
30#ifndef DOXYGEN_SHOULD_SKIP_THIS
31
32#include <cstddef>
33#include <cstdint>
34
35#endif // DOXYGEN_SHOULD_SKIP_THIS
36
37namespace web::websocket {
38
40 : protected Receiver
41 , protected Transmitter {
42 public:
43 SubProtocolContext(core::socket::stream::SocketConnection* socketConnection, bool role);
45
46 ~SubProtocolContext() override;
47
49
50 virtual void sendMessage(uint8_t opCode, const char* message, std::size_t messageLength) = 0;
51 virtual void sendMessageStart(uint8_t opCode, const char* message, std::size_t messageLength) = 0;
52
53 virtual void sendMessageFrame(const char* message, std::size_t messageLength) = 0;
54 virtual void sendMessageEnd(const char* message, std::size_t messageLength) = 0;
55 virtual void sendPing(const char* reason = nullptr, std::size_t reasonLength = 0) = 0;
56 virtual void sendPong(const char* reason = nullptr, std::size_t reasonLength = 0) = 0;
57 virtual void sendClose(uint16_t statusCode = 1000, const char* reason = nullptr, std::size_t reasonLength = 0) = 0;
58
59 virtual core::socket::stream::SocketConnection* getSocketConnection() = 0;
60
61 enum OpCode { CONTINUATION = 0x00, TEXT = 0x01, BINARY = 0x02, CLOSE = 0x08, PING = 0x09, PONG = 0x0A };
62
63 private:
64 virtual void sendClose(const char* message, std::size_t messageLength) = 0;
65 };
66
67} // namespace web::websocket
68
69#endif // WEB_WEBSOCKET_SOCKETCONTEXTUPGRADEBASE_H
void sendClose(uint16_t statusCode=1000, const char *reason=nullptr, std::size_t reasonLength=0) override
void sendPing(const char *reason=nullptr, std::size_t reasonLength=0) override
~SocketContextUpgrade() override=default
void onMessageData(const char *chunk, uint64_t chunkLen) override
SocketContextUpgrade(const SocketContextUpgrade &)=delete
SocketContextUpgrade & operator=(const SocketContextUpgrade &)=delete
void sendMessage(uint8_t opCode, const char *message, std::size_t messageLength) override
void sendClose(const char *message, std::size_t messageLength) override
void sendMessageFrame(const char *message, std::size_t messageLength) override
void sendMessageEnd(const char *message, std::size_t messageLength) override
SocketContextUpgrade(core::socket::stream::SocketConnection *socketConnection, web::http::SocketContextUpgradeFactory< Request, Response > *socketContextUpgradeFactory, Role role)
void sendPong(const char *reason=nullptr, std::size_t reasonLength=0) override
void sendMessageStart(uint8_t opCode, const char *message, std::size_t messageLength) override
core::socket::stream::SocketConnection * getSocketConnection() override
void onMessageError(uint16_t errnum) override
virtual void sendMessage(uint8_t opCode, const char *message, std::size_t messageLength)=0
virtual void sendPing(const char *reason=nullptr, std::size_t reasonLength=0)=0
virtual void sendMessageFrame(const char *message, std::size_t messageLength)=0
SubProtocolContext & operator=(const SubProtocolContext &)=delete
virtual void sendPong(const char *reason=nullptr, std::size_t reasonLength=0)=0
virtual void sendClose(const char *message, std::size_t messageLength)=0
SubProtocolContext(core::socket::stream::SocketConnection *socketConnection, bool role)
virtual void sendMessageEnd(const char *message, std::size_t messageLength)=0
virtual void sendClose(uint16_t statusCode=1000, const char *reason=nullptr, std::size_t reasonLength=0)=0
virtual void sendMessageStart(uint8_t opCode, const char *message, std::size_t messageLength)=0
virtual core::socket::stream::SocketConnection * getSocketConnection()=0
SubProtocolContext(const SubProtocolContext &)=delete
web::websocket::SubProtocolFactory< SubProtocol > * subProtocolFactory
std::string loadSubProtocol(const std::string &subProtocolName)
SocketContextUpgrade(core::socket::stream::SocketConnection *socketConnection, web::http::SocketContextUpgradeFactory< web::http::client::Request, web::http::client::Response > *socketContextUpgradeFactory)