MAK RTIspy API Documentation for HLA Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes | Static 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 (std::shared_ptr< DtMsgHeaderReader > hdrReader, size_t recvBufferSize=20000, int maxQueuedMsgs=-1)
 Constructor. More...
 
 DtTcpMsgSocket (DtUniquePtr< MAKRti::DtInetTcpSocket > socket, std::shared_ptr< DtMsgHeaderReader > hdrReader, size_t recvBuffSize=20000, int maxQueuedMsgs=-1)
 Constructor which takes a pre-created MAKRti::DtInetTcpSocket pointer. More...
 
virtual ~DtTcpMsgSocket ()
 Destructor. More...
 
virtual void openServerSocket (MAKRti::DtU16 localPort, MAKRti::DtU32 flags=theDefaultSockOpts, MAKRti::DtInetDevice *hostIf=NULL, MAKRti::DtInetUtils::DtInetAddrFamily family=MAKRti::DtInetUtils::DtInetAddrFamily_IPv4)
 Opens a server socket if not already open. More...
 
virtual void openClientSocket (const MAKRti::DtInetEndpoint &dest, MAKRti::DtU32 flags=theDefaultSockOpts, MAKRti::DtU16 localPort=0, MAKRti::DtInetDevice *hostIf=NULL)
 Opens a client socket if not already open. More...
 
virtual MAKRti::DtInetTcpSocket * reconnect ()
 
virtual void replaceSocket (DtUniquePtr< MAKRti::DtInetTcpSocket > newSock)
 
virtual int sendMessage (caddr_t msg, size_t msgSize, bool deleteAfterSend, const MAKRti::DtInetAddr &destAddr=MAKRti::DtInetAddr::inaddrAny(), int port=0)
 Sends a message, queuing it up if the receiver's buffer is full. More...
 
virtual bool flush ()
 Attempts to send any queued messages and bundled messages. More...
 
virtual int recvMessage (caddr_t *buffptr)
 Gets the next message from the stream of incoming data. More...
 
virtual int recvMessageWithSrc (caddr_t *buffptr, MAKRti::DtInetEndpoint &src)
 Gets the next message from the stream of incoming data. More...
 
virtual void enableBundling (size_t maxBundleSize)
 Enables message bundling and sets the maximum bundle size. More...
 
virtual void disableBundling ()
 Disables message bundling. More...
 
virtual unsigned bundleSize () const
 Returns the bundle size, or 0 if bundling disabled. More...
 
virtual void enableCompression (MAKRti::DtU8 compressionLevel)
 Enables message compression and sets the compression level. More...
 
virtual void disableCompression ()
 Disables message compression. More...
 
virtual unsigned compressionLevel () const
 Returns the compression level, or 0 if compression disabled. More...
 
virtual bool testConnectionStatus ()
 
virtual void setMaxQueuedMessages (int size)
 Sets the maximum number of messages that can be queued. More...
 
virtual int maxQueuedMessages () const
 Returns the maximum number of messages that can be queued. More...
 
virtual bool getQueueStatus (int &percentFull) const
 Gets the percentage full of the message queue. More...
 
virtual void setTcpNoDelay (bool enable)
 Changes the setting of TCP_NODELAY. More...
 
virtual void setNonBlocking (bool nonBlocking)
 Makes the socket non-blocking or blocking. More...
 
virtual const
MAKRti::DtInetEndpoint & 
destination () const
 Returns the destination endpoint of this socket. More...
 
virtual MAKRti::DtU32 maxMsgSize () const
 Gets the maximum message size. More...
 
MAKRti::DtInetTcpSocket * inetTcpSocket ()
 Returns a pointer to the MAKRti::DtInetTcpSocket. More...
 
bool isConnected () const
 Returns true if the socket is connected. More...
 
bool isConnectionInProgress () const
 Returns true if the socket is in the process of connecting. More...
 
MAKRti::DtString getErrorString () const
 
virtual bool isClient () const
 
- Public Member Functions inherited from DtMsgSocket
 DtMsgSocket (std::shared_ptr< DtMsgHeaderReader > hdrReader, size_t recvBuffSize)
 Constructor. More...
 
 DtMsgSocket (DtUniquePtr< MAKRti::DtInetSocket > socket, std::shared_ptr< DtMsgHeaderReader > hdrReader, size_t recvBuffSize)
 Constructor which takes a pre-created MAKRti::DtInetSocket pointer. More...
 
virtual ~DtMsgSocket ()
 Destructor. More...
 
virtual bool closeSocket ()
 Close a socket. Returns true on successful close or false on failure. More...
 
virtual MAKRti::DtInetSockState state () const
 Returns the state of the socket. More...
 
void printStateToStream (MAKRti::DtOutputStream &stream) const
 prints state to stream More...
 
const MAKRti::DtString & lastError () const
 Returns a description of the last error. More...
 
const MAKRti::DtInetEndpoint & localEndpoint () const
 Gets the local endpoint for the socket. More...
 
