SendReceiveThread Class Reference

#include <SendReceiveThread.h>

Collaboration diagram for SendReceiveThread:

List of all members.


Public Member Functions

 SendReceiveThread ()
void kill ()
void dump ()

Static Public Member Functions

static void run (void *dummy)
static void cleanup ()

Protected Member Functions

int createLocalCopy (SocketListEntry **asArray)
void handlePrioritizedMsgs (SocketListEntry *connections, int entries)
void adjustNextMsgPointers (SocketListEntry *connections, int entries)
int findIndexOfMsg (NetMessage *msg)
void receiveMessage (NetMessage *msg, SocketListEntry *recvdBy)
void decreaseReferenceCounter (SendListEntry *sendListEntry, int idxInSendList, NetworkIdentification connectionCausedDec)
void updateSendListTCP (SocketListEntry *connections, int entries)
void updateSendListUDP (SendListEntry *&nextUDPMsg, int connections)
void checkForPrioritizedMessages (SocketListEntry *socketListCopy, int entries)
void initializeSocketSelection (OSG::SocketSelection &sel, SendListEntry *nextUDPMsg, SocketListEntry *socketListCopy, int entries)
void sendUDPMessage (SendListEntry *&nextUDPMsg, SocketListEntry *socketListCopy, int entries)
void receiveUDPMessage ()
void handleConnectionRequestPrioritizedMsg (SocketListEntry *connections, int entries)
void respondToConnectionRequest (NetMessage *msg, SocketListEntry *recvdBy)
void respondToConnectionRequestDone (NetMessage *msg, SocketListEntry *recvdBy)
void killedSocket (SocketListEntry *connections, int entries, int idx)
SendListEntryfindNextMessageForMe (SocketListEntry *connection, int startIdx)

Protected Attributes

volatile bool shutdown

Static Protected Attributes

static NetworkinternalNetwork = NULL

Friends

class Network

Constructor & Destructor Documentation

OSG_USING_NAMESPACE SendReceiveThread::SendReceiveThread (  ) 


Member Function Documentation

void SendReceiveThread::adjustNextMsgPointers ( SocketListEntry connections,
int  entries 
) [protected]

Here the nextMsg members of the internalNetwork->socketList are updated. We don't use nextMsg members anywhere else but now we have it already and using this method makes the behaviour of the localCopy more intuitive. Assumes socketListLock is hold.

void SendReceiveThread::checkForPrioritizedMessages ( SocketListEntry socketListCopy,
int  entries 
) [protected]

static void SendReceiveThread::cleanup (  )  [static]

Todo:
2009-02-06 ZaJ: I guess this method hasn't been implemented.

int SendReceiveThread::createLocalCopy ( SocketListEntry **  asArray  )  [protected]

This method creates a copy of Networks socketList. In addition it removes dead sockets from it. Assumes socketListLock is hold

void SendReceiveThread::decreaseReferenceCounter ( SendListEntry sendListEntry,
int  idxInSendList,
NetworkIdentification  connectionCausedDec 
) [protected]

This method manages decreasing of the reference counters of a SendListEntry and also releases its resources if necessary.

void SendReceiveThread::dump (  ) 

Todo:
2009-02-06 ZaJ: I guess this method hasn't been implemented.

int SendReceiveThread::findIndexOfMsg ( NetMessage msg  )  [protected]

this method searches the sendListTCP for a specific message and returns it index on success and -1 otherwise. this method should also work in case multiple instances of the same message (pointers) are in the queue which is impossible with the current implementation

SendListEntry * SendReceiveThread::findNextMessageForMe ( SocketListEntry connection,
int  startIdx 
) [protected]

Assumes sendListLock is hold and connection is from the localCopy list

void SendReceiveThread::handleConnectionRequestPrioritizedMsg ( SocketListEntry connections,
int  entries 
) [protected]

