#include <SocketEvents.h>
Public Member Functions | |
SocketEvents (const String &name, const SocketEventCallback &eventsCallback, std::chrono::milliseconds timeout=std::chrono::milliseconds(100)) | |
~SocketEvents () override | |
void | add (BaseSocket &socket, uint8_t *userData) |
void | remove (BaseSocket &socket) |
void | stop () |
void | terminate () override |
size_t | size () const |
Public Member Functions inherited from sptk::Thread | |
Thread (const String &name, const std::shared_ptr< ThreadManager > &threadManager=nullptr) | |
virtual | ~Thread () |
virtual void | run () |
bool | running () const |
virtual void | threadFunction ()=0 |
virtual void | terminate () |
virtual void | onThreadExit () |
virtual bool | terminated () |
virtual void | join () |
Id | id () const |
const String & | name () const |
virtual bool | sleep_for (std::chrono::milliseconds interval) |
virtual bool | sleep_until (const DateTime ×tamp) |
Protected Member Functions | |
void | threadFunction () override |
Additional Inherited Members | |
Public Types inherited from sptk::Thread | |
using | Id = std::thread::id |
Socket events manager.
Dynamic collection of sockets that delivers socket events such as data available for read or peer closed connection, to its sockets.
sptk::SocketEvents::SocketEvents | ( | const String & | name, |
const SocketEventCallback & | eventsCallback, | ||
std::chrono::milliseconds | timeout = std::chrono::milliseconds(100) |
||
) |
Constructor
name | Logical name for event manager (also the thread name) |
eventsCallback | Callback function called for socket events |
timeout | Timeout in event monitoring loop |
|
override |
Destructor
void sptk::SocketEvents::add | ( | BaseSocket & | socket, |
uint8_t * | userData | ||
) |
Add socket to collection and start monitoring its events
socket | Socket to monitor |
userData | User data to pass into callback function |
void sptk::SocketEvents::remove | ( | BaseSocket & | socket | ) |
Remove socket from collection and stop monitoring its events
socket | Socket to remove |
size_t sptk::SocketEvents::size | ( | ) | const |
Get the size of socket collection
void sptk::SocketEvents::stop | ( | ) |
Stop socket events manager and wait until it joins.
|
overridevirtual |
Terminate socket events manager and continue.
Reimplemented from sptk::Thread.
|
overrideprotectedvirtual |
Event monitoring thread
Implements sptk::Thread.