Main Page | Class Hierarchy | Class List | File List | Class Members

TcpConnection Class Reference

#include <main.h>

Inheritance diagram for TcpConnection:

[legend]
Collaboration diagram for TcpConnection:
[legend]
List of all members.

Public Member Functions

 TcpConnection (Manager &_mgr)
 ~TcpConnection ()
void StartRunning ()
BOOL IsRunning ()
void PrintOn (ostream &strm) const
void Terminate ()
void AssignSourceId (PString &newId)
PString GetSourceId ()
void Clear ()
void StartWorkNow (PTCPSocket &listener)
void StartWorkNowNotPossible ()

Protected Types

enum  { readArraySize = 10 }

Protected Member Functions

PString GetNow ()
void DoOneMessage ()
void BreakUpMessageBlock (PBYTEArray &src, PINDEX srcLen, PStringArray &result)
void ProcessOneTextMessage (const PString &txt)
void SendThisMessage (PBYTEArray &msg)
virtual void OnReleaseThreadMain (PThread &, INT)
virtual void OnReleased ()
virtual void IncomingMessagesMain (PThread &, INT)

Protected Attributes

Managermanager
PMutex writeMessageLock
PMutex incomingLock
PThread * incomingMessages
PSyncPoint socketInitialised
PTCPSocket messagesSocket
PString sourceId
PINDEX readArray [readArraySize]
PINDEX readArrayIndex
PMutex clearMutex
BOOL isClearing
BOOL reportReadMessages
BOOL reportSentMessages
PBYTEArray message
PString thisThreadName
PString clearName
PString globalUniqueId

Detailed Description

A class that embodies safe access to a TCPSocket


Member Enumeration Documentation

anonymous enum [protected]
 

The size of the array that we keep track on the read size


Constructor & Destructor Documentation

TcpConnection::TcpConnection Manager _mgr  ) 
 

Constructor

TcpConnection::~TcpConnection  ) 
 

Destructor


Member Function Documentation

void TcpConnection::AssignSourceId PString &  newId  )  [inline]
 

Assign this thread a unique Id - the caller had better make sure it is unique, otherwise the list of connectionsActive will never accept it

void TcpConnection::BreakUpMessageBlock PBYTEArray &  src,
PINDEX  srcLen,
PStringArray &  result
[protected]
 

Take in a PBYTEArray, the specified size, and partition it up for each of the null terminated strings in it. The output is stored in the PStringArray

void TcpConnection::Clear  ) 
 

End this particular TCP connection, and remove it dead. Do notifiy the manager etc.

void TcpConnection::DoOneMessage  )  [protected]
 

The method that reads in one message, and then sends it to the other node. Note that this message may actually be several messages which he naughty internet comms system has glued together. Oh joy. Each message is deliminated by a zero byte.

PString TcpConnection::GetNow  )  [protected]
 

Get a nicely formatted (with micro seconds) time of day + year.

PString TcpConnection::GetSourceId  )  [inline]
 

Report the source id as used by this connection

void TcpConnection::IncomingMessagesMain PThread &  ,
INT 
[protected, virtual]
 

This is the main method of the IncomingMessages thread

BOOL TcpConnection::IsRunning  ) 
 

Managing thread is alive

void TcpConnection::OnReleased  )  [protected, virtual]
 

Clean up the termination of the connection. This function can do any internal cleaning up and waiting on background threads that may be using the connection object.

The default behaviour calls the Manager function of the same name.

void TcpConnection::OnReleaseThreadMain PThread &  ,
INT 
[protected, virtual]
 

This contains the 1 notifier that is used when closing down this instance of TcpConnection class. It is called by a custom thread, which deletes the class

void TcpConnection::PrintOn ostream &  strm  )  const
 

Pretty print this connection

void TcpConnection::ProcessOneTextMessage const PString &  txt  )  [protected]
 

Now, we have exactly one message, not multiple messages. Process it on

void TcpConnection::SendThisMessage PBYTEArray &  msg  )  [protected]
 

Send the supplied message to the node on this socket

void TcpConnection::StartRunning  ) 
 

Get the thread in this class to start running, to process incoming connections

void TcpConnection::StartWorkNow PTCPSocket &  listener  ) 
 

Give this class the socket that we accept off, and then start the work

void TcpConnection::StartWorkNowNotPossible  ) 
 

The opposite of StartWorkNow, - the listen request failed, so we have to get this TcpConnection to die and go away

void TcpConnection::Terminate  ) 
 

Stop the thread on this class


Member Data Documentation

PMutex TcpConnection::clearMutex [protected]
 

Mutex to protect access to the isClearing flag, which ensures that only one thread attempts to clear this connection

PString TcpConnection::clearName [protected]
 

The name of the thread used to clear this TcpConnection instance

PString TcpConnection::globalUniqueId [protected]
 

A globally unique ID that is assigned to this connection, based on a random number. It is used to uniquely identify this class, wherever it is

PMutex TcpConnection::incomingLock [protected]
 

Lock on the pointer to the incoming messages thread

PThread* TcpConnection::incomingMessages [protected]
 

The thread which does all the work of handling (and sending) incoming messages

BOOL TcpConnection::isClearing [protected]
 

Flag to indicate we are being cleared, or have been cleared

Manager& TcpConnection::manager [protected]
 

The manager that looks after us

PBYTEArray TcpConnection::message [protected]
 

Temporary buffer, which we use to store the current incoming message. We preallocate it here, so that no work is spent creating/freeing this block of temporary memory

PTCPSocket TcpConnection::messagesSocket [protected]
 

Socket we manage incoming/outgoing messages on, for this instance of TcpConnection

PINDEX TcpConnection::readArray[readArraySize] [protected]
 

The array we record the sizes in

PINDEX TcpConnection::readArrayIndex [protected]
 

The index as to where we write the data in the readArray

BOOL TcpConnection::reportReadMessages [protected]
 

Flag to control if we should write messages read in to the console

BOOL TcpConnection::reportSentMessages [protected]
 

Flag to control if we should write messages sent to the console. This differs to reportReadMessages, cause if there is no matching destination, nothing will be sent (or printed). This flag allows you to know if the incoming message was sent out.

PSyncPoint TcpConnection::socketInitialised [protected]
 

Flag which says that the socket is accepted on and ready to go

PString TcpConnection::sourceId [protected]
 

The id, as chosen by the remote node who is talking to us

PString TcpConnection::thisThreadName [protected]
 

The name of this thread. Use a local variable to store this value, as it make the thing more thread safe

PMutex TcpConnection::writeMessageLock [protected]
 

Lock on the sending of messages out this socket


The documentation for this class was generated from the following files:
Generated on Thu Apr 19 00:03:11 2007 for SSServer, or Sofa Switch Server by  doxygen 1.4.4