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 
34  bool operator==(const DtTcpSocketMgrCbInfo& rhs)
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

Document ID: Generated on Fri Sep 27 00:57:56 EDT 2019 from SVN revision 201708
Copyright © 2005-2018 VT MÄK Inc. All Rights Reserved (www.mak.com)