VR-Link API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vlInetSocketMgr.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Copyright (c) 1992-2010 VT MAK
3 ** All rights reserved.
4 *********************************************************************/
8 #pragma once
9 
10 #include <vlutil/vlInet.h>
11 #include <vlutil/vlInetSocket.h>
12 #include <vlutil/vlInetEndpoint.h>
13 #include <list>
14 #include <vector>
15 #include <map>
16 
17 #ifdef DtUSE_UTILITIES_NAMESPACE
18 namespace DtUSE_UTILITIES_NAMESPACE
19 {
20 #endif
21 
22 class DtInetTcpSocket;
24 
25 typedef std::multimap<DtInetEndpoint, DtInetSocket*> DtInetSocketList;
26 typedef std::vector<DtInetEndpoint*> DtInetDestList;
27 
28 // Forward declaration to facilitate declaration of socket creation callback
29 // prototype
30 class DtInetSocketMgr;
31 
33 typedef DtInetSocket* (*DtSocketCreationCallback)(void* creator, DtInetSocketMgr * mgr);
34 
35 typedef bool (*DtInetSocketAdditionCallback)(DtInetSocket* sock, void* usr);
38 {
39 public:
40 
42  {
43  myCb = cb;
44  myUsr = usr;
45  myCallOrder = order;
46  }
47 
49  void* myUsr;
51 };
52 
54 {
55 public:
59  DtInetSocketMgr( DtU32 connectionFlags = DtDefaultSockOpts );
60 
85  DtInetSocketMgr( DtInetEndpoint& serverEndpoint,
86  DtInetDevice* hostIf = NULL,
87  DtU32 serverFlags = (DtDefaultSockOpts | DtSockOptNonBlocking),
88  DtU32 connectionFlags = DtDefaultSockOpts,
90 
92  virtual ~DtInetSocketMgr();
93 
100  virtual int processConnections();
101 
112  virtual DtInetSocket* addConnection( const DtInetEndpoint& peerEp,
113  DtU16 localPort = 0,
114  DtInetDevice* hostIf = NULL,
115  bool openImmediately = true,
116  bool connectUdpSocket = false );
117 
122  virtual DtInetSocket* addConnection( const DtInetSocket* socket );
124 
134  virtual bool removeConnection( const DtInetEndpoint& peerEndpoint );
135  virtual bool removeConnection( const DtInetSocket* socket );
137 
140  virtual DtInetSocket* serverSocket() const;
141 
146  virtual const DtInetSocketList& socketList() const;
147 
157  virtual DtInetSocket* peerSocket( const DtInetEndpoint& peer ) const;
158 
167  virtual int sendTo( caddr_t buff, int buffSize, DtInetDestList& dest,
168  DtU32 flags = 0 );
169  virtual int sendTo( DtInetBufferChain packets, DtInetDestList& dest,
170  DtU32 flags = 0 );
172 
189  virtual DtInetSockRcvStatus recvFrom( caddr_t buff, size_t buffSize,
190  DtInetEndpoint& peer,
191  DtU32 flags = 0 );
192  virtual DtInetSockRcvStatus recvToChainFrom( DtInetBufferChain& packets,
193  DtInetEndpoint& peer,
194  DtU32 flags = 0 );
196 
205  virtual void addSocketAdditionCallback( DtInetSocketAdditionCallback cb,
206  void* usr, int order );
207  virtual void removeSocketAdditionCallback( DtInetSocketAdditionCallback cb,
208  void* usr );
210 
219  virtual void addSocketRemovalCallback( DtInetSocketRemovalCallback cb,
220  void* usr, int order );
221  virtual void removeSocketRemovalCallback( DtInetSocketRemovalCallback cb,
222  void* usr);
224 
227  virtual DtU32 getServerFlags() const;
228  virtual DtU32 getConnectionFlags() const;
230 
233  virtual int getLastError();
234  virtual DtString getLastErrorString();
235  virtual void clearError();
237 
242  virtual void addSocketCreationCallback( DtSocketCreationCallback cb,
243  void* socketCreator );
244 
245 protected:
248 
250  DtInetSocketMgr& operator=(const DtInetSocketMgr &);
251 
252  virtual int processNewTcpConnections();
253  virtual int processNewUdpConnections();
254 
255  virtual DtInetSocket* removeByKey( const DtInetEndpoint& key,
256  DtInetSocketList& list );
257  virtual bool removeByItem( const DtInetSocket* item,
258  DtInetSocketList& list );
259 
260 protected:
265 
266  std::pair<DtInetEndpoint, DtInetSocket*> myLastSocketReadFrom;
267 
268  std::map<int, DtInetSocketCbInfo*> myAdditionCallbacks;
269  std::map<int, DtInetSocketCbInfo*> myRemovalCallbacks;
270 
273 
276 
279 
282 };
283 
284 #ifdef DtUSE_UTILITIES_NAMESPACE
285 }
286 #endif
287 
288 

Document ID: Generated on Wed Jan 7 13:31:29 EST 2015 from SVN revision 149162
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)