#include <main.h>
Inheritance diagram for TcpConnection:
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 | |
| Manager & | manager |
| 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 |
|
|
The size of the array that we keep track on the read size |
|
|
Constructor |
|
|
Destructor |
|
|
Assign this thread a unique Id - the caller had better make sure it is unique, otherwise the list of connectionsActive will never accept it |
|
||||||||||||||||
|
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 |
|
|
End this particular TCP connection, and remove it dead. Do notifiy the manager etc. |
|
|
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. |
|
|
Get a nicely formatted (with micro seconds) time of day + year. |
|
|
Report the source id as used by this connection |
|
||||||||||||
|
This is the main method of the IncomingMessages thread |
|
|
Managing thread is alive |
|
|
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. |
|
||||||||||||
|
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 |
|
|
Pretty print this connection |
|
|
Now, we have exactly one message, not multiple messages. Process it on |
|
|
Send the supplied message to the node on this socket |
|
|
Get the thread in this class to start running, to process incoming connections |
|
|
Give this class the socket that we accept off, and then start the work |
|
|
The opposite of StartWorkNow, - the listen request failed, so we have to get this TcpConnection to die and go away |
|
|
Stop the thread on this class |
|
|
Mutex to protect access to the isClearing flag, which ensures that only one thread attempts to clear this connection |
|
|
The name of the thread used to clear this TcpConnection instance |
|
|
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 |
|
|
Lock on the pointer to the incoming messages thread |
|
|
The thread which does all the work of handling (and sending) incoming messages |
|
|
Flag to indicate we are being cleared, or have been cleared |
|
|
The manager that looks after us |
|
|
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 |
|
|
Socket we manage incoming/outgoing messages on, for this instance of TcpConnection |
|
|
The array we record the sizes in |
|
|
The index as to where we write the data in the readArray |
|
|
Flag to control if we should write messages read in to the console |
|
|
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. |
|
|
Flag which says that the socket is accepted on and ready to go |
|
|
The id, as chosen by the remote node who is talking to us |
|
|
The name of this thread. Use a local variable to store this value, as it make the thing more thread safe |
|
|
Lock on the sending of messages out this socket |
1.4.4