void setSendBufferSize (MAKRti::DtU32 size)
 Sets the socket send buffer size. More...
 
void setRecvBufferSize (MAKRti::DtU32 size)
 Sets the socket receive buffer size. More...
 
MAKRti::DtU32 maxSendMsgSize () const
 Gets the maximum socket send size. More...
 
unsigned int descriptor () const
 Get's the socket file descriptor. More...
 
MAKRti::DtInetSocket * inetSocket ()
 Returns a pointer to the MAKRti::DtInetSocket. More...
 

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. More...
 
virtual bool flushQueue ()
 Attempts to send any queued messages. More...
 
virtual bool queueMessage (caddr_t msg, size_t msgSize)
 Adds a message to the transmit queue. Returns true if successful. More...
 
virtual void resizeTestPacket ()
 Resizes the test packet used to test the connection. More...
 
- Protected Member Functions inherited from DtMsgSocket
void expandRecvBuffer (size_t sizeNeeded)
 Expands the receive buffer to accommodate the given size message. More...
 

Protected Attributes

bool myNeedSize
 Whether we still need to receive the size field for the next/current message. More...
 
size_t myNumBytesToWaitFor
 The number of bytes we are waiting for to complete the message. More...
 
int myNumBytesReceived
 The number of bytes we have so far received for the current message. More...
 
MAKRti::DtInetBuffer myTestPacket
 The buffer to store test packets in. More...
 
std::list< DtQueuedMsgmyMsgQueue
 The queue of unsent messages. More...
 
DtMsgBundler myMsgBundler
 Bundler for outgoing messages. More...
 
bool myBundlingEnabled
 Whether message bundling is enabled. More...
 
DtMsgCompressor myMsgCompressor
 Message compressor and uncompressor. More...
 
bool myCompressionEnabled
 Whether message compression is enabled. More...
 
int myMaxQueuedMessages
 The maximum size the send queue is allowed to reach. More...
 
int myMutableOldQueueLevel
 The queue level the last time the user was notified of queue state. More...
 
size_t myBytesNeededForSize
 The number of bytes needed to read the size from the message header. More...
 
bool myIsClient
 
MAKRti::DtInetEndpoint myClientDestination
 
MAKRti::DtU32 myClientFlags
 
MAKRti::DtU16 myClientLocalPort
 
DtUniquePtr< MAKRti::DtInetDevice > myClientHostIf
 
- Protected Attributes inherited from DtMsgSocket
DtUniquePtr< MAKRti::DtInetSocket > mySocket
 The socket. More...
 
MAKRti::DtInetBuffer myRecvBuffer
 The buffer to store received data in. More...
 
MAKRti::DtString myLastError
 Description of last error. More...
 
std::shared_ptr
< DtMsgHeaderReader
myHeaderReader
 Reads data from message header. More...
 

Static Protected Attributes

static const MAKRti::DtU32 theDefaultSockOpts
 

Detailed Description

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

Constructor & Destructor Documentation

