MAK RTIspy API Documentation for HLA Evolved
Public Member Functions | Protected Member Functions | Protected Attributes
DtTcpMsgSocket Class Reference

The DtTcpMsgSocket class provides an address family independent TCP socket that handles RTI messages. More...

+ Inheritance diagram for DtTcpMsgSocket:
+ Collaboration diagram for DtTcpMsgSocket:

List of all members.

Public Member Functions

 DtTcpMsgSocket (DtBoost::shared_ptr< DtMsgHeaderReader > hdrReader, size_t recvBufferSize=20000, int maxQueuedMsgs=-1)
 Constructor.
 DtTcpMsgSocket (std::auto_ptr< DtInetTcpSocket > socket, DtBoost::shared_ptr< DtMsgHeaderReader > hdrReader, size_t recvBuffSize=20000, int maxQueuedMsgs=-1)
 Constructor which takes a pre-created DtInetTcpSocket pointer.
virtual ~DtTcpMsgSocket ()
 Destructor.
virtual void openServerSocket (DtU16 localPort, DtU32 flags=DtDefaultSockOpts, DtInetDevice *hostIf=NULL, DtInetUtils::DtInetAddrFamily family=DtInetUtils::DtInetAddrFamily_IPv4)
 Opens a server socket if not already open.
virtual void openClientSocket (const DtInetEndpoint &dest, DtU32 flags=DtDefaultSockOpts, DtU16 localPort=0, DtInetDevice *hostIf=NULL)
 Opens a client socket if not already open.
virtual int sendMessage (caddr_t msg, size_t msgSize, bool deleteAfterSend, const DtInetAddr &destAddr=DtInetAddr::inaddrAny())
 Sends a message, queuing it up if the receiver's buffer is full.
virtual bool flush ()
 Attempts to send any queued messages and bundled messages.
virtual int recvMessage (caddr_t *buffptr)
 Gets the next message from the stream of incoming data.
virtual int recvMessageWithSrc (caddr_t *buffptr, DtInetEndpoint &src)
 Gets the next message from the stream of incoming data.
virtual void enableBundling (size_t maxBundleSize)
 Enables message bundling and sets the maximum bundle size.
virtual void disableBundling ()
 Disables message bundling.
virtual unsigned bundleSize () const
 Returns the bundle size, or 0 if bundling disabled.
virtual void enableCompression (DtU8 compressionLevel)
 Enables message compression and sets the compression level.
virtual void disableCompression ()
 Disables message compression.
virtual unsigned compressionLevel () const
 Returns the compression level, or 0 if compression disabled.
virtual bool testConnectionStatus ()
virtual void setMaxQueuedMessages (int size)
 Sets the maximum number of messages that can be queued.
virtual int maxQueuedMessages () const
 Returns the maximum number of messages that can be queued.
virtual bool getQueueStatus (int &percentFull) const
 Gets the percentage full of the message queue.
virtual void setTcpNoDelay (bool enable)
 Changes the setting of TCP_NODELAY.
virtual void setNonBlocking (bool nonBlocking)
 Makes the socket non-blocking or blocking.
virtual const DtInetEndpoint & destination () const
 Returns the destination endpoint of this socket.
virtual DtU32 maxMsgSize () const
 Gets the maximum message size.
DtInetTcpSocket * inetTcpSocket ()
 Returns a pointer to the DtInetTcpSocket.
bool isConnected () const
 Returns true if the socket is connected.
bool isConnectionInProgress () const
 Returns true if the socket is in the process of connecting.

Protected Member Functions

virtual int sendData (caddr_t msg, size_t msgSize, bool deleteAfterSend)
 Sends data on the socket, queues if it cannot be sent.
virtual bool flushQueue ()
 Attempts to send any queued messages.
virtual bool queueMessage (caddr_t msg, size_t msgSize)
 Adds a message to the transmit queue. Returns true if successful.
virtual void resizeTestPacket ()
 Resizes the test packet used to test the connection.

Protected Attributes

bool myNeedSize
 Whether we still need to receive the size field for the next/current message.
int myNumBytesToWaitFor
 The number of bytes we are waiting for to complete the message.
int myNumBytesReceived
 The number of bytes we have so far received for the current message.
DtInetBuffer myTestPacket
 The buffer to store test packets in.
std::list< DtQueuedMsgmyMsgQueue
 The queue of unsent messages.
DtMsgBundler myMsgBundler
 Bundler for outgoing messages.
bool myBundlingEnabled
 Whether message bundling is enabled.
DtMsgCompressor myMsgCompressor
 Message compressor and uncompressor.
bool myCompressionEnabled
 Whether message compression is enabled.
int myMaxQueuedMessages
 The maximum size the send queue is allowed to reach.
