MAK RTIspy API Documentation for HLA 1516
tcpMsgSocket.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 ** Copyright (c) 2010 MaK Technologies, Inc.
00003 ** All rights reserved.
00004 *********************************************************************/
00005 /*********************************************************************
00006 ** $RCSfile: tcpMsgSocket.h,v $ $Revision: $ $State: Exp $
00007 *********************************************************************/
00008 
00013 
00014 #ifndef tcpMsgSocket_H_
00015 #define tcpMsgSocket_H_
00016 
00017 #include "msgSocket.h"
00018 #include "msgBundler.h"
00019 #include "msgCompressor.h"
00020 #include <list>
00021 #include <vlutil/vlInetTcpSocket.h>
00022 
00023 using namespace MAKRti;
00024 
00025 class DtQueuedMsg
00026 {
00027 public:
00028    DtQueuedMsg() : msg(0), size(0), remainingMsg(0), remainingSize(0) {}
00029    DtQueuedMsg(caddr_t m, size_t s) : msg(m), size(s),
00030       remainingMsg(m), remainingSize(s) {}
00031    ~DtQueuedMsg() {}
00032 
00033    caddr_t msg;
00034    size_t size;
00035    caddr_t remainingMsg;
00036    size_t remainingSize;
00037 };
00038 
00042 class DT_DLL_RTIUTIL DtTcpMsgSocket : public DtMsgSocket
00043 {
00044 public:
00045 
00049    DtTcpMsgSocket(DtBoost::shared_ptr<DtMsgHeaderReader> hdrReader,
00050       size_t recvBufferSize = 20000, int maxQueuedMsgs = -1);
00051 
00054    DtTcpMsgSocket(std::auto_ptr<DtInetTcpSocket> socket,
00055       DtBoost::shared_ptr<DtMsgHeaderReader> hdrReader,
00056       size_t recvBuffSize = 20000, int maxQueuedMsgs = -1);
00057 
00059    virtual ~DtTcpMsgSocket();
00060 
00069    virtual void openServerSocket( DtU16 localPort,
00070       DtU32 flags = DtDefaultSockOpts, DtInetDevice* hostIf = NULL, 
00071       DtInetUtils::DtInetAddrFamily family = DtInetUtils::DtInetAddrFamily_IPv4 );
00072 
00085    virtual void openClientSocket( const DtInetEndpoint& dest,
00086       DtU32 flags = DtDefaultSockOpts, DtU16 localPort = 0,
00087       DtInetDevice* hostIf = NULL);
00088 
00091    virtual int sendMessage(caddr_t msg, size_t msgSize, bool deleteAfterSend,
00092       const DtInetAddr& destAddr = DtInetAddr::inaddrAny());
00093 
00096    virtual bool flush();
00097 
00099    virtual int recvMessage(caddr_t *buffptr);
00100 
00102    virtual int recvMessageWithSrc(caddr_t *buffptr, DtInetEndpoint& src);
00103 
00105    virtual void enableBundling(size_t maxBundleSize);
00106 
00108    virtual void disableBundling();
00109 
00111    virtual unsigned bundleSize() const;
00112 
00114    virtual void enableCompression(DtU8 compressionLevel);
00115 
00117    virtual void disableCompression();
00118 
00120    virtual unsigned compressionLevel() const;
00121 
00122    // Test the connection
00123    virtual bool testConnectionStatus();
00124 
00127    virtual void setMaxQueuedMessages(int size);
00128    
00131    virtual int maxQueuedMessages() const;
00132 
00135    virtual bool getQueueStatus(int& percentFull) const;
00136 
00138    virtual void setTcpNoDelay(bool enable);
00139 
00141    virtual void setNonBlocking(bool nonBlocking);
00142 
00144    virtual const DtInetEndpoint& destination() const;
00145 
00147    virtual DtU32 maxMsgSize() const;
00148 
00150    DtInetTcpSocket* inetTcpSocket();
00151 
00153    bool isConnected() const { return mySocket.get() && mySocket->state() == DtInetSockState_CONNECTED; }
00154 
00156    bool isConnectionInProgress() const { return mySocket.get() && mySocket->state() == DtInetSockState_INPROGRESS; }
00157 
00158 protected:
00159 
00161    virtual int sendData(caddr_t msg, size_t msgSize, bool deleteAfterSend);
00162 
00165    virtual bool flushQueue();
00166 
00168    virtual bool queueMessage(caddr_t msg, size_t msgSize);
00169    
00171    virtual void resizeTestPacket();
00172 
00173 protected:
00174 
00177    bool myNeedSize;
00178 
00180    int myNumBytesToWaitFor;
00181 
00183    int myNumBytesReceived;
00184 
00186    DtInetBuffer myTestPacket;
00187 
00189    std::list<DtQueuedMsg> myMsgQueue;
00190 
00192    DtMsgBundler myMsgBundler;
00193 
00195    bool myBundlingEnabled;
00196 
00198    DtMsgCompressor myMsgCompressor;
00199 
00201    bool myCompressionEnabled;
00202 
00204    int myMaxQueuedMessages;
00205 
00209    mutable int myMutableOldQueueLevel;
00210 
00212    size_t myBytesNeededForSize;
00213 };
00214 
00215 inline DtInetTcpSocket* DtTcpMsgSocket::inetTcpSocket()
00216 {
00217    return static_cast<DtInetTcpSocket*>(mySocket.get());
00218 }
00219 
00220 #endif //! tcpMsgSocket_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)