GNE
0.75.0
|
Internal class used by GNE to manage Connection events. More...
#include <EventThread.h>
Public Types | |
typedef SmartPtr< EventThread > | sptr |
typedef WeakPtr< EventThread > | wptr |
![]() | |
enum | ThreadType { USER, TIMER, SYSTEM, CONNECTION, ALL } |
An enum for specifying the thread type. More... | |
typedef SmartPtr< Thread > | sptr |
typedef WeakPtr< Thread > | wptr |
Public Member Functions | |
SmartPtr< ConnectionListener > | getListener () const |
Use GNE::Connection::getListener. | |
void | setListener (const SmartPtr< ConnectionListener > &listener) |
Use GNE::Connection::setListener. | |
int | getTimeout () const |
Use GNE::Connection::getTimeout. | |
void | setTimeout (int ms) |
Use GNE::Connection::setTimeout. | |
void | onDisconnect () |
For more information about these events, see ConnectionListener. | |
void | onExit () |
For more information about these events, see ConnectionListener. | |
void | onFailure (const Error &error) |
For more information about these events, see ConnectionListener. | |
void | onError (const Error &error) |
For more information about these events, see ConnectionListener. | |
void | onReceive () |
For more information about these events, see ConnectionListener. | |
void | shutDown () |
Overrides Thread::shutDown so that the daemon thread will be woken up since it might be waiting on a ConditionVariable. | |
![]() | |
Thread (std::string name=DEF_NAME, int priority=DEF_PRI) | |
Creates a new thread, ready to run but not yet running. | |
std::string | getName () const |
Returns the name of this thread. | |
void | join () |
A blocking call that returns when this thread terminates, or returns immediately if the thread has terminated. | |
bool | hasStarted () const |
Returns true if this Thread has ever been started. | |
bool | isRunning () const |
Determine the running state of the thread. | |
void | start () |
Starts this thread running. | |
int | getPriority () const |
Returns the priority of this class. |
Static Public Member Functions | |
static sptr | create (const SmartPtr< Connection > &conn) |
Initializes this class as a event thread for a listener. | |
![]() | |
static sptr | currentThread () |
Returns the Thread object that represents this calling thread. | |
static void | sleep (int ms) |
The currently running thread sleeps for the time given in milliseconds. | |
static void | yield () |
Makes a request to the operating system to give up the remainder of this thread's timeslice to another appropriate thread. | |
static bool | waitForAllThreads (int ms) |
This method will wait for all threads that have a type != SYSTEM. | |
static void | requestAllShutdown (ThreadType threadType) |
Calls the shutDown method of all running threads of the given type. |
Protected Member Functions | |
EventThread (const SmartPtr< Connection > &conn) | |
void | run () |
This thread serializes events for a Connection. | |
![]() | |
void | setThisPointer (const wptr &thisPtr) |
IMPORTANT: call this method in your static create function. | |
sptr | getThisPointer () const |
Returns a SmartPtr to this object. | |
void | setType (ThreadType newType) |
Sets this Thread's type. |
Additional Inherited Members | |
![]() | |
static const int | DEF_PRI = 0 |
The default priority of a thread. | |
static const std::string | DEF_NAME = "Thread" |
The default name for a thread. | |
static const int | LOW_PRI = -1 |
A lowered priority for a thread. | |
static const int | LOWER_PRI = -2 |
A lower priority for a thread than LOW_PRI. | |
static const int | HIGH_PRI = 1 |
A "boosted priority" for a thread. | |
static const int | HIGHER_PRI = 2 |
Even higher priority thread than HIGH_PRI. | |
![]() | |
volatile bool | shutdown |
This variable is set to true when this thread should exit. |
Internal class used by GNE to manage Connection events.
Each Connection has an EventThread. This is used internally by the Connection class to act as a proxy to dispatch events to the ConnectionListener. Because of this, only one event per Connection will be active at any one time. Another appropriate name that might describe this would be an EventQueue. But to improve efficency and stability, some events may be reordered or combined. Remember that onReceive means 1 or more packets have been received. If multiple onReceive or onDoneWriting occur, they will probably be combined. Error events will always have first priority, and if the error leads to a disconnect, pending events after that will not be called (except for onDisconnect).
EventThread was created to solve several things:
|
protected |
|
static |
Initializes this class as a event thread for a listener.
The conn pointer is used to call disconnect when an onFailure event is finally processed. This is to assure that disconnect is called from a safe thread that won't lead to deadlock when a failure occurs.
The SmartPtr also keeps the Connection alive if it is still active.
void GNE::EventThread::onDisconnect | ( | ) |
For more information about these events, see ConnectionListener.
The processing of an onDisconnect event will be the last, and the thread will essentially stop when onDisconnect completes.
|
virtual |
Overrides Thread::shutDown so that the daemon thread will be woken up since it might be waiting on a ConditionVariable.
Once it shuts down it should not be activated again.
Reimplemented from GNE::Thread.