MAK RTIspy API Documentation for HLA 1516
 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 
18 using namespace MAKRti;
19 
21 typedef void (*DtTcpSocketAdditionCallback)(DtTcpMsgSocket* sock, void* usr);
23 
25 {
26 public:
27 
29  {
30  myCb = cb;
31  myUsr = usr;
32  }
33 
35  {
36  return (myCb == rhs.myCb && myUsr == rhs.myUsr);
37  }
38 
40  void* myUsr;
41 };
42 
43 typedef std::map<DtInetTcpSocket*, DtTcpMsgSocket*> DtTcpMsgSocketMap;
44 
46 {
47 public:
48 
50  DtTcpMsgSocketMgr(DtBoost::shared_ptr<DtMsgHeaderReader> hdrReader,
51  size_t recvBufferSize = 20000, int maxQueuedMsgs = -1);
52 
54  virtual ~DtTcpMsgSocketMgr();
55 
63  virtual bool openServerSocket( DtU16 localPort, DtInetDevice* hostIf = NULL,
64  DtInetUtils::DtInetAddrFamily family = DtInetUtils::DtInetAddrFamily_IPv4,
65  DtU32 flags = (DtDefaultSockOpts | DtSockOptNonBlocking) );
66 
67  void processNewConnections();
68 
73  virtual void processConnections();
74 
77  virtual void addSocket(DtTcpMsgSocket* sock);
78 
80  static bool socketAdded(DtInetSocket* sock, void* usr);
81  bool socketAdded(DtInetSocket* sock);
82 
83  DtTcpMsgSocketMap::iterator checkIfReconnecting(const DtInetTcpSocket * newSock);
87  virtual void addSocketAdditionCallback(DtTcpSocketAdditionCallback cb,
88  void* usr);
89  virtual void removeSocketAdditionCallback(DtTcpSocketAdditionCallback cb,
90  void* usr);
92 
94  static bool socketRemoved(DtInetSocket* sock, void* usr);
95  bool socketRemoved(DtInetSocket* sock);
96 
100  virtual void addSocketRemovalCallback(DtTcpSocketRemovalCallback cb,
101  void* usr);
102  virtual void removeSocketRemovalCallback(DtTcpSocketRemovalCallback cb,
103  void* usr);
105 
107  virtual void removeAndDelete(DtTcpMsgSocket* sock);
108 
110  virtual void enableBundling(size_t maxBundleSize);
111 
113  virtual void disableBundling();
114 
116  virtual void enableCompression(DtU8 compressionLevel);
117 
119  virtual void disableCompression();
120 
122  virtual void setTcpNoDelay(bool enable);
123 
125  virtual void setSendBufferSize(DtU32 size);
126 
128  virtual void setRecvBufferSize(DtU32 size);
129 
131  virtual DtInetSockState serverSocketState() const;
132 
134  virtual DtU32 maxMsgSize() const;
135 
137  DtTcpMsgSocketMap& socketSet();
138 
141  DtTcpMsgSocketMap::iterator socketIter(DtTcpMsgSocket* sock);
142 
144  DtString getLastError() const;
145 
147  bool isListening() const { return serverSocketState() == DtInetSockState_LISTENING; }
148 
149 private:
150 
152  DtTcpMsgSocketMgr& operator=(const DtTcpMsgSocketMgr&);
153 
154 protected:
155 
157  std::auto_ptr<DtInetSocketMgr> mySocketMgr;
158 
162 
164  DtBoost::shared_ptr<DtMsgHeaderReader> myHeaderReader;
165 
168 
171 
174 
177 
179  MAKRti::DtU8 myCompressionLevel;
180 
182  MAKRti::DtU32 mySockRecvBufferSize;
183 
185  MAKRti::DtU32 mySockSendBufferSize;
186 
188  std::list<DtTcpSocketMgrCbInfo> myAdditionCallbacks;
189 
191  std::list<DtTcpSocketMgrCbInfo> myRemovalCallbacks;
192 
194  DtString myLastError;
195 };
196 
198 {
199  return mySockets;
200 }
201 
202 inline DtTcpMsgSocketMap::iterator DtTcpMsgSocketMgr::socketIter(DtTcpMsgSocket* sock)
203 {
204  DtTcpMsgSocketMap::iterator iter = mySockets.end();
205  if(sock)
206  {
207  DtInetTcpSocket* inetSock = sock->inetTcpSocket();
208  if(inetSock)
209  {
210  iter = mySockets.find(inetSock);
211  }
212  }
213  return iter;
214 }
215 
216 inline DtString DtTcpMsgSocketMgr::getLastError() const
217 {
218  return myLastError;
219 }
220 
221 #endif
void * myUsr
Definition: tcpMsgSocketMgr.h:40
DtTcpSocketMgrCbInfo(DtTcpSocketAdditionCallback cb, void *usr)
Definition: tcpMsgSocketMgr.h:28
void(* DtTcpSocketAdditionCallback)(DtTcpMsgSocket *sock, void *usr)
Socket addition and removal callback signatures.
Definition: tcpMsgSocketMgr.h:21
std::list< DtTcpSocketMgrCbInfo > myAdditionCallbacks
Socket addition callbacks.
Definition: tcpMsgSocketMgr.h:188
std::map< DtInetTcpSocket *, DtTcpMsgSocket * > DtTcpMsgSocketMap
Definition: tcpMsgSocketMgr.h:43
Definition: tcpMsgSocketMgr.h:45
MAKRti::DtU32 mySockRecvBufferSize
The receive buffer size for managed sockets.
Definition: tcpMsgSocketMgr.h:182
std::auto_ptr< DtInetSocketMgr > mySocketMgr
The underlying socket manager.
Definition: tcpMsgSocketMgr.h:157
bool operator==(const DtTcpSocketMgrCbInfo &rhs)
Definition: tcpMsgSocketMgr.h:34
DtBoost::shared_ptr< DtMsgHeaderReader > myHeaderReader
The message header reader to be used by all managed sockets.
Definition: tcpMsgSocketMgr.h:164
size_t myMaxBundleSize
The maximum size of outgoing message bundles.
Definition: tcpMsgSocketMgr.h:176
DtInetTcpSocket * inetTcpSocket()
Returns a pointer to the DtInetTcpSocket.
Definition: tcpMsgSocket.h:231
MAKRti::DtU8 myCompressionLevel
The maximum size of outgoing message bundles.
Definition: tcpMsgSocketMgr.h:179
Definition: tcpMsgSocketMgr.h:24
size_t myRecvBufferSize
The size of the sockets&#39; receive buffers.
Definition: tcpMsgSocketMgr.h:170
The DtTcpMsgSocket class provides an address family independent TCP socket that handles RTI messages...
Definition: tcpMsgSocket.h:42
bool isListening() const
Returns true if the socket is open.
Definition: tcpMsgSocketMgr.h:147
DtTcpMsgSocketMap & socketSet()
Returns the list of sockets managed by this manager.
Definition: tcpMsgSocketMgr.h:197
MAKRti::DtU32 mySockSendBufferSize
The send buffer size for managed sockets.
Definition: tcpMsgSocketMgr.h:185
int myMaxQueuedMessages
The maximum size the send queue for each socket is allowed to reach.
Definition: tcpMsgSocketMgr.h:167
DtTcpSocketAdditionCallback DtTcpSocketRemovalCallback
Definition: tcpMsgSocketMgr.h:22
bool myTcpNoDelay
The sockets&#39; TCP_NODELAY setting.
Definition: tcpMsgSocketMgr.h:173
This file contains the declaration of the DtTcpMsgSocket base class.
std::list< DtTcpSocketMgrCbInfo > myRemovalCallbacks
Socket removal callbacks.
Definition: tcpMsgSocketMgr.h:191
DtString myLastError
Description of the last error.
Definition: tcpMsgSocketMgr.h:194
DtTcpMsgSocketMap::iterator socketIter(DtTcpMsgSocket *sock)
Returns the iterator for the given socket, if the socket is managed by this manager.
Definition: tcpMsgSocketMgr.h:202
#define DT_DLL_RTIUTIL
Definition: rtiMsConfig.h:127
DtString getLastError() const
Get a description of the last error.
Definition: tcpMsgSocketMgr.h:216
DtTcpSocketAdditionCallback myCb
Definition: tcpMsgSocketMgr.h:39
DtTcpMsgSocketMap mySockets
List of sockets managed by this manager, mapped by the underlying DtInetTcpSocket.
Definition: tcpMsgSocketMgr.h:161

Document ID: Generated on Mon Sep 7 15:40:32 EDT 2020 from SVN revision 217499
Copyright © 2005-2020 MAK Technologies Inc. All Rights Reserved (www.mak.com)