DtTcpMsgSocket::DtTcpMsgSocket ( std::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.

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

Constructor which takes a pre-created MAKRti::DtInetTcpSocket pointer.

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

virtual DtTcpMsgSocket::~DtTcpMsgSocket ( )
virtual

Destructor.

Member Function Documentation

virtual unsigned DtTcpMsgSocket::bundleSize ( ) const
virtual

Returns the bundle size, or 0 if bundling disabled.

virtual unsigned DtTcpMsgSocket::compressionLevel ( ) const
virtual

Returns the compression level, or 0 if compression disabled.

virtual const MAKRti::DtInetEndpoint& DtTcpMsgSocket::destination ( ) const
virtual

Returns the destination endpoint of this socket.

virtual void DtTcpMsgSocket::disableBundling ( )
virtual

Disables message bundling.

Implements DtMsgSocket.

virtual void DtTcpMsgSocket::disableCompression ( )
virtual

Disables message compression.

Implements DtMsgSocket.

virtual void DtTcpMsgSocket::enableBundling ( size_t  maxBundleSize)
virtual

Enables message bundling and sets the maximum bundle size.

Implements DtMsgSocket.

virtual void DtTcpMsgSocket::enableCompression ( MAKRti::DtU8  compressionLevel)
virtual

Enables message compression and sets the compression level.

Implements DtMsgSocket.

virtual bool DtTcpMsgSocket::flush ( )
virtual

Attempts to send any queued messages and bundled messages.

Returns true if all queued and bundled messages were sent.

Implements DtMsgSocket.

virtual bool DtTcpMsgSocket::flushQueue ( )
protectedvirtual

Attempts to send any queued messages.

Returns true if all queued messages were sent.

MAKRti::DtString DtTcpMsgSocket::getErrorString ( ) const
virtual 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.

MAKRti::DtInetTcpSocket * DtTcpMsgSocket::inetTcpSocket ( )
inline

Returns a pointer to the MAKRti::DtInetTcpSocket.

References DtMsgSocket::mySocket.

Referenced by DtMessageFilter::addToSocketMap(), DtMessageFilter::removeFromSocketMap(), and DtTcpMsgSocketMgr::socketIter().

virtual bool DtTcpMsgSocket::isClient ( ) const
virtual
bool DtTcpMsgSocket::isConnected ( ) const
inline

Returns true if the socket is connected.

bool DtTcpMsgSocket::isConnectionInProgress ( ) const
inline

Returns true if the socket is in the process of connecting.

virtual MAKRti::DtU32 DtTcpMsgSocket::maxMsgSize ( ) const
virtual

Gets the maximum message size.

virtual int DtTcpMsgSocket::maxQueuedMessages ( ) const
virtual

Returns the maximum number of messages that can be queued.

A negative value indicates no limit is imposed.

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

Opens a client socket if not already open.

Takes a MAKRti::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.

virtual void DtTcpMsgSocket::openServerSocket ( MAKRti::DtU16  localPort,
MAKRti::DtU32  flags = theDefaultSockOpts,
MAKRti::DtInetDevice *  hostIf = NULL,
MAKRti::DtInetUtils::DtInetAddrFamily  family = MAKRti::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.

virtual bool DtTcpMsgSocket::queueMessage ( caddr_t  msg,
size_t  msgSize 
)
protectedvirtual

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

virtual MAKRti::DtInetTcpSocket* DtTcpMsgSocket::reconnect ( )
virtual
virtual int DtTcpMsgSocket::recvMessage ( caddr_t *  buffptr)
virtual

Gets the next message from the stream of incoming data.

Implements DtMsgSocket.

virtual int DtTcpMsgSocket::recvMessageWithSrc ( caddr_t *  buffptr,
MAKRti::DtInetEndpoint &  src 
)
virtual

Gets the next message from the stream of incoming data.

Implements DtMsgSocket.

virtual void DtTcpMsgSocket::replaceSocket ( DtUniquePtr< MAKRti::DtInetTcpSocket >  newSock)
virtual
virtual void DtTcpMsgSocket::resizeTestPacket ( )
protectedvirtual

Resizes the test packet used to test the connection.

virtual int DtTcpMsgSocket::sendData ( caddr_t  msg,
size_t  msgSize,
bool  deleteAfterSend 
)
protectedvirtual

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

virtual int DtTcpMsgSocket::sendMessage ( caddr_t  msg,
size_t  msgSize,
bool  deleteAfterSend,
const MAKRti::DtInetAddr &  destAddr = MAKRti::DtInetAddr::inaddrAny(),
int  port = 0 
)
virtual

Sends a message, queuing it up if the receiver's buffer is full.

destAddr is ignored.

Implements DtMsgSocket.

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.

virtual void DtTcpMsgSocket::setNonBlocking ( bool  nonBlocking)
virtual

Makes the socket non-blocking or blocking.

virtual void DtTcpMsgSocket::setTcpNoDelay ( bool  enable)
virtual

Changes the setting of TCP_NODELAY.

virtual bool DtTcpMsgSocket::testConnectionStatus ( )
virtual

Member Data Documentation

bool DtTcpMsgSocket::myBundlingEnabled
protected

Whether message bundling is enabled.

size_t DtTcpMsgSocket::myBytesNeededForSize
protected

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

MAKRti::DtInetEndpoint DtTcpMsgSocket::myClientDestination
protected
MAKRti::DtU32 DtTcpMsgSocket::myClientFlags
protected
DtUniquePtr<MAKRti::DtInetDevice> DtTcpMsgSocket::myClientHostIf
protected
MAKRti::DtU16 DtTcpMsgSocket::myClientLocalPort
protected
bool DtTcpMsgSocket::myCompressionEnabled
protected

Whether message compression is enabled.

bool DtTcpMsgSocket::myIsClient
protected
int DtTcpMsgSocket::myMaxQueuedMessages
protected

The maximum size the send queue is allowed to reach.

DtMsgBundler DtTcpMsgSocket::myMsgBundler
protected

Bundler for outgoing messages.

DtMsgCompressor DtTcpMsgSocket::myMsgCompressor
protected

Message compressor and uncompressor.

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

The queue of unsent messages.

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.

bool DtTcpMsgSocket::myNeedSize
protected

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

int DtTcpMsgSocket::myNumBytesReceived
protected

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

size_t DtTcpMsgSocket::myNumBytesToWaitFor
protected

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

MAKRti::DtInetBuffer DtTcpMsgSocket::myTestPacket
protected

The buffer to store test packets in.

const MAKRti::DtU32 DtTcpMsgSocket::theDefaultSockOpts
staticprotected

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

Document ID: Generated on Sun Jul 20 16:15:30 EDT 2025 from SVN revision 277985
Copyright © 2005-2025 MAK Technologies Inc. All Rights Reserved (www.mak.com)