VR-Link API Documentation for HLA 1516
vlInetSocketUtils.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/vlInetSocket.h>
13 
14 #ifdef DtUSE_UTILITIES_NAMESPACE
15 namespace DtUSE_UTILITIES_NAMESPACE
16 {
17 #endif
18 
19 namespace DtInetUtils
20 {
21 
22 // Each unique destination a socket sends to needs its own outbound bundle
23 // entry. The first value in the pair is the current number of bytes in all
24 // the buffer chains in the bundle. This eliminates the need to calculate the
25 // size of the bundle each time it's accessed.
26 typedef std::pair<DtU32, DtInetBufferChain> DtInetChainEntry;
27 typedef std::map<DtInetEndpoint, DtInetChainEntry> DtInetSockOutboundBundleMap;
28 
29 // The inbound bundle queue needs to store each bundle received in the order
30 // received with the source endpoint in case the application retrieving the
31 // the packets wants to know the source. So rather than storing inbound bundles
32 // separated by source endpoint a single queue is appropriate.
33 typedef std::pair<DtInetEndpoint, DtInetBuffer*> DtInetSockInboundBundleEntry;
34 typedef std::deque<DtInetSockInboundBundleEntry> DtInetSockInboundBundleQueue;
35 
40 {
41  DtNetU8 sizeFieldOffset; // bytes from start of packet
42  int sizeFieldLength; // in bytes. Valid values: 1 (DtU8), 2 (DtU16), 4 (DtU32)
43  int sizeFieldMask; // bitmask applied to size field
44 
47 #define DtInetSockPacketHeader_MASK_NONE 0x00
48 #define DtInetSockPacketHeader_MASK_DtU8 0xff
49 #define DtInetSockPacketHeader_MASK_DtU16 0xffff
50 #define DtInetSockPacketHeader_MASK_DtU32 0xffffffff
51 
52 // The default RTI header descriptor: offset = 0, length = 4, bitmask = MASK_DtU32
53 #define DtInetSockDefaultPktHdrDesc { 0, 4, DtInetSockPacketHeader_MASK_DtU32 }
54 
55 #if 0
56 // STOPPED HERE --- move to socket subclass header
57 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
58 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
59 // v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v
60  // Pre- and post-processing method utility members and functions
61  DtInetSockPktHdrDesc myHeaderDesc;
62  int myBytesNeeded;
63  bool myWaitingForStartOfPacket;
64 
71  virtual bool setHeaderDescriptor( DtInetSockPktHdrDesc& hdrDesc );
72  virtual DtInetSockPktHdrDesc& getHeaderDescriptor() const;
73 
84  virtual bool setMaxBacklogSize( DtU32 size );
85  virtual DtU32 getMaxBacklogSize();
86 
89  DtU32 myMaxBacklogSize;
91  DtU32 myMaxBundleSize;
92 
93 
94 // ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
95 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
96 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
97 // STOPPED HERE --- move to socket subclass header
98 
99 // STOPPED HERE --- move to socket subclass implementation
100 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
101 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
102 // v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v
103 bool DtInetSocket::setHeaderDescriptor( DtInetSockPktHdrDesc& hdrDesc )
104 {
105  if ( (hdrDesc.sizeFieldLength != 0) && (hdrDesc.sizeFieldLength != 1)
106  && (hdrDesc.sizeFieldLength != 2) && (hdrDesc.sizeFieldLength != 4) )
107  {
108  return false;
109  }
110 
111  // Initialize packet demultiplexing vars.
112  myHeaderDesc.sizeFieldOffset = hdrDesc.sizeFieldOffset;
113  myHeaderDesc.sizeFieldLength = hdrDesc.sizeFieldLength;
114  myHeaderDesc.sizeFieldMask = hdrDesc.sizeFieldMask;
115  myBytesNeeded = myHeaderDesc.sizeFieldOffset + myHeaderDesc.sizeFieldLength;
116  if ( hdrDesc.sizeFieldLength != 0 )
117  {
118  myWaitingForStartOfPacket = true;
119  }
120  else
121  {
122  myWaitingForStartOfPacket = false;
123  }
124  return true;
125 }
126 
127 DtInetSockPktHdrDesc& DtInetSocket::getHeaderDescriptor() const
128 {
129  return (DtInetSockPktHdrDesc&)myHeaderDesc;
130 }
131 
132 bool DtInetSocket::setMaxBundleSize( DtU32 size )
133 {
134  myMaxBundleSize = size;
135 // STOPPED HERE
136  if ( size > 0 )
137  {
138  // Add default bundling pre- and post- processing callbacks. Bundling
139  // should happen fairly early
140  addProcessingCallback( DtInetSockProcess_PRE_SEND,
141  DtInetSocket::addToBundle, cbPriority );
142  }
143  else
144  {
145  // Try to remove default bundling pre- and post- processing callbacks.
146  // They may have been replaced by custom bundling callbacks, in which
147  // case they won't be found, but that's not a problem.
148 
149  }
150  return true;
151 }
152 
153 DtU32 DtInetSocket::getMaxBundleSize()
154 {
155  return myMaxBundleSize;
156 }
157 
158 bool DtInetSocket::isBundling()
159 {
160  return (myMaxBundleSize > 0);
161 }
162 
163 bool DtInetSocket::setMaxBacklogSize( DtU32 size, int cbPriority )
164 {
165  myMaxBacklogSize = size;
166  if ( size > 0 )
167  {
168  // Add default backlog pre- and post- processing callbacks
169  }
170  else
171  {
172  // Try to remove default bundling pre- and post- processing callbacks.
173  // They may have been replaced by custom backlog callbacks, in which
174  // case they won't be found, but that's not a problem.
175 
176  }
177  return true;
178 }
179 
180 DtU32 DtInetSocket::getMaxBacklogSize()
181 {
182  return myMaxBacklogSize;
183 }
184 // ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
185 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
186 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
187 // STOPPED HERE --- move to socket subclass implementation
188 
189 #endif // 0
190 
194 int DtInetSockUtilAddToBundle( DtInetSocket* sock, int size,
195  DtInetBufferChain& buffChain, DtInetEndpoint& ep,
196  void* usr );
197 int DtInetSockUtilFlushBundle( DtInetSocket* sock, int size,
198  DtInetBufferChain& buffChain, DtInetEndpoint& ep,
199  void* usr );
200 int DtInetSockUtilUnbundle( DtInetSocket* sock, int size,
201  DtInetBufferChain& buffChain, DtInetEndpoint& ep,
202  void* usr );
203 
204 int DtInetSockUtilQueueBacklog( DtInetSocket* sock, int size,
205  DtInetBufferChain& buffChain, DtInetEndpoint& ep,
206  void* usr );
207 int DtInetSockUtilFlushBacklog( DtInetSocket* sock, int size,
208  DtInetBufferChain& buffChain, DtInetEndpoint& ep,
209  void* usr );
210 
211 }
212 
213 #ifdef DtUSE_UTILITIES_NAMESPACE
214 }
215 #endif
216 

Document ID: Generated on Wed Aug 14 15:35:11 EDT 2013 from SVN revision 130445
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)