int myMutableOldQueueLevel
 The queue level the last time the user was notified of queue state.
size_t myBytesNeededForSize
 The number of bytes needed to read the size from the message header.

Detailed Description

The DtTcpMsgSocket class provides an address family independent TCP socket that handles RTI messages.


Constructor & Destructor Documentation

DtTcpMsgSocket::DtTcpMsgSocket ( DtBoost::shared_ptr< DtMsgHeaderReader hdrReader,
size_t  recvBufferSize = 20000,
int  maxQueuedMsgs = -1 
)

Constructor.

Requires a header reader to extract information from message headers. Does NOT open the socket. A call to openServerSocket() or openClientSocket() is required.

References myBytesNeededForSize, myNumBytesToWaitFor, and resizeTestPacket().

DtTcpMsgSocket::DtTcpMsgSocket ( std::auto_ptr< DtInetTcpSocket >  socket,
DtBoost::shared_ptr< DtMsgHeaderReader hdrReader,
size_t  recvBuffSize = 20000,
int  maxQueuedMsgs = -1 
)

Constructor which takes a pre-created DtInetTcpSocket pointer.

Gives ownership and responsibility of the socket to the DtTcpMsgSocket object.

References myBytesNeededForSize, myNumBytesToWaitFor, and resizeTestPacket().

Destructor.


Member Function Documentation

unsigned DtTcpMsgSocket::bundleSize ( ) const [virtual]
unsigned DtTcpMsgSocket::compressionLevel ( ) const [virtual]

Returns the compression level, or 0 if compression disabled.

References DtMsgCompressor::compressionLevel(), myCompressionEnabled, and myMsgCompressor.

const DtInetEndpoint & DtTcpMsgSocket::destination ( ) const [virtual]
void DtTcpMsgSocket::disableBundling ( ) [virtual]

Disables message bundling.

Implements DtMsgSocket.

References myBundlingEnabled.

Disables message compression.

Implements DtMsgSocket.

References myCompressionEnabled.

void DtTcpMsgSocket::enableBundling ( size_t  maxBundleSize) [virtual]
void DtTcpMsgSocket::enableCompression ( DtU8  compressionLevel) [virtual]
bool DtTcpMsgSocket::flush ( ) [virtual]
bool DtTcpMsgSocket::flushQueue ( ) [protected, virtual]

Attempts to send any queued messages.

Returns true if all queued messages were sent.

References myMsgQueue, and DtMsgSocket::mySocket.

Referenced by flush(), and sendData().

bool DtTcpMsgSocket::getQueueStatus ( int &  percentFull) const [virtual]

Gets the percentage full of the message queue.

Return value indicates whether a threshold has been hit such that a user alert is necessary.

References myMaxQueuedMessages, myMsgQueue, and myMutableOldQueueLevel.

Referenced by DtFilteredTcpForwarder::sendToList().

DtInetTcpSocket * DtTcpMsgSocket::inetTcpSocket ( ) [inline]
bool DtTcpMsgSocket::isConnected ( ) const [inline]
DtU32 DtTcpMsgSocket::maxMsgSize ( ) const [virtual]

Gets the maximum message size.

References DtMsgSocket::mySocket.

int DtTcpMsgSocket::maxQueuedMessages ( ) const [virtual]

Returns the maximum number of messages that can be queued.

A negative value indicates no limit is imposed.

References myMaxQueuedMessages.

void DtTcpMsgSocket::openClientSocket ( const DtInetEndpoint &  dest,
DtU32  flags = DtDefaultSockOpts,
DtU16  localPort = 0,
DtInetDevice *  hostIf = NULL 
) [virtual]

Opens a client socket if not already open.

Takes a DtInetEndpoint (containing the destination address, protocol - TCP or UDP, and destination port number), a source port number to use, a pointer to the local network interface device the socket will be bound to, and socket option flags. The address family (IPv4 or IPv6) is assumed from the dest endpoint object. If the specified local port is 0 an ephemeral port will be chosen for the connection UNLESS the destination is a broadcast or multicast address, in which case the destination port is used as the local port also. If no host interface is specified the most appropriate interface will be chosen based on the destination. This ctor will not throw exceptions on failure. Check the socket status by calling state() to determine if the socket is ready.

References DtMsgSocket::myLastError, and DtMsgSocket::mySocket.

Referenced by DtPeerToPeerTcpSockMgr::connectToPeer(), DtTcpWwwSpyAdapter::connectToWebServer(), DtConnectionMgr::createAncillaryRelConns(), DtConnectionMgr::createRelConn(), and DtRtiAssistantClient::makeSingleConnectionAttempt().

