VR-Link API Documentation for HLA 1.3
vlSocket.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 ** Copyright (c) 1992, 1997 MaK Technologies, Inc.
00003 ** All rights reserved.
00004 *********************************************************************/
00005 /*********************************************************************
00006 ** $RCSfile: vlSocket.h,v $ $Revision: 1.2.6.2 $ $State: Exp $
00007 *********************************************************************/
00008 #ifndef vlSocket_H_
00009 #define vlSocket_H_
00010 
00015 #include <vlutil/vlConfig.h>
00016 #include <vlutil/vlUtil.h>
00017 #include <vlutil/vlList.h>
00018 #include <vlutil/vlMutex.h>
00019 
00020 #if DT_HAVE_STD_H
00021 #include <std.h>
00022 #endif
00023 
00024 #include <stdio.h>
00025 #include <sys/types.h>
00026 #include <map>
00027 #include <vector>
00028 
00029 struct ifconf;
00030 
00031 #ifdef DtUSE_UTILITIES_NAMESPACE
00032 namespace DtUSE_UTILITIES_NAMESPACE
00033 {
00034 #endif
00035 
00036 
00044 
00048 #define DtDEFAULT_MAX_PACKET_SIZE  15000 //! Multiple of 8 bytes.
00049 #define DtDEFAULT_PORT 3000
00050 
00051 #ifdef DtUSE_UTILITIES_NAMESPACE
00052 const DtIpv4Addr DtUSE_DEFAULT_IP_ADDR = DtUSE_UTILITIES_NAMESPACE::DtIpv4Addr(0);
00053 #else
00054 const DtIpv4Addr DtUSE_DEFAULT_IP_ADDR = DtIpv4Addr(0);
00055 #endif
00056 
00057 #define DtSOCKET_PACKET      1
00058 #define DtSOCKET_NO_PACKET        0
00059 #define DtSOCKET_SERVER_MSG      -1
00060 #define DtSOCKET_FILTERED_PACKET -2
00061 #define DtSOCKET_FILTERED_BY_PORT -3
00062 
00063 
00065 enum DtTestOperator {  Dto_EQ, Dto_NEQ } ;
00066 
00068 enum DtFilterType { DtFtInetAddr, DtFtNetU8 };
00069 
00071 enum DtFlushStatus
00072 {
00073    DtFlushError = -1, 
00074    DtFlushIncomplete, 
00075    DtFlushComplete   
00076 };
00077 
00079 class DT_DLL_NETCOMPAT DtFilterTest
00080 {
00081   public:
00082     DtFilterTest() { disableTest();}
00083     virtual ~DtFilterTest() {}
00084 
00085     void disableTest()                           { setTest(Dto_NEQ, 0, 0); }
00086     void setTest(DtTestOperator op, DtU32 value) { setTest(op, 1, &value);    }
00087     void extendTest(DtU32 value)                 { extendTest (1, &value);    }
00088     void reduceTest(DtU32 value)                 { reduceTest (1, &value);    }
00089     virtual void setOperator(DtTestOperator op);
00090     virtual void setTest(DtTestOperator op, int n, DtU32 *values);
00091     virtual void extendTest(int n, DtU32 *values);
00092     virtual void reduceTest(int n, DtU32 *values);
00093     
00094     virtual bool evalTest(char *buf, int offset, DtFilterType type);
00095 
00096   protected:
00097 
00098     virtual void clearList();
00099     DtTestOperator testOp;
00100     DtList values;
00101 };
00102 
00110 class DT_DLL_NETCOMPAT DtSocket
00111 {
00112   public:
00113     
00115     DtSocket();
00116 
00118     virtual ~DtSocket();
00119 
00128     virtual int DtSend(caddr_t packet, size_t size, 
00129              DtIpv4Addr addr = DtUSE_DEFAULT_IP_ADDR);
00130 
00134     virtual int sendTo(caddr_t packet, size_t size, 
00135              DtIpv4Addr addr = DtUSE_DEFAULT_IP_ADDR) = 0;
00136 
00150     virtual int DtRecv(caddr_t *buffptr, int *status=0) = 0;
00151 
00153     virtual int DtRecv(caddr_t buff, size_t) = 0;
00155     caddr_t DtRecv();
00156 
00159     virtual DtFlushStatus flush();
00160 
00164     virtual DtFlushStatus flush(long& byteCount);
00165 
00170     virtual void setReceiveBufferSize(int newsize);
00171 
00175     virtual void setSendBufferSize(int newsize);
00176    
00177     virtual void setBundling(int maxSize);
00178     virtual int isBundling();
00179     virtual void setUnbundling(int);
00180 
00181     virtual DtIpv4Addr lastSourceInetAddr();
00182     virtual int DtReportPktsRcvd(void);
00183     virtual void DtBecomeNonBlocking(void);
00184     virtual void notifyMe();
00185 
00186     virtual int listenToMulticastGroup(DtIpv4Addr addr, DtIpv4Addr netInterface = DtUSE_DEFAULT_IP_ADDR);
00187     virtual int dropMulticastGroup(DtIpv4Addr addr, DtIpv4Addr netInterface = DtUSE_DEFAULT_IP_ADDR);
00188     virtual int setMcastTtl(int);
00189     virtual void setMcastDevice(DtIpv4Addr);
00190 
00191     virtual DtFilterTest *exerciseId();
00192     virtual DtFilterTest *protocolVersion();
00193     virtual DtFilterTest *pduKind();
00194     virtual DtFilterTest *ipAddr();
00195     
00196     
00197     int myBlockingFlag;
00198     int pkts_rcvd;
00199     
00204     virtual int readFd();
00205     virtual int writeFd();
00206     virtual bool isOk() const;
00207 
00208     static void initializeNetwork();
00209     
00210 
00212     static void setQuietSockets(bool quietVal);
00213     static bool areQuietSockets();
00214 
00215   protected:
00216     
00217 #ifdef _WIN32
00218     static void winInit();
00219     static void winClose();
00220     static int theWindowsInitializedCount;
00221     static DtMutex theWindowsInitMutex;
00222 #endif
00223 
00224     static bool theAreQuietSockets;
00225 
00228    static int getConfig(const char* device, int sock, ifconf* ifc);
00229 
00230   protected:
00231 
00232     virtual bool accept(char *buf, DtIpv4Addr iaddr);
00233 
00234     typedef std::vector<char> Buffer;
00235     typedef std::map<DtIpv4Addr, Buffer> BufferMap; 
00236 
00237     BufferMap myBufferMap;
00238 
00239     int myBundlingFlag;
00240     int myMaxBundleSize;
00241     int mySockFd;
00242 
00243 
00244   private:
00246     DtSocket(const DtSocket &);
00247 
00249     DtSocket &operator=(const DtSocket &);
00250 
00251   private:
00252 
00253     DtFilterTest myVersionFilter;
00254     DtFilterTest myExerciseFilter;
00255     DtFilterTest myKindFilter;
00256     DtFilterTest myAddrFilter;
00257 };
00258 
00260 DT_DLL_NETCOMPAT DtSocket *DtNewDfltSocket(int port, DtIpv4Addr destAddr = 0,
00261                                         bool use_async = false);
00266 DT_DLL_NETCOMPAT int DtMaxPacketSize();
00267 
00271 DT_DLL_NETCOMPAT void DtSetMaxPacketSize(int size);
00272 
00273 #ifdef DtUSE_UTILITIES_NAMESPACE
00274 }
00275 #endif
00276 
00277 #define vlSocket_inl_
00278 #include "vlSocket.inl"
00279 #undef vlSocket_inl_
00280 
00281 #endif

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)