MAK RTIspy API Documentation for HLA 1516
msgSocket.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 ** Copyright (c) 2010 MaK Technologies, Inc.
00003 ** All rights reserved.
00004 *********************************************************************/
00005 /*********************************************************************
00006 ** $RCSfile: msgSocket.h,v $ $Revision: $ $State: Exp $
00007 *********************************************************************/
00008 
00013 
00014 #ifndef msgSocket_H_
00015 #define msgSocket_H_
00016 
00017 #include <rtiMsConfig.h>
00018 #include <vlutil/vlInetSocket.h>
00019 #include <list>
00020 
00021 #include "msgHeaderReader.h"
00022 
00023 using namespace MAKRti;
00024 
00028 class DT_DLL_RTIUTIL DtMsgSocket
00029 {
00030 public:
00031 
00034    DtMsgSocket(DtBoost::shared_ptr<DtMsgHeaderReader> hdrReader,
00035       size_t recvBuffSize);
00036 
00039    DtMsgSocket(std::auto_ptr<DtInetSocket> socket,
00040       DtBoost::shared_ptr<DtMsgHeaderReader> hdrReader, size_t recvBuffSize);
00041 
00043    virtual ~DtMsgSocket();
00044 
00046    virtual int sendMessage(caddr_t msg, size_t msgSize, bool deleteAfterSend,
00047       const DtInetAddr& destAddr = DtInetAddr::inaddrAny()) = 0;
00048 
00051    virtual bool flush() = 0;
00052 
00054    virtual int recvMessage(caddr_t *buffptr) = 0;
00055 
00058    virtual int recvMessageWithSrc(caddr_t *buffptr, DtInetEndpoint& src) = 0;
00059 
00061    virtual bool closeSocket();
00062       
00064    virtual DtInetSockState state() const;
00065 
00067    const DtString& lastError() const;
00068 
00070    virtual void enableBundling(size_t maxBundleSize) = 0;
00071 
00073    virtual void disableBundling() = 0;
00074 
00076    virtual void enableCompression(DtU8 compressionLevel) = 0;
00077 
00079    virtual void disableCompression() = 0;
00080 
00082    const DtInetEndpoint& localEndpoint() const { return mySocket->localEndpoint(); }
00083 
00085    void setSendBufferSize(DtU32 size) { mySocket->setSendBufferSize(size); }
00086 
00088    void setRecvBufferSize(DtU32 size) { mySocket->setReceiveBufferSize(size); }
00089 
00091    DtU32 maxSendMsgSize() const { return mySocket->getSendBufferSize(); }
00092 
00094    int descriptor() const { return mySocket->descriptor(); }
00095 
00097    DtInetSocket* inetSocket();
00098 
00099 private:
00100 
00102    DtMsgSocket(const DtMsgSocket&);
00103    DtMsgSocket& operator=(const DtMsgSocket&);
00104 
00105 protected:
00106 
00108    void expandRecvBuffer( size_t sizeNeeded );
00109 
00110 protected:
00111 
00113    std::auto_ptr<MAKRti::DtInetSocket> mySocket;
00114 
00116    DtInetBuffer myRecvBuffer;
00117 
00119    DtString myLastError;
00120 
00122    DtBoost::shared_ptr<DtMsgHeaderReader> myHeaderReader;
00123 
00124 };
00125 
00126 inline DtInetSockState DtMsgSocket::state() const
00127 {
00128    DtInetSockState state = DtInetSockState_NOT_INITIALIZED;
00129    if(mySocket.get())
00130    {
00131       state = mySocket->state();
00132    }
00133    return state;   
00134 }
00135 
00136 inline const DtString& DtMsgSocket::lastError() const
00137 {
00138    return myLastError;
00139 }
00140 
00141 inline void DtMsgSocket::expandRecvBuffer( size_t sizeNeeded )
00142 {
00143    if(sizeNeeded > myRecvBuffer.size())
00144    {
00145       div_t ratio = div( (int)sizeNeeded, (int)myRecvBuffer.size() );
00146       size_t newSize = myRecvBuffer.size() * ( ratio.quot + 1 );
00147       myRecvBuffer.resize(newSize);
00148    }
00149 }
00150 
00151 inline DtInetSocket* DtMsgSocket::inetSocket()
00152 {
00153    return mySocket.get();
00154 }
00155 
00156 #endif //! msgSocket_H_

Document ID: Generated on Thu Jun 14 14:15:04 EDT 2012 from SVN revision 116116
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)