VR-Link API Documentation for DIS
vlInetSocket.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 1992-2010 VT MAK
3 ** All rights reserved.
4 *********************************************************************/
9 #pragma once
10 
11 #include <vlutil/vlInet.h>
12 #include <vlutil/vlInetAddr.h>
13 #include <vlutil/vlInetAddrUtils.h>
14 #include <vlutil/vlInetDevice.h>
15 #include <vlutil/vlInetEndpoint.h>
16 #include <vlutil/vlThreadSafe.h>
17 #include <vlutil/vlString.h>
18 #include <deque>
19 #include <map>
20 
21 #ifdef DtUSE_UTILITIES_NAMESPACE
22 namespace DtUSE_UTILITIES_NAMESPACE
23 {
24 #endif
25 
32 #define DtRead ((DtU32) 0x01)
33 
34 #define DtWrite ((DtU32) 0x02)
35 
36 #define DtReadWrite (DtRead | DtWrite)
37 
38 
39 
40 
41 
42 
43 #define DtBindToDestAddr ((DtU32) 0x08)
44 
45 
46 
47 
48 #define DtQuiet ((DtU32) 0x10)
49 
54 #define DtSockOptStrictMulticastBinding ((DtU32) 0x20)
55 
56 #ifdef _WIN32
57 #define DtSockOptNonBlocking ((DtU32) 0x40) // MSG_DONTWAIT not supported
58 #else // !_WIN32
59 // Not sure if MSG_DONTWAIT is supported on Solaris, Irix, etc...
60 #define DtSockOptNonBlocking ((DtU32) MSG_DONTWAIT)
61 #endif
62 
63 
64 #define DtSockOptNoDelay ((DtU32) 0x80)
65 
66 
67 
68 
69 
70 
71 
72 #define DtSockAsyncRead ((DtU32) 0x100)
73 #define DtSockAsyncWrite ((DtU32) 0x200)
74 #define DtAsyncReadWrite (DtSockAsyncRead | DtSockAsyncWrite)
75 #define DtSockWriteable ((DtU32)DtWrite | DtSockAsyncWrite)
76 #define DtSockReadable ((DtU32)DtRead | DtSockAsyncRead)
77 
78 
79 #define DtSockOptAddrReuse ((DtU32) 0x400)
80 #define DtSockOptPortReuse ((DtU32) 0x800)
81 #define DtSockOptAllReuse (DtSockOptAddrReuse | DtSockOptPortReuse)
82 
83 
84 #define DtSockDisablePreProcCallbacks ((DtU32) 0x1000)
85 #define DtSockDisablePostProcCallbacks ((DtU32) 0x2000)
86 #define DtSockDisableCallbacks (DtSockDisablePreProcCallbacks || DtSockDisablePostProcCallbacks)
87 // By default client sockets will be configured for blocking mode, read-write
88 // operation, address and port reuse enabled (UDP), NODELAY (TCP) operation.
89 #define DtDefaultSockOpts (DtU32)(DtReadWrite | DtSockOptAllReuse | DtSockOptNoDelay)
90 
93 class DtInetSocket;
94 
102 // STOPPED HERE -- use shared_ptr for buffers see Boost documentation on reference-counted buffers
103 typedef std::vector<char> DtInetBuffer;
104 typedef std::vector<DtInetBuffer*> DtInetBufferChain;
105 typedef std::pair<void*, DtInetBuffer*> DtInetBuffQueueEntry;
107 
111 {
123 
124 };
125 
128 {
135  // Any value greater than NO_PACKET represents
136  // the number of bytes received
138 
139 };
140 
143 {
147 
148 };
149 
152 {
157 };
158 
170 typedef int (*DtInetSocketProcessingCallback)( DtInetSocket* sock, int size,
171  DtInetBufferChain& buffChain,
172  DtInetEndpoint& ep, void* usr);
175 {
176 public:
177 
179  int order )
180  {
181  myCb = cb;
182  myUsr = usr;
183  myCallOrder = order;
184  }
185 
187  void* myUsr;
189 };
190 typedef std::multimap<int, DtInetSocketProcessingCbInfo*> DtInetSockCallbackList;
191 
193 
200 {
201 public:
202 
206  DtInetSocket();
207 
209  virtual ~DtInetSocket();
210 
217  virtual bool setDestination( const DtInetEndpoint& dest ) = 0;
218  virtual const DtInetEndpoint& destination() const;
219 
224  virtual const DtInetEndpoint& localEndpoint() const;
225 
229  virtual bool setLocalPort( DtU16 port );
230  virtual DtU16 localPort() const;
231 
243  virtual bool bindToDevice( const DtInetDevice* hostIf = NULL ) = 0;
244 
250  virtual const DtInetDevice* hostIf() const;
251 
256  virtual bool openSocket() = 0;
257 
262  virtual bool closeSocket() = 0;
263 
272  virtual bool connectToDestination() = 0;
273 
279 
282  virtual int send( caddr_t packet, size_t size, DtU32 flags = 0 ) = 0;
283  virtual int sendTo( caddr_t packet, size_t size,
284  DtInetEndpoint& dest, DtU32 flags = 0 ) = 0;
285 
289  virtual int sendChain( DtInetBufferChain& packets, DtU32 flags = 0 ) = 0;
290 
291  virtual int sendChainTo( DtInetBufferChain& packets,
292  DtInetEndpoint& dest, DtU32 flags = 0 ) = 0;
294 
304 
307  virtual DtInetSockRcvStatus recv( caddr_t buff, size_t buffSize,
308  DtU32 flags = 0 ) = 0;
309 
314  virtual DtInetSockRcvStatus recvToChain( DtInetBufferChain& packets,
315  DtU32 flags = 0 ) = 0;
316 
319  virtual DtInetSockRcvStatus recvFrom( caddr_t buff, size_t buffSize,
320  DtInetEndpoint& src, DtU32 flags = 0 ) = 0;
321 
322  virtual DtInetSockRcvStatus recvToChainFrom( DtInetBufferChain& packets,
323  DtInetEndpoint& src, DtU32 flags = 0 ) = 0;
325 
327  virtual DtInetSockState state();
328 
335  virtual bool isOk();
336 
338  virtual DtU32 protocol() const;
339 
341  virtual DtInetUtils::DtInetAddrFamily family() const;
342 
344  virtual int descriptor() const = 0;
345 
352  virtual bool setSocket( const DtInetEndpoint& dest, DtU16 localPort = 0,
353  DtInetDevice* hostIf = NULL, DtU32 flags = DtDefaultSockOpts ) = 0;
354 
362  virtual bool setNonBlockingOption( bool onOrOff ) = 0;
363  virtual bool setReuseAddressOption( bool onOrOff ) = 0;
364  virtual bool setSendBufferSize( DtU32 size ) = 0;
365  virtual bool setReceiveBufferSize( DtU32 size ) = 0;
366  virtual bool setDoNotRouteOption( bool onOrOff ) = 0;
367  virtual bool setSendLowWatermark( DtU32 size ) = 0;
368  virtual bool setReceiveLowWatermark( DtU32 size ) = 0;
369 
370  virtual bool isNonBlocking() const;
371  virtual bool isNoDelay() const;
372  virtual bool getReuseAddressOption() = 0;
373  virtual bool getDoNotRouteOption() = 0;
374  virtual DtU32 getSendBufferSize() = 0;
375  virtual DtU32 getReceiveBufferSize() = 0;
376  virtual DtU32 getBytesAvailable() = 0;
377  virtual DtU32 getSendLowWatermark() = 0;
378  virtual DtU32 getReceiveLowWatermark() = 0;
380 
383  virtual bool isIPv4() const;
384  virtual bool isIPv6() const;
385  virtual bool isTcp() const;
386  virtual bool isUdp() const;
388 
390  virtual int getLastError();
391  virtual DtString getLastErrorString();
392  virtual bool isErrorWouldBlockOrTryAgain();
393  virtual void clearError();
394 
396  virtual int getTerminationCode();
397  virtual DtString getTerminationString();
398 
405  virtual DtU64 totalBytesSent() const;
406  virtual DtU64 totalPacketsSent() const;
407  virtual DtU64 totalBytesReceived() const;
408  virtual DtU64 totalPacketsReceived() const;
409 
411  virtual void clearStats();
412 
419  virtual bool addProcessingCallback( DtInetSockProcessingType kind,
420  DtInetSocketProcessingCallback cb, void* usr, int callSequence = -1 );
421 
422  virtual bool removeProcessingCallback( DtInetSockProcessingType kind,
424 
425 protected:
426  virtual bool findAndRemoveCallback( DtInetSockCallbackList& cbList,
428 
429 private:
431  DtInetSocket( const DtInetSocket& orig );
432 
434  DtInetSocket& operator=(const DtInetSocket& orig);
435 
436 protected:
439 
441 
443 
445  bool myAsync;
449 
452 
455 
460 
461  // For internal statistics only
466 
467 };
468 // end of class DtInetSocket
469 
471 {
472  return mySentByteCount;
473 }
474 
476 {
477  return mySentPacketCount;
478 }
479 
481 {
482  return myReceivedByteCount;
483 }
484 
486 {
487  return myReceivedPacketCount;
488 }
489 
491 {
492  mySentByteCount = 0;
493  mySentPacketCount = 0;
494  myReceivedByteCount = 0;
495  myReceivedPacketCount = 0;
496 }
497 
500 {
501  bool found = false;
502  DtInetSockCallbackList::iterator iter = cbList.begin();
503  while ( !found && iter != cbList.end() )
504  {
505  if ( cb == iter->second->myCb )
506  {
507  DtDELETE(iter->second);
508  cbList.erase( iter );
509  found = true;
510  }
511  else
512  {
513  ++iter;
514  }
515  }
516 
517  return found;
518 }
519 
520 #ifdef DtUSE_UTILITIES_NAMESPACE
521 }
522 #endif
523 
524 
525 

Document ID: Generated on Wed Oct 23 22:25:48 EDT 2013 from SVN revision 132765
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)