This method waits for the answers of all partners to the previous sent connectionRequest. It does this by iterating over all sockets and waiting for a message with a connectionRequestOkTag or a connectionRequestDenyTag. If a message with another Tag is received at a socket, the receiveMessage method is called and the method waits again for the answer. When all answers arrived, the method checks if every partner accepts the connection request and sets the connectionGlobalAllowed-member in the Network according to it. Afterwards it enters a connectionBarrier for synchronisation with the ServerThread.

Parameters:
connections list of socketListEntrys from which an answer is expected
entries the number of entries in connections
Author:
hbress

void SendReceiveThread::handlePrioritizedMsgs ( SocketListEntry connections,
int  entries 
) [protected]

In case a prioritizedMsg is assigned to a SocketListEntry (by now that means each SocketListEntry has the same prioritizedMsg) we typically have to stick to a certain order of send and recv steps. However because blocking operations can be avoided by introducing special message tags and working together with receiveMessage() we tried to go this way, so expect some complicated pieces of code ;-)

void SendReceiveThread::initializeSocketSelection ( OSG::SocketSelection &  sel,
SendListEntry nextUDPMsg,
SocketListEntry socketListCopy,
int  entries 
) [protected]

void SendReceiveThread::kill (  ) 

void SendReceiveThread::killedSocket ( SocketListEntry connections,
int  entries,
int  idx 
) [protected]

Here we try to close a lost socket in a safe way and to reduce the ref counters of all the messages it would have send.

void SendReceiveThread::receiveMessage ( NetMessage msg,
SocketListEntry recvdBy 
) [protected]

Basically this method simply puts all messages into the recvList (TCP and UDP). Beside this and as mentioned in the description for handlePrioritizedMsgs() it is also involved in more complicated procedures (like connection requests).

void SendReceiveThread::receiveUDPMessage (  )  [protected]

void SendReceiveThread::respondToConnectionRequest ( NetMessage msg,
SocketListEntry recvdBy 
) [protected]

This method sends back an answer to a received connectionRequest-message. If another client is already trying to connect a message with a connectionRequestDenyTag will be sent back, otherwise a message with a connectionRequestOkTag will be sent.

Parameters:
msg pointer to received connectionRequest-message
recvdBy SocketListEntry from partner who sent connectionRequest
Author:
hbress

void SendReceiveThread::respondToConnectionRequestDone ( NetMessage msg,
SocketListEntry recvdBy 
) [protected]

This method finalizes the connectionRequest. For this it pushes back the socketListEntry of the new client into the socketList and sets the connectionLocalAllowed-member to true again.

Parameters:
msg pointer to received connectionRequest-message
recvdBy SocketListEntry from partner who sent connectionRequest
Author:
hbress

void SendReceiveThread::run ( void *  dummy  )  [static]

This method contains the main loop of this thread. It uses a socket selection to avoid busy waiting or blocking. Whenever a prioritizedMsg is found, it invokes handlePrioritizedMsgs(). All received messages are handled by receiveMessage(). In order to minimize synchronization efforts it makes copy of the working set of the connections at the beginning of each iteration (thats the localCopy local variable). Additionally the rawSendListTCP is appended to the sendListTCP. This method is also responsible for dealing with lost connections, which are handled in the killedSocket() method.

Parameters:
dummy has type SendReceiveThread, its an instance created by the caller

void SendReceiveThread::sendUDPMessage ( SendListEntry *&  nextUDPMsg,
SocketListEntry socketListCopy,
int  entries 
) [protected]

void SendReceiveThread::updateSendListTCP ( SocketListEntry connections,
int  entries 
) [protected]

void SendReceiveThread::updateSendListUDP ( SendListEntry *&  nextUDPMsg,
int  connections 
) [protected]


Friends And Related Function Documentation

friend class Network [friend]


Member Data Documentation

Network * SendReceiveThread::internalNetwork = NULL [static, protected]

volatile bool SendReceiveThread::shutdown [protected]


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

Generated on Wed Oct 20 16:12:00 2010 for inVRs by doxygen 1.5.8