MAK RTIspy API Documentation for HLA 1516
List of all members | 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:

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.
- Public Member Functions inherited from DtMsgSocket
 DtMsgSocket (DtBoost::shared_ptr< DtMsgHeaderReader > hdrReader, size_t recvBuffSize)
 Constructor.
 DtMsgSocket (std::auto_ptr< DtInetSocket > socket, DtBoost::shared_ptr< DtMsgHeaderReader > hdrReader, size_t recvBuffSize)
 Constructor which takes a pre-created DtInetSocket pointer.
virtual ~DtMsgSocket ()
 Destructor.
virtual bool closeSocket ()
 Close a socket. Returns true on successful close or false on failure.
virtual DtInetSockState state () const
 Returns the state of the socket.
void printStateToStream (MAKRti::DtOutputStream &stream) const
 prints state to stream
const DtString & lastError () const
 Returns a description of the last error.
const DtInetEndpoint & localEndpoint () const
 Gets the local endpoint for the socket.
void setSendBufferSize (DtU32 size)
 Sets the socket send buffer size.
void setRecvBufferSize (DtU32 size)
 Sets the socket receive buffer size.
DtU32 maxSendMsgSize () const
 Gets the maximum socket send size.
int descriptor () const
 Get's the socket file descriptor.
DtInetSocket * inetSocket ()
 Returns a pointer to the DtInetSocket.

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 Member Functions inherited from DtMsgSocket
void expandRecvBuffer (size_t sizeNeeded)
 Expands the receive buffer to accommodate the given size message.

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.
- Protected Attributes inherited from DtMsgSocket
std::auto_ptr
< MAKRti::DtInetSocket > 
mySocket
 The socket.
DtInetBuffer myRecvBuffer
 The buffer to store received data in.
DtString myLastError
 Description of last error.
DtBoost::shared_ptr
< DtMsgHeaderReader
myHeaderReader
 Reads data from 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().

DtTcpMsgSocket::~DtTcpMsgSocket ( )
virtual

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.

void DtTcpMsgSocket::disableCompression ( )
virtual

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 ( )
protectedvirtual

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
bool DtTcpMsgSocket::isConnectionInProgress ( ) 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(), 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 
)
protectedvirtual

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 ( )
protectedvirtual

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 
)
protectedvirtual

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().

bool DtTcpMsgSocket::testConnectionStatus ( )
virtual

Member Data Documentation

bool DtTcpMsgSocket::myBundlingEnabled
protected

Whether message bundling is enabled.

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

size_t DtTcpMsgSocket::myBytesNeededForSize
protected

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

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

bool DtTcpMsgSocket::myCompressionEnabled
protected

Whether message compression is enabled.

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

int DtTcpMsgSocket::myMaxQueuedMessages
protected

The maximum size the send queue is allowed to reach.

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

DtMsgBundler DtTcpMsgSocket::myMsgBundler
protected

Bundler for outgoing messages.

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

DtMsgCompressor DtTcpMsgSocket::myMsgCompressor
protected

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
mutableprotected

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().

bool DtTcpMsgSocket::myNeedSize
protected

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

Referenced by recvMessage().

int DtTcpMsgSocket::myNumBytesReceived
protected

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

Referenced by recvMessage().

int DtTcpMsgSocket::myNumBytesToWaitFor
protected

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 Tue May 7 16:26:47 EDT 2013 from SVN revision 126903
Copyright © 2005-2013 VT MÄK Inc. All Rights Reserved (www.mak.com)