VR-Link API Documentation for HLA Evolved
vlInetSocketUtils.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 ** Copyright (c) 1992-2010 VT MAK
00003 ** All rights reserved.
00004 *********************************************************************/
00009 #pragma once
00010 
00011 #include <vlutil/vlInet.h>
00012 #include <vlutil/vlInetSocket.h>
00013 
00014 #ifdef DtUSE_UTILITIES_NAMESPACE
00015 namespace DtUSE_UTILITIES_NAMESPACE
00016 {
00017 #endif
00018 
00019 namespace DtInetUtils
00020 {
00021 
00022 // Each unique destination a socket sends to needs its own outbound bundle
00023 // entry. The first value in the pair is the current number of bytes in all
00024 // the buffer chains in the bundle. This eliminates the need to calculate the
00025 // size of the bundle each time it's accessed.
00026 typedef std::pair<DtU32, DtInetBufferChain> DtInetChainEntry;
00027 typedef std::map<DtInetEndpoint, DtInetChainEntry> DtInetSockOutboundBundleMap;
00028 
00029 // The inbound bundle queue needs to store each bundle received in the order 
00030 // received with the source endpoint in case the application retrieving the
00031 // the packets wants to know the source. So rather than storing inbound bundles
00032 // separated by source endpoint a single queue is appropriate.
00033 typedef std::pair<DtInetEndpoint, DtInetBuffer*> DtInetSockInboundBundleEntry;
00034 typedef std::deque<DtInetSockInboundBundleEntry> DtInetSockInboundBundleQueue;
00035 
00039 typedef struct DtInetPktHeaderDescriptor
00040 {
00041    DtNetU8  sizeFieldOffset; // bytes from start of packet
00042    int sizeFieldLength; // in bytes. Valid values: 1 (DtU8), 2 (DtU16), 4 (DtU32)
00043    int sizeFieldMask;   // bitmask applied to size field
00044 
00045 } DtInetPktHeaderDescriptor;
00047 #define DtInetSockPacketHeader_MASK_NONE  0x00
00048 #define DtInetSockPacketHeader_MASK_DtU8  0xff
00049 #define DtInetSockPacketHeader_MASK_DtU16 0xffff
00050 #define DtInetSockPacketHeader_MASK_DtU32 0xffffffff
00051 
00052 // The default RTI header descriptor: offset = 0, length = 4, bitmask = MASK_DtU32
00053 #define DtInetSockDefaultPktHdrDesc { 0, 4, DtInetSockPacketHeader_MASK_DtU32 }
00054 
00055 #if 0
00056 // STOPPED HERE --- move to socket subclass header
00057 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 
00058 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 
00059 // 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
00060    // Pre- and post-processing method utility members and functions 
00061    DtInetSockPktHdrDesc myHeaderDesc;
00062    int                  myBytesNeeded;
00063    bool                 myWaitingForStartOfPacket;
00064 
00071    virtual bool setHeaderDescriptor( DtInetSockPktHdrDesc& hdrDesc );
00072    virtual DtInetSockPktHdrDesc& getHeaderDescriptor() const;
00073 
00084    virtual bool  setMaxBacklogSize( DtU32 size );
00085    virtual DtU32 getMaxBacklogSize();
00086 
00088    DtInetUtils::DtInetSockOutboundBundleMap  myOutboundBacklogs;
00089    DtU32                                     myMaxBacklogSize;
00090    DtInetUtils::DtInetSockOutboundBundleMap  myOutboundBundles;
00091    DtU32                                     myMaxBundleSize;
00092 
00093 
00094 // ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
00095 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 
00096 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 
00097 // STOPPED HERE --- move to socket subclass header
00098 
00099 // STOPPED HERE --- move to socket subclass implementation
00100 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 
00101 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 
00102 // 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
00103 bool DtInetSocket::setHeaderDescriptor( DtInetSockPktHdrDesc& hdrDesc )
00104 {
00105    if ( (hdrDesc.sizeFieldLength != 0) && (hdrDesc.sizeFieldLength != 1)
00106      && (hdrDesc.sizeFieldLength != 2) && (hdrDesc.sizeFieldLength != 4) )
00107    {
00108       return false;
00109    }
00110 
00111    // Initialize packet demultiplexing vars. 
00112    myHeaderDesc.sizeFieldOffset = hdrDesc.sizeFieldOffset;
00113    myHeaderDesc.sizeFieldLength = hdrDesc.sizeFieldLength;
00114    myHeaderDesc.sizeFieldMask = hdrDesc.sizeFieldMask;
00115    myBytesNeeded = myHeaderDesc.sizeFieldOffset + myHeaderDesc.sizeFieldLength;
00116    if ( hdrDesc.sizeFieldLength != 0 )
00117    {
00118       myWaitingForStartOfPacket = true;
00119    }
00120    else
00121    {
00122       myWaitingForStartOfPacket = false;
00123    }
00124    return true;
00125 }
00126 
00127 DtInetSockPktHdrDesc& DtInetSocket::getHeaderDescriptor() const
00128 {
00129    return (DtInetSockPktHdrDesc&)myHeaderDesc;
00130 }
00131 
00132 bool DtInetSocket::setMaxBundleSize( DtU32 size )
00133 {
00134    myMaxBundleSize = size;
00135 // STOPPED HERE
00136    if ( size > 0 )
00137    {
00138       // Add default bundling pre- and post- processing callbacks. Bundling
00139       // should happen fairly early 
00140       addProcessingCallback( DtInetSockProcess_PRE_SEND,
00141                               DtInetSocket::addToBundle, cbPriority );
00142    }
00143    else
00144    {
00145       // Try to remove default bundling pre- and post- processing callbacks.
00146       // They may have been replaced by custom bundling callbacks, in which
00147       // case they won't be found, but that's not a problem.
00148 
00149    }
00150    return true;
00151 }
00152 
00153 DtU32 DtInetSocket::getMaxBundleSize()
00154 {
00155    return myMaxBundleSize;
00156 }
00157 
00158 bool DtInetSocket::isBundling()
00159 {
00160    return (myMaxBundleSize > 0);
00161 }
00162 
00163 bool DtInetSocket::setMaxBacklogSize( DtU32 size, int cbPriority )
00164 {
00165    myMaxBacklogSize = size;
00166    if ( size > 0 )
00167    {
00168       // Add default backlog pre- and post- processing callbacks
00169    }
00170    else
00171    {
00172       // Try to remove default bundling pre- and post- processing callbacks.
00173       // They may have been replaced by custom backlog callbacks, in which
00174       // case they won't be found, but that's not a problem.
00175 
00176    }
00177    return true;
00178 }
00179 
00180 DtU32 DtInetSocket::getMaxBacklogSize()
00181 {
00182    return myMaxBacklogSize;
00183 }
00184 // ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
00185 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 
00186 // | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 
00187 // STOPPED HERE --- move to socket subclass implementation
00188 
00189 #endif // 0
00190 
00194 int DtInetSockUtilAddToBundle( DtInetSocket* sock, int size,
00195                            DtInetBufferChain& buffChain, DtInetEndpoint& ep,
00196                            void* usr );
00197 int DtInetSockUtilFlushBundle( DtInetSocket* sock, int size,
00198                            DtInetBufferChain& buffChain, DtInetEndpoint& ep, 
00199                            void* usr );
00200 int DtInetSockUtilUnbundle( DtInetSocket* sock, int size,
00201                         DtInetBufferChain& buffChain, DtInetEndpoint& ep, 
00202                         void* usr );
00203 
00204 int DtInetSockUtilQueueBacklog( DtInetSocket* sock, int size,
00205                             DtInetBufferChain& buffChain, DtInetEndpoint& ep, 
00206                             void* usr );
00207 int DtInetSockUtilFlushBacklog( DtInetSocket* sock, int size,
00208                             DtInetBufferChain& buffChain, DtInetEndpoint& ep, 
00209                             void* usr );
00210 
00211 } 
00212 
00213 #ifdef DtUSE_UTILITIES_NAMESPACE
00214 } 
00215 #endif
00216 

Document ID: Generated on Mon May 14 08:06:18 EDT 2012 from SVN revision 114750
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)