Public Types

using Observer = std::function< void(std::vector< uint8_t > &, bool)>
 
using ObserverUriCheck = std::function< bool(const std::string &, const std::vector< std::string > &)>
 

Public Member Functions

const std::chrono::steady_clock::time_point & getLastTimeReceive ()
 
const std::chrono::steady_clock::time_point & getLastTimeSend ()
 
 WebSocket (enet::Tcp _connection, bool _isServer=false)
 
void setInterface (enet::Tcp _connection, bool _isServer=false)
 
void start (const std::string &_uri="", const std::vector< std::string > &_listProtocols=std::vector< std::string >())
 
void stop (bool _inThread=false)
 
bool isAlive () const
 
void onReceiveData (enet::Tcp &_data)
 
void onReceiveRequest (const enet::HttpRequest &_data)
 
void onReceiveAnswer (const enet::HttpAnswer &_data)
 
void setProtocol (const std::string &_protocol)
 
template<class CLASS_TYPE >
void connect (CLASS_TYPE *_class, void(CLASS_TYPE::*_func)(std::vector< uint8_t > &, bool))
 
void connect (Observer _func)
 
template<class CLASS_TYPE >
void connectUri (CLASS_TYPE *_class, bool(CLASS_TYPE::*_func)(const std::string &, const std::vector< std::string > &))
 
void connectUri (ObserverUriCheck _func)
 
bool configHeader (bool _isString=false, bool _mask=false)
 
int32_t writeData (uint8_t *_data, int32_t _len)
 
int32_t send ()
 
int32_t write (const void *_data, int32_t _len, bool _isString=false, bool _mask=false)
 
int32_t write (const std::string &_data, bool _writeBackSlashZero=true)
 
template<class T >
int32_t write (const std::vector< T > &_data)
 
void controlPing ()
 
void controlPong ()
 
void controlClose ()
 

Protected Attributes

std::vector< uint8_t > m_sendBuffer
 
bool m_connectionValidate
 
ememory::SharedPtr< enet::Httpm_interface
 
std::vector< uint8_t > m_buffer
 
std::string m_checkKey
 
std::chrono::steady_clock::time_point m_lastReceive
 
std::chrono::steady_clock::time_point m_lastSend
 
std::string m_protocol
 
Observer m_observer
 
ObserverUriCheck m_observerUriCheck
 

Member Typedef Documentation

§ Observer

using enet::WebSocket::Observer = std::function<void(std::vector<uint8_t>&, bool)>

Define an Observer: function pointer.

§ ObserverUriCheck

using enet::WebSocket::ObserverUriCheck = std::function<bool(const std::string&, const std::vector<std::string>&)>

Define an Observer: function pointer.

Member Function Documentation

§ connect()

template<class CLASS_TYPE >
void enet::WebSocket::connect ( CLASS_TYPE *  _class,
void(CLASS_TYPE::*)(std::vector< uint8_t > &, bool)  _func 
)
inline

Connect an function member on the signal with the shared_ptr object.

Parameters
[in]_classshared_ptr Object on whe we need to call ==> the object is get in keeped in weak_ptr.
[in]_funcFunction to call.
[in]_argsArgument optinnal the user want to add.

§ connectUri()

template<class CLASS_TYPE >
void enet::WebSocket::connectUri ( CLASS_TYPE *  _class,
bool(CLASS_TYPE::*)(const std::string &, const std::vector< std::string > &)  _func 
)
inline

Connect an function member on the signal with the shared_ptr object.

Parameters
[in]_classshared_ptr Object on whe we need to call ==> the object is get in keeped in weak_ptr.
[in]_funcFunction to call.
[in]_argsArgument optinnal the user want to add.

§ write() [1/3]

int32_t enet::WebSocket::write ( const void *  _data,
int32_t  _len,
bool  _isString = false,
bool  _mask = false 
)

Write a chunk of data on the socket.

Parameters
[in]_datapointer on the data might be write
[in]_lenSize that must be written socket
Returns
>0 byte size on the socket write
-1 an error occured.

§ write() [2/3]

int32_t enet::WebSocket::write ( const std::string &  _data,
bool  _writeBackSlashZero = true 
)
inline

Write a chunk of data on the socket.

Parameters
[in]_dataString to rite on the soccket
[in]_writeBackSlashZeroif false, the \0 is not write
Returns
>0 byte size on the socket write
-1 an error occured.

§ write() [3/3]

template<class T >
int32_t enet::WebSocket::write ( const std::vector< T > &  _data)
inline

Write a chunk of data on the socket.

Parameters
[in]_dataString to rite on the soccket
[in]_writeBackSlashZeroif false, the \0 is not write
Returns
>0 T element write on the socket
-1 an error occured.

The documentation for this class was generated from the following file: