VR-Link API Documentation for HLA Evolved
 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 
This file contains the declaration of the DtInetSocket base class.
Definition: vlInetAddrUtils.h:58
DtInetSocketAdditionCallback myCb
Definition: vlInetSocketMgr.h:48
std::multimap< DtInetEndpoint, DtInetSocket * > DtInetSocketList
Definition: vlInetSocketMgr.h:23
DtInetSockRcvStatus
Socket state enumeration.
Definition: vlInetSocket.h:129
std::map< int, DtInetSocketCbInfo * > myAdditionCallbacks
Definition: vlInetSocketMgr.h:268
std::vector< DtInetBuffer * > DtInetBufferChain
Socket state enumeration.
Definition: vlInetSocket.h:105
DtSocket *(* DtSocketCreationCallback)(void *creator, DtTcpSocketMgr *mgr)
Specialized socket creation callback signature.
Definition: vlTcpSocketMgr.h:33
The DtInetSocket class provides a protocol independant, address family independant base class for TCP...
Definition: vlInetSocket.h:201
DtInetSocketCbInfo(DtInetSocketAdditionCallback cb, void *usr, int order)
Definition: vlInetSocketMgr.h:41
DtU32 myServerFlags
Definition: vlInetSocketMgr.h:274
std::pair< DtInetEndpoint, DtInetSocket * > myLastSocketReadFrom
Definition: vlInetSocketMgr.h:266
DtInetSocketList mySockets
Definition: vlInetSocketMgr.h:264
DtU32 myConnectionFlags
Definition: vlInetSocketMgr.h:275
This file contains the declaration of the DtInetEndpoint class.
DtInetAddrFamily
Definition: vlInetAddrUtils.h:55
The DtInetEndpoint class provides a protocol independant, address family independent mechanism to rep...
Definition: vlInetEndpoint.h:33
DtSocketCreationCallback mySocketCreateCallback
Definition: vlInetSocketMgr.h:271
int myErrorCode
Definition: vlInetSocketMgr.h:277
std::map< int, DtInetSocketCbInfo * > myRemovalCallbacks
Definition: vlInetSocketMgr.h:269
DtInetTcpSocket * myPeerSocket
The next peer socket to be returned.
Definition: vlInetSocketMgr.h:281
Definition: vlInetDevice.h:101
DtInetSocket * myServerSocket
Definition: vlInetSocketMgr.h:261
int socket(int, int, int)
void * mySocketCreator
Definition: vlInetSocketMgr.h:272
Definition: vlInetSocketMgr.h:53
DtInetUdpSocket * myUdpServerSocket
Definition: vlInetSocketMgr.h:263
DtString myErrorString
Definition: vlInetSocketMgr.h:278
unsigned short DtU16
A 16 bit unsigned integer value.
Definition: vlMachineTypes.h:140
std::vector< DtInetEndpoint * > DtInetDestList
Definition: vlInetSocketMgr.h:26
DtInetSocketAdditionCallback DtInetSocketRemovalCallback
Definition: vlInetSocketMgr.h:36
An abstract base class to represent a Socket Type.
Definition: vlInetUdpSocket.h:24
#define DtSockOptNonBlocking
Tells the socket to operate in non-blocking mode when set.
Definition: vlInetSocket.h:61
void * myUsr
Definition: vlInetSocketMgr.h:49
unsigned long DtU32
A 32 bit unsigned integer value.
Definition: vlMachineTypes.h:153
Instances of DtString are used to represent strings.
Definition: vlString.h:29
bool(* DtInetSocketAdditionCallback)(DtInetSocket *sock, void *usr)
Definition: vlInetSocketMgr.h:35
int myCallOrder
Definition: vlInetSocketMgr.h:50
Definition: vlInetSocketMgr.h:37
The DtInetSocket class provides an address family independent stream socket.
Definition: vlInetTcpSocket.h:23
#define DtDefaultSockOpts
Marks the Socket as Writable.
Definition: vlInetSocket.h:90
DtInetTcpSocket * myTcpServerSocket
Definition: vlInetSocketMgr.h:262
This file declares useful defaults constants and static methods employed with the networking abstract...
#define DT_DLL_VLUTIL
Definition: vlMachineTypes.h:109

Document ID: Generated on Tue Feb 2 21:02:17 EST 2021 from SVN revision 223668
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)