GNE 0.75.0
GNE::ServerConnection Class Reference

A GNE "internal" class. More...

#include <ServerConnection.h>

Inheritance diagram for GNE::ServerConnection:
GNE::Connection GNE::Thread

List of all members.

Public Types

typedef SmartPtr
< ServerConnection
sptr
typedef WeakPtr< ServerConnectionwptr

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 ()
 This thread performs the connection process.
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 >

Detailed Description

A GNE "internal" class.

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.

The fact that a ServerConnection is a Thread is an implementation detail and should not be used outside of this class's implementation. Originally it was private, but this presented a compatibility issue with Boost 1.36. Long-term, the Thread will be encapsulated as a private object, rather than inheritance abuse.


Constructor & Destructor Documentation

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.


Member Function Documentation

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.

Parameters:
rsocket2the reliable socket received from the accept command.
creatorthe 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.
See also:
ServerConnectionListener
void GNE::ServerConnection::run ( ) [protected, virtual]

This thread performs the connection process.

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.

Todo:
better test GNE shutting down while connection is being made.
Bug:
The PacketFeeder is set after onNewConn, so it is possible that if the user sets a different PacketFeeder right after connecting, it might "get lost" and if set during onNewConn, is definitely lost. I do provide a check do this is only a problem if a feeder is set in the ConnectionParams AND in onNewConn.

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.


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