16 std::vector<uint8_t> m_sendBuffer;
17 bool m_connectionValidate;
19 std::vector<uint8_t> m_buffer;
20 std::string m_checkKey;
21 std::chrono::steady_clock::time_point m_lastReceive;
22 std::chrono::steady_clock::time_point m_lastSend;
24 const std::chrono::steady_clock::time_point& getLastTimeReceive() {
27 const std::chrono::steady_clock::time_point& getLastTimeSend() {
33 void setInterface(
enet::Tcp _connection,
bool _isServer=
false);
35 void start(
const std::string& _uri=
"",
const std::vector<std::string>& _listProtocols=std::vector<std::string>());
36 void stop(
bool _inThread=
false);
37 bool isAlive()
const {
38 if (m_interface ==
nullptr) {
41 return m_interface->isAlive();
47 std::string m_protocol;
49 void setProtocol(
const std::string& _protocol) {
50 m_protocol = _protocol;
53 using Observer = std::function<void(std::vector<uint8_t>&, bool)>;
63 template<
class CLASS_TYPE>
64 void connect(CLASS_TYPE* _class,
void (CLASS_TYPE::*_func)(std::vector<uint8_t>&,
bool)) {
65 m_observer = [=](std::vector<uint8_t>& _value,
bool _isString){
66 (*_class.*_func)(_value, _isString);
74 using ObserverUriCheck = std::function<bool(const std::string&, const std::vector<std::string>&)>;
84 template<
class CLASS_TYPE>
85 void connectUri(CLASS_TYPE* _class,
bool (CLASS_TYPE::*_func)(
const std::string&,
const std::vector<std::string>&)) {
86 m_observerUriCheck = [=](
const std::string& _value,
const std::vector<std::string>& _protocols){
87 return (*_class.*_func)(_value, _protocols);
91 m_observerUriCheck = _func;
96 uint8_t m_dataMask[4];
98 bool configHeader(
bool _isString=
false,
bool _mask=
false);
99 int32_t writeData(uint8_t* _data, int32_t _len);
109 int32_t
write(
const void* _data, int32_t _len,
bool _isString=
false,
bool _mask=
false);
117 int32_t
write(
const std::string& _data,
bool _writeBackSlashZero =
true) {
118 if (_data.size() == 0) {
121 if (_writeBackSlashZero ==
true) {
122 return write(_data.c_str(), _data.size()+1,
true);
124 return write(_data.c_str(), _data.size(),
true);
134 int32_t
write(
const std::vector<T>& _data) {
135 if (_data.size() == 0) {
138 size_t ret =
write(&_data[0], _data.size()*
sizeof(T));
142 return ret/
sizeof(T);
int32_t write(const std::string &_data, bool _writeBackSlashZero=true)
Write a chunk of data on the socket.
Definition: WebSocket.hpp:117
std::function< bool(const std::string &, const std::vector< std::string > &)> ObserverUriCheck
Define an Observer: function pointer.
Definition: WebSocket.hpp:74
std::function< void(std::vector< uint8_t > &, bool)> Observer
Define an Observer: function pointer.
Definition: WebSocket.hpp:53
void connectUri(CLASS_TYPE *_class, bool(CLASS_TYPE::*_func)(const std::string &, const std::vector< std::string > &))
Connect an function member on the signal with the shared_ptr object.
Definition: WebSocket.hpp:85
int32_t write(const std::vector< T > &_data)
Write a chunk of data on the socket.
Definition: WebSocket.hpp:134
Definition: WebSocket.hpp:14
void connect(CLASS_TYPE *_class, void(CLASS_TYPE::*_func)(std::vector< uint8_t > &, bool))
Connect an function member on the signal with the shared_ptr object.
Definition: WebSocket.hpp:64
int32_t write(const void *_data, int32_t _len, bool _isString=false, bool _mask=false)
Write a chunk of data on the socket.
Main esvg namespace.
Definition: enet.hpp:17