VR-Link API Documentation for HLA Evolved
 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 <vlutil/vlTime.h>
19 #include <deque>
20 #include <map>
21 
22 #ifdef DtUSE_UTILITIES_NAMESPACE
23 namespace DtUSE_UTILITIES_NAMESPACE
24 {
25 #endif
26 
33 #define DtRead ((DtU32) 0x01)
34 
35 #define DtWrite ((DtU32) 0x02)
36 
37 #define DtReadWrite (DtRead | DtWrite)
38 
39 
40 
41 
42 
43 
44 #define DtBindToDestAddr ((DtU32) 0x08)
45 
46 
47 
48 
49 #define DtQuiet ((DtU32) 0x10)
50 
55 #define DtSockOptStrictMulticastBinding ((DtU32) 0x20)
56 
57 #ifdef _WIN32
58 #define DtSockOptNonBlocking ((DtU32) 0x40) // MSG_DONTWAIT not supported
59 #else // !_WIN32
60 // Not sure if MSG_DONTWAIT is supported on Solaris, Irix, etc...
61 #define DtSockOptNonBlocking ((DtU32) MSG_DONTWAIT)
62 #endif
63 
64 
65 #define DtSockOptNoDelay ((DtU32) 0x80)
66 
67 
68 
69 
70 
71 
72 
73 #define DtSockAsyncRead ((DtU32) 0x100)
74 #define DtSockAsyncWrite ((DtU32) 0x200)
75 #define DtAsyncReadWrite (DtSockAsyncRead | DtSockAsyncWrite)
76 #define DtSockWriteable ((DtU32)DtWrite | DtSockAsyncWrite)
77 #define DtSockReadable ((DtU32)DtRead | DtSockAsyncRead)
78 
79 
80 #define DtSockOptAddrReuse ((DtU32) 0x400)
81 #define DtSockOptPortReuse ((DtU32) 0x800)
82 #define DtSockOptAllReuse (DtSockOptAddrReuse | DtSockOptPortReuse)
83 
84 
85 #define DtSockDisablePreProcCallbacks ((DtU32) 0x1000)
86 #define DtSockDisablePostProcCallbacks ((DtU32) 0x2000)
87 #define DtSockDisableCallbacks (DtSockDisablePreProcCallbacks || DtSockDisablePostProcCallbacks)
88 // By default client sockets will be configured for blocking mode, read-write
89 // operation, address and port reuse enabled (UDP), NODELAY (TCP) operation.
90 #define DtDefaultSockOpts (DtU32)(DtReadWrite | DtSockOptAllReuse | DtSockOptNoDelay)
91 
94 class DtInetSocket;
95 
103 // STOPPED HERE -- use shared_ptr for buffers see Boost documentation on reference-counted buffers
104 typedef std::vector<char> DtInetBuffer;
105 typedef std::vector<DtInetBuffer*> DtInetBufferChain;
106 typedef std::pair<void*, DtInetBuffer*> DtInetBuffQueueEntry;
109 
113 {
125 
126 };
127 
130 {
137  // Any value greater than NO_PACKET represents
138  // the number of bytes received
140 
141 };
142 
145 {
149 
150 };
151 
154 {
159 };
160 
172 typedef int (*DtInetSocketProcessingCallback)( DtInetSocket* sock, int size,
173  DtInetBufferChain& buffChain,
174  DtInetEndpoint& ep, void* usr);
177 {
178 public:
179 
181  int order )
182  {
183  myCb = cb;
184  myUsr = usr;
185  myCallOrder = order;
186  }
187 
189  void* myUsr;
191 };
192 typedef std::multimap<int, DtInetSocketProcessingCbInfo*> DtInetSockCallbackList;
193 
195 
202 {
203 public:
204 
208  DtInetSocket();
209 
211  virtual ~DtInetSocket();
212 
219  virtual bool setDestination( const DtInetEndpoint& dest ) = 0;
220  virtual const DtInetEndpoint& destination() const;
221 
226  virtual const DtInetEndpoint& localEndpoint() const;
227 
231  virtual bool setLocalPort( DtU16 port );
232  virtual DtU16 localPort() const;
233 
245  virtual bool bindToDevice( const DtInetDevice* hostIf = NULL ) = 0;
246 
252  virtual const DtInetDevice* hostIf() const;
253 
258  virtual bool openSocket() = 0;
259 
264  virtual bool closeSocket() = 0;
265 
274  virtual bool connectToDestination() = 0;
275 
281 
284  virtual int send( caddr_t packet, size_t size, DtU32 flags = 0 ) = 0;
285  virtual int sendTo( caddr_t packet, size_t size,
286  DtInetEndpoint& dest, DtU32 flags = 0 ) = 0;
287 
291  virtual int sendChain( DtInetBufferChain& packets, DtU32 flags = 0 ) = 0;
292 
293  virtual int sendChainTo( DtInetBufferChain& packets,
294  DtInetEndpoint& dest, DtU32 flags = 0 ) = 0;
296 
306 
309  virtual DtInetSockRcvStatus recv( caddr_t buff, size_t buffSize,
310  DtU32 flags = 0 ) = 0;
311 
316  virtual DtInetSockRcvStatus recvToChain( DtInetBufferChain& packets,
317  DtU32 flags = 0 ) = 0;
318 
321  virtual DtInetSockRcvStatus recvFrom( caddr_t buff, size_t buffSize,
322  DtInetEndpoint& src, DtU32 flags = 0 ) = 0;
323 
324  virtual DtInetSockRcvStatus recvToChainFrom( DtInetBufferChain& packets,
325  DtInetEndpoint& src, DtU32 flags = 0 ) = 0;
327 
329  virtual DtInetSockState state();
330 
337  virtual bool isOk();
338 
340  virtual DtU32 protocol() const;
341 
343  virtual DtInetUtils::DtInetAddrFamily family() const;
344 
346  virtual unsigned descriptor() const = 0;
347 
349  virtual DtU32 flags() { return myFlags; }
350 
357  virtual bool setSocket( const DtInetEndpoint& dest, DtU16 localPort = 0,
358  DtInetDevice* hostIf = NULL, DtU32 flags = DtDefaultSockOpts ) = 0;
359 
367  virtual bool setNonBlockingOption( bool onOrOff ) = 0;
368  virtual bool setReuseAddressOption( bool onOrOff ) = 0;
369  virtual bool setSendBufferSize( DtU32 size ) = 0;
370  virtual bool setReceiveBufferSize( DtU32 size ) = 0;
371  virtual bool setDoNotRouteOption( bool onOrOff ) = 0;
372  virtual bool setSendLowWatermark( DtU32 size ) = 0;
373  virtual bool setReceiveLowWatermark( DtU32 size ) = 0;
374 
375  virtual bool isNonBlocking() const;
376  virtual bool isNoDelay() const;
377  virtual bool getReuseAddressOption() = 0;
378  virtual bool getDoNotRouteOption() = 0;
379  virtual DtU32 getSendBufferSize() = 0;
380  virtual DtU32 getReceiveBufferSize() = 0;
381  virtual DtU32 getBytesAvailable() = 0;
382  virtual DtU32 getSendLowWatermark() = 0;
383  virtual DtU32 getReceiveLowWatermark() = 0;
385 
388  virtual bool isIPv4() const;
389  virtual bool isIPv6() const;
390  virtual bool isTcp() const;
391  virtual bool isUdp() const;
393 
395  virtual int getLastError();
396  virtual DtString getLastErrorString();
397  virtual bool isErrorWouldBlockOrTryAgain();
398  virtual void clearError();
399 
401  virtual int getTerminationCode();
402  virtual DtString getTerminationString();
403 
410  virtual DtU64 totalBytesSent() const;
411  virtual DtU64 totalPacketsSent() const;
412  virtual DtU64 totalBytesReceived() const;
413  virtual DtU64 totalPacketsReceived() const;
414 
416  virtual void clearStats();
417 
424  virtual bool addProcessingCallback( DtInetSockProcessingType kind,
425  DtInetSocketProcessingCallback cb, void* usr, int callSequence = -1 );
426 
427  virtual bool removeProcessingCallback( DtInetSockProcessingType kind,
429 
430  // Absolute time of arrival of the datagram just read
431  virtual DtTime receiveTime() { return myReceiveTime; }
432 
433 #ifdef _WIN32
434 
438  inline HANDLE getReadHandle() const { return myInetReadHandle; }
439 #endif
440 
441 protected:
442  virtual bool findAndRemoveCallback( DtInetSockCallbackList& cbList,
444 
445 private:
447  DtInetSocket( const DtInetSocket& orig );
448 
450  DtInetSocket& operator=(const DtInetSocket& orig);
451 
452 protected:
453 #ifdef _WIN32
454  HANDLE myInetReadHandle;
455 #endif
456 
459 
461 
463 
465  bool myAsync;
469 
472 
475 
480 
481  // For internal statistics only
486 
487  // Absolute time of arrival of the datagram just read
489 };
490 // end of class DtInetSocket
491 
493 {
494  return mySentByteCount;
495 }
496 
498 {
499  return mySentPacketCount;
500 }
501 
503 {
504  return myReceivedByteCount;
505 }
506 
508 {
509  return myReceivedPacketCount;
510 }
511 
513 {
514  mySentByteCount = 0;
515  mySentPacketCount = 0;
516  myReceivedByteCount = 0;
517  myReceivedPacketCount = 0;
518 }
519 
522 {
523  bool found = false;
524  DtInetSockCallbackList::iterator iter = cbList.begin();
525  while ( !found && iter != cbList.end() )
526  {
527  if ( cb == iter->second->myCb )
528  {
529  DtDELETE(iter->second);
530  cbList.erase( iter );
531  found = true;
532  }
533  else
534  {
535  ++iter;
536  }
537  }
538 
539  return found;
540 }
541 
542 #ifdef DtUSE_UTILITIES_NAMESPACE
543 }
544 #endif
545 
546 
547 

Document ID: Generated on Mon Apr 8 04:49:21 EDT 2019 from SVN revision 197403
Copyright © 2005-2016 VT MÄK. All Rights Reserved (www.mak.com)