MAK RTIspy API Documentation for HLA 1.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
tcpMsgSocket.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 2010 MaK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 /*********************************************************************
6 ** $RCSfile: tcpMsgSocket.h,v $ $Revision: $ $State: Exp $
7 *********************************************************************/
8 
13 
14 #ifndef tcpMsgSocket_H_
15 #define tcpMsgSocket_H_
16 
17 #include "msgSocket.h"
18 #include "msgBundler.h"
19 #include "msgCompressor.h"
20 #include <list>
21 #include <vlutil/vlInetTcpSocket.h>
22 
24 {
25 public:
27  DtQueuedMsg(caddr_t m, size_t s) : msg(m), size(s),
28  remainingMsg(m), remainingSize(s) {}
30 
31  caddr_t msg;
32  size_t size;
33  caddr_t remainingMsg;
34  size_t remainingSize;
35 };
36 
41 {
42 public:
43 
47  DtTcpMsgSocket(std::shared_ptr<DtMsgHeaderReader> hdrReader,
48  size_t recvBufferSize = 20000, int maxQueuedMsgs = -1);
49 
52  DtTcpMsgSocket(DtUniquePtr<MAKRti::DtInetTcpSocket> socket,
53  std::shared_ptr<DtMsgHeaderReader> hdrReader,
54  size_t recvBuffSize = 20000, int maxQueuedMsgs = -1);
55 
57  virtual ~DtTcpMsgSocket();
58 
67  virtual void openServerSocket( MAKRti::DtU16 localPort,
68  MAKRti::DtU32 flags = theDefaultSockOpts, MAKRti::DtInetDevice* hostIf = NULL,
69  MAKRti::DtInetUtils::DtInetAddrFamily family = MAKRti::DtInetUtils::DtInetAddrFamily_IPv4 );
70 
83  virtual void openClientSocket( const MAKRti::DtInetEndpoint& dest,
84  MAKRti::DtU32 flags = theDefaultSockOpts, MAKRti::DtU16 localPort = 0,
85  MAKRti::DtInetDevice* hostIf = NULL);
86 
87  virtual MAKRti::DtInetTcpSocket* reconnect();
88  virtual void replaceSocket(DtUniquePtr<MAKRti::DtInetTcpSocket> newSock);
89 
92  virtual int sendMessage(caddr_t msg, size_t msgSize, bool deleteAfterSend,
93  const MAKRti::DtInetAddr& destAddr = MAKRti::DtInetAddr::inaddrAny(), int port = 0);
94 
97  virtual bool flush();
98 
100  virtual int recvMessage(caddr_t *buffptr);
101 
103  virtual int recvMessageWithSrc(caddr_t *buffptr, MAKRti::DtInetEndpoint& src);
104 
106  virtual void enableBundling(size_t maxBundleSize);
107 
109  virtual void disableBundling();
110 
112  virtual unsigned bundleSize() const;
113 
115  virtual void enableCompression(MAKRti::DtU8 compressionLevel);
116 
118  virtual void disableCompression();
119 
121  virtual unsigned compressionLevel() const;
122 
123  // Test the connection
124  virtual bool testConnectionStatus();
125 
128  virtual void setMaxQueuedMessages(int size);
129 
132  virtual int maxQueuedMessages() const;
133 
136  virtual bool getQueueStatus(int& percentFull) const;
137 
139  virtual void setTcpNoDelay(bool enable);
140 
142  virtual void setNonBlocking(bool nonBlocking);
143 
145  virtual const MAKRti::DtInetEndpoint& destination() const;
146 
148  virtual MAKRti::DtU32 maxMsgSize() const;
149 
151  MAKRti::DtInetTcpSocket* inetTcpSocket();
152 
154  bool isConnected() const { return mySocket.get() && mySocket->state() == MAKRti::DtInetSockState_CONNECTED; }
155 
157  bool isConnectionInProgress() const { return mySocket.get() && mySocket->state() == MAKRti::DtInetSockState_INPROGRESS; }
158 
159  MAKRti::DtString getErrorString() const;
160 
161  virtual bool isClient() const;
162 
163 protected:
164 
166  virtual int sendData(caddr_t msg, size_t msgSize, bool deleteAfterSend);
167 
170  virtual bool flushQueue();
171 
173  virtual bool queueMessage(caddr_t msg, size_t msgSize);
174 
176  virtual void resizeTestPacket();
177 
178 protected:
179 
183 
186 
189 
191  MAKRti::DtInetBuffer myTestPacket;
192 
194  std::list<DtQueuedMsg> myMsgQueue;
195 
198 
201 
204 
207 
210 
215 
218 
220 
221  // These are client connection related params required for reconnection
222  MAKRti::DtInetEndpoint myClientDestination;
223  MAKRti::DtU32 myClientFlags;
224  MAKRti::DtU16 myClientLocalPort;
225  DtUniquePtr<MAKRti::DtInetDevice> myClientHostIf;
226 
227  static const MAKRti::DtU32 theDefaultSockOpts;
228 };
229 
230 inline MAKRti::DtInetTcpSocket* DtTcpMsgSocket::inetTcpSocket()
231 {
232  return static_cast<MAKRti::DtInetTcpSocket*>(mySocket.get());
233 }
234 
235 #endif
~DtQueuedMsg()
Definition: tcpMsgSocket.h:29
bool isConnectionInProgress() const
Returns true if the socket is in the process of connecting.
Definition: tcpMsgSocket.h:157
size_t myBytesNeededForSize
The number of bytes needed to read the size from the message header.
Definition: tcpMsgSocket.h:217
std::list< DtQueuedMsg > myMsgQueue
The queue of unsent messages.
Definition: tcpMsgSocket.h:194
virtual void enableCompression(MAKRti::DtU8 compressionLevel)=0
Enables message compression and sets the compression level.
DtUniquePtr< MAKRti::DtInetDevice > myClientHostIf
Definition: tcpMsgSocket.h:225
This file contains the declaration of the DtMsgCompressor class.
virtual int recvMessage(caddr_t *buffptr)=0
Gets the next message from the incoming data.
size_t myNumBytesToWaitFor
The number of bytes we are waiting for to complete the message.
Definition: tcpMsgSocket.h:185
MAKRti::DtU32 myClientFlags
Definition: tcpMsgSocket.h:223
DtMsgBundler myMsgBundler
Bundler for outgoing messages.
Definition: tcpMsgSocket.h:197
MAKRti::DtInetTcpSocket * inetTcpSocket()
Returns a pointer to the MAKRti::DtInetTcpSocket.
Definition: tcpMsgSocket.h:230
DtQueuedMsg(caddr_t m, size_t s)
Definition: tcpMsgSocket.h:27
The DtMsgCompressor class provides a means for compressing and uncompressing messages.
Definition: msgCompressor.h:31
bool myNeedSize
Whether we still need to receive the size field for the next/current message.
Definition: tcpMsgSocket.h:182
int myMutableOldQueueLevel
The queue level the last time the user was notified of queue state.
Definition: tcpMsgSocket.h:214
MAKRti::DtInetEndpoint myClientDestination
Definition: tcpMsgSocket.h:222
static const MAKRti::DtU32 theDefaultSockOpts
Definition: tcpMsgSocket.h:227
int myMaxQueuedMessages
The maximum size the send queue is allowed to reach.
Definition: tcpMsgSocket.h:209
size_t size
Definition: tcpMsgSocket.h:32
#define NULL
Definition: baseTypes13.h:8
This file contains the declaration of the DtMsgSocket base class.
bool myIsClient
Definition: tcpMsgSocket.h:219
MAKRti::DtInetBuffer myTestPacket
The buffer to store test packets in.
Definition: tcpMsgSocket.h:191
DtQueuedMsg()
Definition: tcpMsgSocket.h:26
virtual int sendMessage(caddr_t msg, size_t msgSize, bool deleteAfterSend, const MAKRti::DtInetAddr &destAddr=MAKRti::DtInetAddr::inaddrAny(), int port=0)=0
Sends a message.
The DtMsgBundler class provides a means for bundling and unbundling messages.
Definition: msgBundler.h:27
The DtTcpMsgSocket class provides an address family independent TCP socket that handles RTI messages...
Definition: tcpMsgSocket.h:40
This file contains the declaration of the DtMsgBundler class.
int myNumBytesReceived
The number of bytes we have so far received for the current message.
Definition: tcpMsgSocket.h:188
bool isConnected() const
Returns true if the socket is connected.
Definition: tcpMsgSocket.h:154
virtual void disableBundling()=0
Disables message bundling.
The DtMsgSocket provides a wrapper around the MAKRti::DtInetSocket class to operate on messages rathe...
Definition: msgSocket.h:28
DtUniquePtr< MAKRti::DtInetSocket > mySocket
The socket.
Definition: msgSocket.h:116
bool myCompressionEnabled
Whether message compression is enabled.
Definition: tcpMsgSocket.h:206
virtual bool flush()=0
Attempts to send any queued messages and bundled messages.
size_t remainingSize
Definition: tcpMsgSocket.h:34
DtMsgCompressor myMsgCompressor
Message compressor and uncompressor.
Definition: tcpMsgSocket.h:203
MAKRti::DtU16 myClientLocalPort
Definition: tcpMsgSocket.h:224
virtual int recvMessageWithSrc(caddr_t *buffptr, MAKRti::DtInetEndpoint &src)=0
Gets the next message from the stream of incoming data and sets the source of the message...
Definition: tcpMsgSocket.h:23
virtual void enableBundling(size_t maxBundleSize)=0
Enables message bundling and sets the maximum bundle size.
virtual void disableCompression()=0
Disables message compression.
caddr_t remainingMsg
Definition: tcpMsgSocket.h:33
#define DT_DLL_RTIUTIL
Definition: rtiMsConfig.h:160
bool myBundlingEnabled
Whether message bundling is enabled.
Definition: tcpMsgSocket.h:200
caddr_t msg
Definition: tcpMsgSocket.h:31

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)