MAK RTIspy API Documentation for HLA 1.3
 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 
71  virtual void processConnections();
72 
75  virtual void addSocket(DtTcpMsgSocket* sock);
76 
78  static bool socketAdded(DtInetSocket* sock, void* usr);
79  bool socketAdded(DtInetSocket* sock);
80 
84  virtual void addSocketAdditionCallback(DtTcpSocketAdditionCallback cb,
85  void* usr);
86  virtual void removeSocketAdditionCallback(DtTcpSocketAdditionCallback cb,
87  void* usr);
89 
91  static bool socketRemoved(DtInetSocket* sock, void* usr);
92  bool socketRemoved(DtInetSocket* sock);
93 
97  virtual void addSocketRemovalCallback(DtTcpSocketRemovalCallback cb,
98  void* usr);
99  virtual void removeSocketRemovalCallback(DtTcpSocketRemovalCallback cb,
100  void* usr);
102 
104  virtual void removeAndDelete(DtTcpMsgSocket* sock);
105 
107  virtual void enableBundling(size_t maxBundleSize);
108 
110  virtual void disableBundling();
111 
113  virtual void enableCompression(DtU8 compressionLevel);
114 
116  virtual void disableCompression();
117 
119  virtual void setTcpNoDelay(bool enable);
120 
122  virtual void setSendBufferSize(DtU32 size);
123 
125  virtual void setRecvBufferSize(DtU32 size);
126 
128  virtual DtInetSockState serverSocketState() const;
129 
131  virtual DtU32 maxMsgSize() const;
132 
134  DtTcpMsgSocketMap& socketSet();
135 
138  DtTcpMsgSocketMap::iterator socketIter(DtTcpMsgSocket* sock);
139 
141  DtString getLastError() const;
142 
144  bool isListening() const { return serverSocketState() == DtInetSockState_LISTENING; }
145 
146 private:
147 
149  DtTcpMsgSocketMgr& operator=(const DtTcpMsgSocketMgr&);
150 
151 protected:
152 
154  std::auto_ptr<DtInetSocketMgr> mySocketMgr;
155 
159 
161  DtBoost::shared_ptr<DtMsgHeaderReader> myHeaderReader;
162 
165 
168 
171 
174 
176  MAKRti::DtU8 myCompressionLevel;
177 
179  MAKRti::DtU32 mySockRecvBufferSize;
180 
182  MAKRti::DtU32 mySockSendBufferSize;
183 
185  std::list<DtTcpSocketMgrCbInfo> myAdditionCallbacks;
186 
188  std::list<DtTcpSocketMgrCbInfo> myRemovalCallbacks;
189 
191  DtString myLastError;
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  DtInetTcpSocket* inetSock = sock->inetTcpSocket();
205  if(inetSock)
206  {
207  iter = mySockets.find(inetSock);
208  }
209  }
210  return iter;
211 }
212 
213 inline DtString DtTcpMsgSocketMgr::getLastError() const
214 {
215  return myLastError;
216 }
217 
218 #endif

Document ID: Generated on Wed Mar 11 20:26:49 EDT 2015 from SVN revision 150939
Copyright © 2005-2015 VT MÄK Inc. All Rights Reserved (www.mak.com)