void DtTcpMsgSocket::openServerSocket ( DtU16  localPort,
DtU32  flags = DtDefaultSockOpts,
DtInetDevice *  hostIf = NULL,
DtInetUtils::DtInetAddrFamily  family = DtInetUtils::DtInetAddrFamily_IPv4 
) [virtual]

Opens a server socket if not already open.

Takes a port number to listen on, a pointer to the local network interface device the socket will be bound to, an address family indication (IPv4 or IPv6), socket option flags, and a trigger to open the socket immediately. If no host interface is specified the socket will be bound to INADDR_ANY (or IN6ADDR_ANY). Socket will be opened immediately. This ctor will not throw exceptions on failure. Check the socket status by calling state() to determine if the socket is ready to use.

References DtMsgSocket::myLastError, and DtMsgSocket::mySocket.

bool DtTcpMsgSocket::queueMessage ( caddr_t  msg,
size_t  msgSize 
) [protected, virtual]

Adds a message to the transmit queue. Returns true if successful.

References DtMsgSocket::myLastError, myMaxQueuedMessages, and myMsgQueue.

Referenced by sendData().

int DtTcpMsgSocket::recvMessage ( caddr_t *  buffptr) [virtual]
int DtTcpMsgSocket::recvMessageWithSrc ( caddr_t *  buffptr,
DtInetEndpoint &  src 
) [virtual]

Gets the next message from the stream of incoming data.

Implements DtMsgSocket.

References DtMsgSocket::mySocket, and recvMessage().

void DtTcpMsgSocket::resizeTestPacket ( ) [protected, virtual]

Resizes the test packet used to test the connection.

References myBytesNeededForSize, DtMsgSocket::myHeaderReader, and myTestPacket.

Referenced by DtTcpMsgSocket().

int DtTcpMsgSocket::sendData ( caddr_t  msg,
size_t  msgSize,
bool  deleteAfterSend 
) [protected, virtual]

Sends data on the socket, queues if it cannot be sent.

References flushQueue(), DtMsgSocket::myLastError, DtMsgSocket::mySocket, and queueMessage().

Referenced by flush(), and sendMessage().

int DtTcpMsgSocket::sendMessage ( caddr_t  msg,
size_t  msgSize,
bool  deleteAfterSend,
const DtInetAddr &  destAddr = DtInetAddr::inaddrAny() 
) [virtual]
void DtTcpMsgSocket::setMaxQueuedMessages ( int  size) [virtual]

Sets the maximum number of messages that can be queued.

A negative value indicates no limit is imposed.

References myMaxQueuedMessages.

void DtTcpMsgSocket::setNonBlocking ( bool  nonBlocking) [virtual]
void DtTcpMsgSocket::setTcpNoDelay ( bool  enable) [virtual]

Changes the setting of TCP_NODELAY.

References DtMsgSocket::mySocket.

Referenced by DtTcpMsgSocketMgr::socketAdded().


Member Data Documentation

Whether message bundling is enabled.

Referenced by bundleSize(), disableBundling(), enableBundling(), flush(), and sendMessage().

The number of bytes needed to read the size from the message header.

Referenced by DtTcpMsgSocket(), recvMessage(), and resizeTestPacket().

Whether message compression is enabled.

Referenced by compressionLevel(), disableCompression(), enableCompression(), and sendMessage().

The maximum size the send queue is allowed to reach.

Referenced by getQueueStatus(), maxQueuedMessages(), queueMessage(), and setMaxQueuedMessages().

Bundler for outgoing messages.

Referenced by bundleSize(), enableBundling(), flush(), and sendMessage().

Message compressor and uncompressor.

Referenced by compressionLevel(), enableCompression(), recvMessage(), and sendMessage().

std::list<DtQueuedMsg> DtTcpMsgSocket::myMsgQueue [protected]

The queue of unsent messages.

Referenced by flush(), flushQueue(), getQueueStatus(), and queueMessage().

int DtTcpMsgSocket::myMutableOldQueueLevel [mutable, protected]

The queue level the last time the user was notified of queue state.

Mutable since this is solely to maintain internal state and needs to be modified by the const getQueueStatus() method.

Referenced by getQueueStatus().

Whether we still need to receive the size field for the next/current message.

Referenced by recvMessage().

The number of bytes we have so far received for the current message.

Referenced by recvMessage().

The number of bytes we are waiting for to complete the message.

Referenced by DtTcpMsgSocket(), and recvMessage().

DtInetBuffer DtTcpMsgSocket::myTestPacket [protected]

The buffer to store test packets in.

Referenced by resizeTestPacket(), and testConnectionStatus().


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

Document ID: Generated on Thu Jun 14 14:15:04 EDT 2012 from SVN revision 116116
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)