GNU CommonC++
|
The SocketService is a thread pool object that is meant to service attached socket ports. More...
#include <socketport.h>
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. | |
SocketService (int pri=0, size_t stack=0, const char *id=NULL) | |
Create a service thread for attaching socket ports. | |
virtual | ~SocketService () |
Terminate the thread pool and eliminate any attached socket ports. | |
int | getCount (void) const |
Get current reference count. | |
![]() | |
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. | |
Thread (int pri=0, size_t stack=0) | |
When a thread object is contructed, a new thread of execution context is created. | |
Thread (const Thread &th) | |
A thread of execution can also be specified by cloning an existing thread. | |
virtual | ~Thread () |
The thread destructor should clear up any resources that have been allocated by the thread. | |
int | start (Semaphore *start=0) |
When a new thread is created, it does not begin immediate execution. | |
int | detach (Semaphore *start=0) |
Start a new thread as "detached". | |
Thread * | getParent (void) |
Gets the pointer to the Thread class which created the current thread object. | |
void | suspend (void) |
Suspends execution of the selected thread. | |
void | resume (void) |
Resumes execution of the selected thread. | |
Cancel | getCancel (void) |
Used to retrieve the cancellation mode in effect for the selected thread. | |
bool | isRunning (void) const |
Verifies if the thread is still running or has already been terminated but not yet deleted. | |
bool | isDetached (void) const |
Check if this thread is detached. | |
void | join (void) |
Blocking call which unlocks when thread terminates. | |
bool | isThread (void) const |
Tests to see if the current execution context is the same as the specified thread object. | |
cctid_t | getId (void) const |
Get system thread numeric identifier. | |
const char * | getName (void) const |
Get the name string for this thread, to use in debug messages. | |
Protected Member Functions | |
virtual void | onUpdate (unsigned char buf) |
Handles all requests other than "termination". | |
virtual void | onEvent (void) |
Called once each time the service thread is rescheduled. | |
virtual void | onCallback (SocketPort *port) |
Called for each port that is being processed in response to an event. | |
![]() | |
void | setName (const char *text) |
Set the name of the current thread. | |
virtual void | final (void) |
A thread that is self terminating, either by invoking exit() or leaving it's run(), will have this method called. | |
virtual void | initial (void) |
The initial method is called by a newly created thread when it starts execution. | |
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(). | |
virtual void | notify (Thread *) |
When a thread terminates, it now sends a notification message to the parent thread which created it. | |
void | exit (void) |
Used to properly exit from a Thread derived run() or initial() method. | |
void | sync (void) |
Used to wait for a join or cancel, in place of explicit exit. | |
bool | testCancel (void) |
test a cancellation point for deferred thread cancellation. | |
void | setCancel (Cancel mode) |
Sets thread cancellation mode. | |
void | setSuspend (Suspend mode) |
Sets the thread's ability to be suspended from execution. | |
void | terminate (void) |
Used by another thread to terminate the current thread. | |
void | clrParent (void) |
clear parent thread relationship. | |
Friends | |
class | SocketPort |
Additional Inherited Members | |
![]() | |
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. | |
typedef enum ost::Thread::Cancel | Cancel |
How work cancellation. | |
typedef enum ost::Thread::Suspend | Suspend |
How work suspend. | |
![]() | |
static Thread * | get (void) |
static void | setStack (size_t size=0) |
Set base stack limit before manual stack sizes have effect. | |
static void | sleep (timeout_t msec) |
A thread-safe sleep call. | |
static void | yield (void) |
Yields the current thread's CPU time slice to allow another thread to begin immediate execution. | |
static Throw | getException (void) |
Get exception mode of the current thread. | |
static void | setException (Throw mode) |
Set exception mode of the current thread. | |
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. | |
static void | exitCancel (Cancel cancel) |
This is used to restore a cancel block. | |
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.
Thread pool service object for socket ports.
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.
pri | of this thread to run under. |
stack | stack size. |
id | thread ID. |
|
virtual |
Terminate the thread pool and eliminate any attached socket ports.
|
inline |
Get current reference count.
This can be used when selecting the least used service handler from a pool.
|
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().
port | SocketPort who's callback events are being evaluated. |
References SocketPort.
|
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.
|
protectedvirtual |
Handles all requests other than "termination".
buf | request id as posted from 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.
flag | update flag value. |
|
friend |
References SocketPort.
Referenced by onCallback(), and SocketPort.