MAK RTIspy API Documentation for HLA Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
tcpMsgSocketMgr.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 2010 MaK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 /*********************************************************************
6 ** $RCSfile: $ $Revision: $ $State: Exp $
7 *********************************************************************/
8 
10 
11 #ifndef tcpMsgSocketMgr_H_
12 #define tcpMsgSocketMgr_H_
13 
14 #include <set>
15 #include <vlutil/vlInetSocketMgr.h>
16 #include "tcpMsgSocket.h"
17 
19 typedef void (*DtTcpSocketAdditionCallback)(DtTcpMsgSocket* sock, void* usr);
21 
23 {
24 public:
25 
27  {
28  myCb = cb;
29  myUsr = usr;
30  }
31 
33  {
34  return (myCb == rhs.myCb && myUsr == rhs.myUsr);
35  }
36 
38  void* myUsr;
39 };
40 
41 typedef std::map<MAKRti::DtInetTcpSocket*, DtTcpMsgSocket*> DtTcpMsgSocketMap;
42 
44 {
45 public:
46 
48  DtTcpMsgSocketMgr(std::shared_ptr<DtMsgHeaderReader> hdrReader,
49  size_t recvBufferSize = 20000, int maxQueuedMsgs = -1);
50 
52  virtual ~DtTcpMsgSocketMgr();
53 
61  virtual bool openServerSocket( MAKRti::DtU16 localPort, MAKRti::DtInetDevice* hostIf = NULL,
62  MAKRti::DtInetUtils::DtInetAddrFamily family = MAKRti::DtInetUtils::DtInetAddrFamily_IPv4,
63  MAKRti::DtU32 flags = (theDefaultSockOpts | theSockOptNonBlocking));
64 
65  void processNewConnections();
66 
71  virtual void processConnections();
72 
75  virtual void addSocket(DtTcpMsgSocket* sock);
76 
78  static bool socketAdded(MAKRti::DtInetSocket* sock, void* usr);
79  bool socketAdded(MAKRti::DtInetSocket* sock);
80 
81  DtTcpMsgSocketMap::iterator checkIfReconnecting(const MAKRti::DtInetTcpSocket * newSock);
85  virtual void addSocketAdditionCallback(DtTcpSocketAdditionCallback cb, void* usr);
86  virtual void removeSocketAdditionCallback(DtTcpSocketAdditionCallback cb, void* usr);
88 
90  static bool socketRemoved(MAKRti::DtInetSocket* sock, void* usr);
91  bool socketRemoved(MAKRti::DtInetSocket* sock);
92 
96  virtual void addSocketRemovalCallback(DtTcpSocketRemovalCallback cb, void* usr);
97  virtual void removeSocketRemovalCallback(DtTcpSocketRemovalCallback cb, void* usr);
99 
101  virtual void removeAndDelete(DtTcpMsgSocket* sock);
102 
104  virtual void enableBundling(size_t maxBundleSize);
105 
107  virtual void disableBundling();
108 
110  virtual void enableCompression(MAKRti::DtU8 compressionLevel);
111 
113  virtual void disableCompression();
114 
116  virtual void setTcpNoDelay(bool enable);
117 
119  virtual void setSendBufferSize(MAKRti::DtU32 size);
120 
122  virtual void setRecvBufferSize(MAKRti::DtU32 size);
123 
125  virtual MAKRti::DtInetSockState serverSocketState() const;
126 
128  virtual MAKRti::DtU32 maxMsgSize() const;
129 
131  DtTcpMsgSocketMap& socketSet();
132 
135  DtTcpMsgSocketMap::iterator socketIter(DtTcpMsgSocket* sock);
136 
138  MAKRti::DtString getLastError() const;
139 
141  bool isListening() const { return serverSocketState() == MAKRti::DtInetSockState_LISTENING; }
142 
143 private:
144 
146  DtTcpMsgSocketMgr& operator=(const DtTcpMsgSocketMgr&);
147 
148 protected:
149 
151  DtUniquePtr<MAKRti::DtInetSocketMgr> mySocketMgr;
152 
156 
158  std::shared_ptr<DtMsgHeaderReader> myHeaderReader;
159 
162 
165 
168 
171 
173  MAKRti::DtU8 myCompressionLevel;
174 
176  MAKRti::DtU32 mySockRecvBufferSize;
177 
179  MAKRti::DtU32 mySockSendBufferSize;
180 
182  std::list<DtTcpSocketMgrCbInfo> myAdditionCallbacks;
183 
185  std::list<DtTcpSocketMgrCbInfo> myRemovalCallbacks;
186 
188  MAKRti::DtString myLastError;
189 
190  static const MAKRti::DtU32 theDefaultSockOpts;
191  static const MAKRti::DtU32 theSockOptNonBlocking;
192 };
193 
195 {
196  return mySockets;
197 }
198 
199 inline DtTcpMsgSocketMap::iterator DtTcpMsgSocketMgr::socketIter(DtTcpMsgSocket* sock)
200 {
201  DtTcpMsgSocketMap::iterator iter = mySockets.end();
202  if(sock)
203  {
204  MAKRti::DtInetTcpSocket* inetSock = sock->inetTcpSocket();
205  if(inetSock)
206  {
207  iter = mySockets.find(inetSock);
208  }
209  }
210  return iter;
211 }
212 
213 inline MAKRti::DtString DtTcpMsgSocketMgr::getLastError() const
214 {
215  return myLastError;
216 }
217 
218 #endif
void * myUsr
Definition: tcpMsgSocketMgr.h:38
DtTcpSocketMgrCbInfo(DtTcpSocketAdditionCallback cb, void *usr)
Definition: tcpMsgSocketMgr.h:26
void(* DtTcpSocketAdditionCallback)(DtTcpMsgSocket *sock, void *usr)
Socket addition and removal callback signatures.
Definition: tcpMsgSocketMgr.h:19
std::list< DtTcpSocketMgrCbInfo > myAdditionCallbacks
Socket addition callbacks.
Definition: tcpMsgSocketMgr.h:182
Definition: tcpMsgSocketMgr.h:43
MAKRti::DtU32 mySockRecvBufferSize
The receive buffer size for managed sockets.
Definition: tcpMsgSocketMgr.h:176
DtUniquePtr< MAKRti::DtInetSocketMgr > mySocketMgr
The underlying socket manager.
Definition: tcpMsgSocketMgr.h:151
MAKRti::DtInetTcpSocket * inetTcpSocket()
Returns a pointer to the MAKRti::DtInetTcpSocket.
Definition: tcpMsgSocket.h:230
bool operator==(const DtTcpSocketMgrCbInfo &rhs)
Definition: tcpMsgSocketMgr.h:32
MAKRti::DtString myLastError
Description of the last error.
Definition: tcpMsgSocketMgr.h:188
size_t myMaxBundleSize
The maximum size of outgoing message bundles.
Definition: tcpMsgSocketMgr.h:170
static const MAKRti::DtU32 theDefaultSockOpts
Definition: tcpMsgSocketMgr.h:190
static const MAKRti::DtU32 theSockOptNonBlocking
Definition: tcpMsgSocketMgr.h:191
MAKRti::DtU8 myCompressionLevel
The maximum size of outgoing message bundles.
Definition: tcpMsgSocketMgr.h:173
MAKRti::DtString getLastError() const
Get a description of the last error.
Definition: tcpMsgSocketMgr.h:213
Definition: tcpMsgSocketMgr.h:22
size_t myRecvBufferSize
The size of the sockets&#39; receive buffers.
Definition: tcpMsgSocketMgr.h:164
The DtTcpMsgSocket class provides an address family independent TCP socket that handles RTI messages...
Definition: tcpMsgSocket.h:40
bool isListening() const
Returns true if the socket is open.
Definition: tcpMsgSocketMgr.h:141
std::map< MAKRti::DtInetTcpSocket *, DtTcpMsgSocket * > DtTcpMsgSocketMap
Definition: tcpMsgSocketMgr.h:41
DtTcpMsgSocketMap & socketSet()
Returns the list of sockets managed by this manager.
Definition: tcpMsgSocketMgr.h:194
MAKRti::DtU32 mySockSendBufferSize
The send buffer size for managed sockets.
Definition: tcpMsgSocketMgr.h:179
int myMaxQueuedMessages
The maximum size the send queue for each socket is allowed to reach.
Definition: tcpMsgSocketMgr.h:161
DtTcpSocketAdditionCallback DtTcpSocketRemovalCallback
Definition: tcpMsgSocketMgr.h:20
bool myTcpNoDelay
The sockets&#39; TCP_NODELAY setting.
Definition: tcpMsgSocketMgr.h:167
This file contains the declaration of the DtTcpMsgSocket base class.
std::list< DtTcpSocketMgrCbInfo > myRemovalCallbacks
Socket removal callbacks.
Definition: tcpMsgSocketMgr.h:185
DtTcpMsgSocketMap::iterator socketIter(DtTcpMsgSocket *sock)
Returns the iterator for the given socket, if the socket is managed by this manager.
Definition: tcpMsgSocketMgr.h:199
#define DT_DLL_RTIUTIL
Definition: rtiMsConfig.h:160
std::shared_ptr< DtMsgHeaderReader > myHeaderReader
The message header reader to be used by all managed sockets.
Definition: tcpMsgSocketMgr.h:158
DtTcpSocketAdditionCallback myCb
Definition: tcpMsgSocketMgr.h:37
DtTcpMsgSocketMap mySockets
List of sockets managed by this manager, mapped by the underlying MAKRti::DtInetTcpSocket.
Definition: tcpMsgSocketMgr.h:155

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)