VR-Link API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 unsigned descriptor() const = 0;
345 
347  virtual DtU32 flags() { return myFlags; }
348 
355  virtual bool setSocket( const DtInetEndpoint& dest, DtU16 localPort = 0,
356  DtInetDevice* hostIf = NULL, DtU32 flags = DtDefaultSockOpts ) = 0;
357 
365  virtual bool setNonBlockingOption( bool onOrOff ) = 0;
366  virtual bool setReuseAddressOption( bool onOrOff ) = 0;
367  virtual bool setSendBufferSize( DtU32 size ) = 0;
368  virtual bool setReceiveBufferSize( DtU32 size ) = 0;
369  virtual bool setDoNotRouteOption( bool onOrOff ) = 0;
370  virtual bool setSendLowWatermark( DtU32 size ) = 0;
371  virtual bool setReceiveLowWatermark( DtU32 size ) = 0;
372 
373  virtual bool isNonBlocking() const;
374  virtual bool isNoDelay() const;
375  virtual bool getReuseAddressOption() = 0;
376  virtual bool getDoNotRouteOption() = 0;
377  virtual DtU32 getSendBufferSize() = 0;
378  virtual DtU32 getReceiveBufferSize() = 0;
379  virtual DtU32 getBytesAvailable() = 0;
380  virtual DtU32 getSendLowWatermark() = 0;
381  virtual DtU32 getReceiveLowWatermark() = 0;
383 
386  virtual bool isIPv4() const;
387  virtual bool isIPv6() const;
388  virtual bool isTcp() const;
389  virtual bool isUdp() const;
391 
393  virtual int getLastError();
394  virtual DtString getLastErrorString();
395  virtual bool isErrorWouldBlockOrTryAgain();
396  virtual void clearError();
397 
399  virtual int getTerminationCode();
400  virtual DtString getTerminationString();
401 
408  virtual DtU64 totalBytesSent() const;
409  virtual DtU64 totalPacketsSent() const;
410  virtual DtU64 totalBytesReceived() const;
411  virtual DtU64 totalPacketsReceived() const;
412 
414  virtual void clearStats();
415 
422  virtual bool addProcessingCallback( DtInetSockProcessingType kind,
423  DtInetSocketProcessingCallback cb, void* usr, int callSequence = -1 );
424 
425  virtual bool removeProcessingCallback( DtInetSockProcessingType kind,
427 
428 #ifdef _WIN32
429 
433  inline HANDLE getReadHandle() const { return myInetReadHandle; }
434 #endif
435 
436 protected:
437  virtual bool findAndRemoveCallback( DtInetSockCallbackList& cbList,
439 
440 private:
442  DtInetSocket( const DtInetSocket& orig );
443 
445  DtInetSocket& operator=(const DtInetSocket& orig);
446 
447 protected:
448 #ifdef _WIN32
449  HANDLE myInetReadHandle;
450 #endif
451 
454 
456 
458 
460  bool myAsync;
464 
467 
470 
475 
476  // For internal statistics only
481 
482 };
483 // end of class DtInetSocket
484 
486 {
487  return mySentByteCount;
488 }
489 
491 {
492  return mySentPacketCount;
493 }
494 
496 {
497  return myReceivedByteCount;
498 }
499 
501 {
502  return myReceivedPacketCount;
503 }
504 
506 {
507  mySentByteCount = 0;
508  mySentPacketCount = 0;
509  myReceivedByteCount = 0;
510  myReceivedPacketCount = 0;
511 }
512 
515 {
516  bool found = false;
517  DtInetSockCallbackList::iterator iter = cbList.begin();
518  while ( !found && iter != cbList.end() )
519  {
520  if ( cb == iter->second->myCb )
521  {
522  DtDELETE(iter->second);
523  cbList.erase( iter );
524  found = true;
525  }
526  else
527  {
528  ++iter;
529  }
530  }
531 
532  return found;
533 }
534 
535 #ifdef DtUSE_UTILITIES_NAMESPACE
536 }
537 #endif
538 
539 
540 

Document ID: Generated on Mon Feb 6 18:36:34 EST 2017 from SVN revision 173107
Copyright © 2005-2016 VT MÄK. All Rights Reserved (www.mak.com)