#include <ServerConnection.h>
Inheritance diagram for GNE::ServerConnection:
Public Types | |
typedef SmartPtr< ServerConnection > | sptr |
typedef WeakPtr< ServerConnection > | wptr |
Public Member Functions | |
virtual | ~ServerConnection () |
Destructs this ServerConnection object. | |
Static Public Member Functions | |
static sptr | create (const ConnectionParams &p, NLsocket rsocket, const SmartPtr< ServerConnectionListener > &creator) |
Intializes this class. | |
Protected Member Functions | |
ServerConnection () | |
We need information gained from setThisPointer to initialize, so the real work is done in the init method, which should be called right after constructon and setThisPointer has been called. | |
void | init (const ConnectionParams &p, NLsocket rsocket, const SmartPtr< ServerConnectionListener > &creator) |
void | run () |
void | shutDown () |
Makes a request that this thread should shutdown. | |
Friends | |
class | boost::weak_ptr< Thread > |
class | boost::shared_ptr< Thread > |
class | boost::weak_ptr< Connection > |
class | boost::shared_ptr< Connection > |
Users will use this class, but probably only as its base class -- a Connection. This class is created by ServerConnectionListener when incoming connections are comming in.
GNE::ServerConnection::~ServerConnection | ( | ) | [virtual] |
Destructs this ServerConnection object.
The user need not worry about the fact that ServerConnection is a thread (in the sense that the user never need to call detach or join), to do a proper cleanup.
ServerConnection::sptr GNE::ServerConnection::create | ( | const ConnectionParams & | p, | |
NLsocket | rsocket, | |||
const SmartPtr< ServerConnectionListener > & | creator | |||
) | [static] |
Intializes this class.
Note that you won't create a ServerConnection directly. The ServerConnectionListener does that for you.
rsocket2 | the reliable socket received from the accept command. | |
creator | the ServerConnectionListener that created us, so that we may call its onListenFailure event. This strong pointer will be released after the connection finished, as to not worry about cycles. |
void GNE::ServerConnection::run | ( | ) | [protected, virtual] |
If an error occurs:
Before onNewConn: ServerConnectionListener::onListenFailure() is called.
During onNewConn: Only onNewConn is called and is reponsible for catching the exception and cleaning up anything it has done. onDisconnect will NOT be called, but onListenFailure will be.
After onNewConn: onFailure then onDisconnect.
After onNewConn is called successfully, then ServerConnectionListener::onListenSuccess is called.
Implements GNE::Thread.
void GNE::ServerConnection::shutDown | ( | ) | [protected, virtual] |
Makes a request that this thread should shutdown.
Tells this thread to shutdown, if it is in an infinite loop. You will probably want to call join right after calling this to wait for the shutdown to complete which is dependent on the thread you are shutting down.
This function is virtual if the thread needs any additional actions to notify itself to shutdown, for example if it is waiting for some event on a ConditionVariable.
You will want to call this function from the override to make sure that shutdown is set to true.
This function is safe to call multiple times, but you cannot undo a shutdown once it has been called.
Reimplemented from GNE::Thread.