REDAC HybridController
Firmware for LUCIDAC/REDAC Teensy
Loading...
Searching...
No Matches
endpoint.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef ARDUINO
4
5#include "websockets/common.h"
8#include "websockets/tcp.h"
9
10#include <memory>
11
12#define __TINY_WS_INTERNAL_DEFAULT_MASK "\00\00\00\00"
13
14namespace websockets {
16
30
31CloseReason GetCloseReason(uint16_t reasonCode);
32
33namespace internals {
34
36public:
37 WebsocketsEndpoint(std::shared_ptr<network::TcpClient> socket,
39
42
45
46 void setInternalSocket(std::shared_ptr<network::TcpClient> socket);
47
48 bool poll();
50 bool send(const char *data, const size_t len, const uint8_t opcode, const bool fin, const bool mask,
51 const char *maskingKey = __TINY_WS_INTERNAL_DEFAULT_MASK);
52 bool send(const std::string &data, const uint8_t opcode, const bool fin, const bool mask,
53 const char *maskingKey = __TINY_WS_INTERNAL_DEFAULT_MASK);
54
55 bool send(const char *data, const size_t len, const uint8_t opcode, const bool fin);
56 bool send(const std::string &data, const uint8_t opcode, const bool fin);
57
58 bool ping(const std::string &msg);
59 bool ping(const std::string &&msg);
60
61 bool pong(const std::string &msg);
62 bool pong(const std::string &&msg);
63
64 void close(const CloseReason reason = CloseReason_NormalClosure);
66
67 void setFragmentsPolicy(const FragmentsPolicy newPolicy);
69
70 void setUseMasking(bool useMasking) { _useMasking = useMasking; }
71
72 virtual ~WebsocketsEndpoint();
73
74private:
75 std::shared_ptr<network::TcpClient> _client;
76 FragmentsPolicy _fragmentsPolicy;
77
78 enum RecvMode { RecvMode_Normal, RecvMode_Streaming } _recvMode;
79
81 CloseReason _closeReason;
82 bool _useMasking = true;
83
84 WebsocketsFrame _recv();
85 void handleMessageInternally(WebsocketsMessage &msg);
86
87 WebsocketsMessage handleFrameInStreamingMode(WebsocketsFrame &frame);
88 WebsocketsMessage handleFrameInStandardMode(WebsocketsFrame &frame);
89
90 std::string getHeader(uint64_t len, uint8_t opcode, bool fin, bool mask);
91};
92} // namespace internals
93} // namespace websockets
94
95#endif // ARDUINO
bool ping(const std::string &msg)
Definition endpoint.cpp:432
FragmentsPolicy getFragmentsPolicy() const
Definition endpoint.cpp:470
void setUseMasking(bool useMasking)
Definition endpoint.h:70
bool send(const char *data, const size_t len, const uint8_t opcode, const bool fin, const bool mask, const char *maskingKey="\00\00\00\00")
Definition endpoint.cpp:387
void close(const CloseReason reason=CloseReason_NormalClosure)
Definition endpoint.cpp:413
void setFragmentsPolicy(const FragmentsPolicy newPolicy)
Definition endpoint.cpp:468
bool pong(const std::string &msg)
Definition endpoint.cpp:450
WebsocketsEndpoint & operator=(const WebsocketsEndpoint &other)
Definition endpoint.cpp:95
WebsocketsEndpoint(std::shared_ptr< network::TcpClient > socket, FragmentsPolicy fragmentsPolicy=FragmentsPolicy_Aggregate)
Definition endpoint.cpp:72
void setInternalSocket(std::shared_ptr< network::TcpClient > socket)
Definition endpoint.cpp:123
#define __TINY_WS_INTERNAL_DEFAULT_MASK
Definition endpoint.h:12
Definition carrier.h:12
@ FragmentsPolicy_Aggregate
Definition endpoint.h:15
@ FragmentsPolicy_Notify
Definition endpoint.h:15
@ CloseReason_PolicyViolation
Definition endpoint.h:26
@ CloseReason_None
Definition endpoint.h:18
@ CloseReason_NoStatusRcvd
Definition endpoint.h:23
@ CloseReason_InvalidPayloadData
Definition endpoint.h:25
@ CloseReason_MessageTooBig
Definition endpoint.h:27
@ CloseReason_GoingAway
Definition endpoint.h:20
@ CloseReason_UnsupportedData
Definition endpoint.h:22
@ CloseReason_NormalClosure
Definition endpoint.h:19
@ CloseReason_ProtocolError
Definition endpoint.h:21
@ CloseReason_InternalServerError
Definition endpoint.h:28
@ CloseReason_AbnormalClosure
Definition endpoint.h:24
FLASHMEM CloseReason GetCloseReason(uint16_t reasonCode)
Definition endpoint.cpp:10