GNU CommonC++
Public Member Functions | Protected Member Functions | Friends | List of all members
ost::SocketService Class Reference

The SocketService is a thread pool object that is meant to service attached socket ports. More...

#include <socketport.h>

Inheritance diagram for ost::SocketService:
ost::Thread ost::Mutex

Public Member Functions

void update (unsigned char flag=0xff)
 Notify service thread that a port has been added or removed, or a timer changed, so that a new schedule can be computed for expiring attached ports. More...
 
 SocketService (int pri=0, size_t stack=0, const char *id=NULL)
 Create a service thread for attaching socket ports. More...
 
virtual ~SocketService ()
 Terminate the thread pool and eliminate any attached socket ports. More...
 
int getCount (void) const
 Get current reference count. More...
 
- Public Member Functions inherited from ost::Thread
 Thread (bool isMain)
 This is actually a special constructor that is used to create a thread "object" for the current execution context when that context is not created via an instance of a derived Thread object itself. More...
 
 Thread (int pri=0, size_t stack=0)
 When a thread object is contructed, a new thread of execution context is created. More...
 
 Thread (const Thread &th)
 A thread of execution can also be specified by cloning an existing thread. More...
 
virtual ~Thread ()
 The thread destructor should clear up any resources that have been allocated by the thread. More...
 
int start (Semaphore *start=0)
 When a new thread is created, it does not begin immediate execution. More...
 
int detach (Semaphore *start=0)
 Start a new thread as "detached". More...
 
ThreadgetParent (void)
 Gets the pointer to the Thread class which created the current thread object. More...
 
void suspend (void)
 Suspends execution of the selected thread. More...
 
void resume (void)
 Resumes execution of the selected thread. More...
 
Cancel getCancel (void)
 Used to retrieve the cancellation mode in effect for the selected thread. More...
 
bool isRunning (void) const
 Verifies if the thread is still running or has already been terminated but not yet deleted. More...
 
bool isDetached (void) const
 Check if this thread is detached. More...
 
void join (void)
 Blocking call which unlocks when thread terminates. More...
 
bool isThread (void) const
 Tests to see if the current execution context is the same as the specified thread object. More...
 
cctid_t getId (void) const
 Get system thread numeric identifier. More...
 
const char * getName (void) const
 Get the name string for this thread, to use in debug messages. More...
 

Protected Member Functions

virtual void onUpdate (unsigned char buf)
 Handles all requests other than "termination". More...
 
virtual void onEvent (void)
 Called once each time the service thread is rescheduled. More...
 
virtual void onCallback (SocketPort *port)
 Called for each port that is being processed in response to an event. More...
 
- Protected Member Functions inherited from ost::Thread
void setName (const char *text)
 Set the name of the current thread. More...
 
virtual void final (void)
 A thread that is self terminating, either by invoking exit() or leaving it's run(), will have this method called. More...
 
virtual void initial (void)
 The initial method is called by a newly created thread when it starts execution. More...
 
virtual void * getExtended (void)
 Since getParent() and getThread() only refer to an object of the Thread "base" type, this virtual method can be replaced in a derived class with something that returns data specific to the derived class that can still be accessed through the pointer returned by getParent() and getThread(). More...
 
virtual void notify (Thread *)
 When a thread terminates, it now sends a notification message to the parent thread which created it. More...
 
void exit (void)
 Used to properly exit from a Thread derived run() or initial() method. More...
 
void sync (void)
 Used to wait for a join or cancel, in place of explicit exit. More...
 
bool testCancel (void)
 test a cancellation point for deferred thread cancellation. More...
 
void setCancel (Cancel mode)
 Sets thread cancellation mode. More...
 
void setSuspend (Suspend mode)
 Sets the thread's ability to be suspended from execution. More...
 
void terminate (void)
 Used by another thread to terminate the current thread. More...
 
void clrParent (void)
 clear parent thread relationship. More...
 

Friends

class SocketPort
 

Additional Inherited Members

- Public Types inherited from ost::Thread
enum  Throw { throwNothing, throwObject, throwException }
 How to raise error. More...
 
enum  Cancel {
  cancelInitial =0, cancelDeferred =1, cancelImmediate, cancelDisabled,
  cancelManual, cancelDefault =cancelDeferred
}
 How work cancellation. More...
 
enum  Suspend { suspendEnable, suspendDisable }
 How work suspend. More...
 
typedef enum ost::Thread::Throw Throw
 How to raise error. More...
 
typedef enum ost::Thread::Cancel Cancel
 How work cancellation. More...
 
typedef enum ost::Thread::Suspend Suspend
 How work suspend. More...
 
- Static Public Member Functions inherited from ost::Thread
static Threadget (void)
 
static void setStack (size_t size=0)
 Set base stack limit before manual stack sizes have effect. More...
 
static void sleep (timeout_t msec)
 A thread-safe sleep call. More...
 
static void yield (void)
 Yields the current thread's CPU time slice to allow another thread to begin immediate execution. More...
 
static Throw getException (void)
 Get exception mode of the current thread. More...
 
static void setException (Throw mode)
 Set exception mode of the current thread. More...
 
static Cancel enterCancel (void)
 This is used to help build wrapper functions in libraries around system calls that should behave as cancellation points but don't. More...
 
static void exitCancel (Cancel cancel)
 This is used to restore a cancel block. More...
 

Detailed Description

The SocketService is a thread pool object that is meant to service attached socket ports.

Multiple pool objects may be created and multiple socket ports may be attached to the same thread of execution. This allows one to balance threads and sockets they service rather than either using a single thread for all connections or a seperate thread for each connection. Features can be added through supported virtual methods.

Author
David Sugar dyfet.nosp@m.@ost.nosp@m.el.co.nosp@m.m

Thread pool service object for socket ports.

Examples
tcpservice.cpp.

Constructor & Destructor Documentation

◆ SocketService()

ost::SocketService::SocketService ( int  pri = 0,
size_t  stack = 0,
const char *  id = NULL 
)

Create a service thread for attaching socket ports.

The thread begins execution with the first attached socket.

Parameters
priof this thread to run under.
stackstack size.
idthread ID.

◆ ~SocketService()

virtual ost::SocketService::~SocketService ( )
virtual

Terminate the thread pool and eliminate any attached socket ports.

Member Function Documentation

◆ getCount()

int ost::SocketService::getCount ( void  ) const
inline

Get current reference count.

This can be used when selecting the least used service handler from a pool.

Returns
count of active ports.

◆ onCallback()

virtual void ost::SocketService::onCallback ( SocketPort port)
protectedvirtual

Called for each port that is being processed in response to an event.

This can be used to add additional notification options during callback in combination with update().

Parameters
portSocketPort who's callback events are being evaluated.

◆ onEvent()

virtual void ost::SocketService::onEvent ( void  )
protectedvirtual

Called once each time the service thread is rescheduled.

This is called after the mutex is locked and can be used to slip in additional processing.

◆ onUpdate()

virtual void ost::SocketService::onUpdate ( unsigned char  buf)
protectedvirtual

Handles all requests other than "termination".

Parameters
bufrequest id as posted from update().

◆ update()

void ost::SocketService::update ( unsigned char  flag = 0xff)

Notify service thread that a port has been added or removed, or a timer changed, so that a new schedule can be computed for expiring attached ports.

A "0" is used to terminate the service thread, and additional values can be specified which will be "caught" in the onUpdate() handler.

Parameters
flagupdate flag value.

Friends And Related Function Documentation

◆ SocketPort

friend class SocketPort
friend

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