Ocean
Ocean::Network::SocketScheduler Class Reference

This class implements a high performance scheduler for socket events. More...

Inheritance diagram for Ocean::Network::SocketScheduler:

Protected Types

typedef std::unordered_set< Socket * > SocketSet
 Definition of a set holding socket pointers. More...
 
- Protected Types inherited from Ocean::Thread
typedef std::pair< pthread_t, bool > TimedJoinPair
 Definition of a pair holding a thread id and a boolean state. More...
 
enum  ThreadPriority {
  PRIORITY_IDLE , PRIORTY_BELOW_NORMAL , PRIORTY_NORMAL , PRIORTY_ABOVE_NORMAL ,
  PRIORTY_HIGH , PRIORTY_REALTIME
}
 Definition of different thread priority values. More...
 

Protected Member Functions

 SocketScheduler ()
 Creates a new scheduler object. More...
 
 ~SocketScheduler () override
 Destructs a scheduler object. More...
 
void registerSocket (Socket &socket)
 Register socket. More...
 
void unregisterSocket (Socket &socket)
 Unregister socket. More...
 
bool isSocketUnregistered (Socket &socket) const
 Checks whether a specific socket has been unregistered successfully. More...
 
void threadRun () override
 The internal run function. More...
 
- Protected Member Functions inherited from Ocean::Singleton< SocketScheduler >
 Singleton ()=default
 Default constructor. More...
 
- Protected Member Functions inherited from Ocean::Thread
 Thread (const Thread &thread)=delete
 Disabled copy constructor. More...
 
void createThread ()
 Creates the thread itself. More...
 
void destroyThread ()
 Destroys the thread itself. More...
 
void stopThreadExplicitly (const unsigned int timeout=5000u)
 Tries to stop the thread gracefully. More...
 
Threadoperator= (const Thread &thread)=delete
 The disabled assign operator. More...
 
 Thread (const std::string &name=std::string())
 Creates a new thread object. More...
 
 Thread (const unsigned int randomNumberSeedValue, const std::string &name=std::string())
 Creates a new thread object. More...
 
virtual ~Thread ()
 Destructs a thread object. More...
 
bool startThread ()
 Starts the thread. More...
 
void stopThread ()
 Informs the thread to stop. More...
 
bool terminateThread ()
 Terminates the thread. More...
 
bool joinThread (const unsigned int timeout=(unsigned int)(-1))
 Waits until this thread has been stopped. More...
 
bool shouldThreadStop () const
 Returns whether this thread should stop. More...
 
bool isThreadInvokedToStart () const
 Returns whether this thread has been invoked to start immediately. More...
 
bool isThreadActive () const
 Returns whether this thread is active. More...
 

Protected Attributes

SocketSet activeSockets_
 The active sockets of this scheduler. More...
 
SocketSet registerSockets_
 The set of sockets which are requested to be registered. More...
 
SocketSet unregisterSockets_
 The set of sockets which are requested to be unregistered. More...
 
Lock lock_
 The lock of this scheduler. More...
 

Friends

class Socket
 
class Singleton< SocketScheduler >
 

Additional Inherited Members

- Static Public Member Functions inherited from Ocean::Singleton< SocketScheduler >
static SocketScheduler & get ()
 Returns a reference to the unique object. More...
 
- Static Protected Member Functions inherited from Ocean::Thread
static void sleep (unsigned int ms)
 Sleeps the calling thread for a given time. More...
 
static void giveUp ()
 Gives up the remaining thread time. More...
 
static ThreadId currentThreadId ()
 Returns the thread id of the current (calling) thread. More...
 
static ThreadPriority threadPriority ()
 Returns the priority of the current thread. More...
 
static bool setThreadPriority (const ThreadPriority priority)
 Sets the priority of the current thread. More...
 
template<typename TObject , typename TExpectedValue >
static bool waitForValue (TObject &object, const TExpectedValue &expectedValue, const double timeout=-1.0)
 Waits until an object/variable has an expected value. More...
 
template<typename TObject , typename TExpectedValue >
static bool waitForValue (TObject &object, const TExpectedValue &expectedValue, TemporaryScopedLock &temporaryScopedLock, const double timeout=-1.0)
 Waits until an object/variable has an expected value. More...
 
static int pthread_timedjoin_np (pthread_t thread, void **retval, const struct timespec *abstime)
 Implements a thread join function with timeout value. More...
 

Detailed Description

This class implements a high performance scheduler for socket events.

Member Typedef Documentation

◆ SocketSet

typedef std::unordered_set<Socket*> Ocean::Network::SocketScheduler::SocketSet
protected

Definition of a set holding socket pointers.

Constructor & Destructor Documentation

◆ SocketScheduler()

Ocean::Network::SocketScheduler::SocketScheduler ( )
protected

Creates a new scheduler object.

◆ ~SocketScheduler()

Ocean::Network::SocketScheduler::~SocketScheduler ( )
overrideprotected

Destructs a scheduler object.

Member Function Documentation

◆ isSocketUnregistered()

bool Ocean::Network::SocketScheduler::isSocketUnregistered ( Socket socket) const
protected

Checks whether a specific socket has been unregistered successfully.

Parameters
socketThe socket which is checked
Returns
True, if the socket has been unregistered successfully

◆ registerSocket()

void Ocean::Network::SocketScheduler::registerSocket ( Socket socket)
protected

Register socket.

Parameters
socketThe socket to be registered

◆ threadRun()

void Ocean::Network::SocketScheduler::threadRun ( )
overrideprotectedvirtual

The internal run function.

Implements Ocean::Thread.

◆ unregisterSocket()

void Ocean::Network::SocketScheduler::unregisterSocket ( Socket socket)
protected

Unregister socket.

Beware: The unregister process is not completed immediately!

Parameters
socketThe socket to be unregistered

Friends And Related Function Documentation

◆ Singleton< SocketScheduler >

friend class Singleton< SocketScheduler >
friend

◆ Socket

friend class Socket
friend

Field Documentation

◆ activeSockets_

SocketSet Ocean::Network::SocketScheduler::activeSockets_
protected

The active sockets of this scheduler.

◆ lock_

Lock Ocean::Network::SocketScheduler::lock_
mutableprotected

The lock of this scheduler.

◆ registerSockets_

SocketSet Ocean::Network::SocketScheduler::registerSockets_
protected

The set of sockets which are requested to be registered.

◆ unregisterSockets_

SocketSet Ocean::Network::SocketScheduler::unregisterSockets_
protected

The set of sockets which are requested to be unregistered.


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