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

TCPConnection Class Reference

#include <main.h>

Inheritance diagram for TCPConnection:

Inheritance graph
[legend]
Collaboration diagram for TCPConnection:

Collaboration graph
[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

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

Protected Attributes

Managermanager
PMutex incomingLock
PThread * incomingMessages
PSyncPoint socketInitialised
PTCPSocket serverSocket
PString sourceId
PINDEX readArray [readArraySize]
PINDEX readArrayIndex
PMutex clearMutex
BOOL isClearing
BOOL reportReadMessages

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::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 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

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

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

PTCPSocket TCPConnection::serverSocket [protected]
 

Socket we manage incoming connection requests on

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


The documentation for this class was generated from the following files:
Generated on Sun Jan 29 19:49:43 2006 for SSServer, or Sofa Switch Server by  doxygen 1.4.4