#include <EventThread.h>
Inheritance diagram for GNE::EventThread:
Public Types | |
typedef SmartPtr< EventThread > | sptr |
typedef WeakPtr< EventThread > | 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. | |
Static Public Member Functions | |
sptr | create (const SmartPtr< Connection > &conn) |
Initializes this class as a event thread for a listener. | |
Protected Member Functions | |
EventThread (const SmartPtr< Connection > &conn) | |
void | run () |
This thread serializes events for a Connection. |
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:
|
|
|
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. |
|
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. |
|
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. |