sptk2 logo
SPTK Home Page
Public Member Functions | Protected Member Functions | List of all members
sptk::SocketEvents Class Reference

#include <SocketEvents.h>

Inheritance diagram for sptk::SocketEvents:
sptk::Thread

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 Stringname () const
 
virtual bool sleep_for (std::chrono::milliseconds interval)
 
virtual bool sleep_until (const DateTime &timestamp)
 

Protected Member Functions

void threadFunction () override
 

Additional Inherited Members

- Public Types inherited from sptk::Thread
using Id = std::thread::id
 

Detailed Description

Socket events manager.

Dynamic collection of sockets that delivers socket events such as data available for read or peer closed connection, to its sockets.

Constructor & Destructor Documentation

◆ SocketEvents()

sptk::SocketEvents::SocketEvents ( const String name,
const SocketEventCallback &  eventsCallback,
std::chrono::milliseconds  timeout = std::chrono::milliseconds(100) 
)

Constructor

Parameters
nameLogical name for event manager (also the thread name)
eventsCallbackCallback function called for socket events
timeoutTimeout in event monitoring loop

◆ ~SocketEvents()

sptk::SocketEvents::~SocketEvents ( )
override

Destructor

Member Function Documentation

◆ add()

void sptk::SocketEvents::add ( BaseSocket socket,
uint8_t *  userData 
)

Add socket to collection and start monitoring its events

Parameters
socketSocket to monitor
userDataUser data to pass into callback function

◆ remove()

void sptk::SocketEvents::remove ( BaseSocket socket)

Remove socket from collection and stop monitoring its events

Parameters
socketSocket to remove

◆ size()

size_t sptk::SocketEvents::size ( ) const

Get the size of socket collection

Returns
number of sockets being watched

◆ stop()

void sptk::SocketEvents::stop ( )

Stop socket events manager and wait until it joins.

◆ terminate()

void sptk::SocketEvents::terminate ( )
overridevirtual

Terminate socket events manager and continue.

Reimplemented from sptk::Thread.

◆ threadFunction()

void sptk::SocketEvents::threadFunction ( )
overrideprotectedvirtual

Event monitoring thread

Implements sptk::Thread.


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

Fri Oct 14 2022 09:58:45: SPTK 5.4.1