MAK RTIspy API Documentation for HLA 1.3
msgSocket.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 2010 MaK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 /*********************************************************************
6 ** $RCSfile: msgSocket.h,v $ $Revision: $ $State: Exp $
7 *********************************************************************/
8 
13 
14 #ifndef msgSocket_H_
15 #define msgSocket_H_
16 
17 #include <rtiMsConfig.h>
18 #include <vlutil/vlInetSocket.h>
19 #include <vlutil/vlPrint.h>
20 #include <list>
21 
22 #include "msgHeaderReader.h"
23 
24 using namespace MAKRti;
25 
30 {
31 public:
32 
35  DtMsgSocket(DtBoost::shared_ptr<DtMsgHeaderReader> hdrReader,
36  size_t recvBuffSize);
37 
40  DtMsgSocket(std::auto_ptr<DtInetSocket> socket,
41  DtBoost::shared_ptr<DtMsgHeaderReader> hdrReader, size_t recvBuffSize);
42 
44  virtual ~DtMsgSocket();
45 
47  virtual int sendMessage(caddr_t msg, size_t msgSize, bool deleteAfterSend,
48  const DtInetAddr& destAddr = DtInetAddr::inaddrAny()) = 0;
49 
52  virtual bool flush() = 0;
53 
55  virtual int recvMessage(caddr_t *buffptr) = 0;
56 
59  virtual int recvMessageWithSrc(caddr_t *buffptr, DtInetEndpoint& src) = 0;
60 
62  virtual bool closeSocket();
63 
65  virtual DtInetSockState state() const;
66 
68  void printStateToStream(MAKRti::DtOutputStream& stream) const;
69 
71  const DtString& lastError() const;
72 
74  virtual void enableBundling(size_t maxBundleSize) = 0;
75 
77  virtual void disableBundling() = 0;
78 
80  virtual void enableCompression(DtU8 compressionLevel) = 0;
81 
83  virtual void disableCompression() = 0;
84 
86  const DtInetEndpoint& localEndpoint() const { return mySocket->localEndpoint(); }
87 
89  void setSendBufferSize(DtU32 size) { mySocket->setSendBufferSize(size); }
90 
92  void setRecvBufferSize(DtU32 size) { mySocket->setReceiveBufferSize(size); }
93 
95  DtU32 maxSendMsgSize() const { return mySocket->getSendBufferSize(); }
96 
98  int descriptor() const { return mySocket->descriptor(); }
99 
101  DtInetSocket* inetSocket();
102 
103 private:
104 
106  DtMsgSocket(const DtMsgSocket&);
107  DtMsgSocket& operator=(const DtMsgSocket&);
108 
109 protected:
110 
112  void expandRecvBuffer( size_t sizeNeeded );
113 
114 protected:
115 
117  std::auto_ptr<MAKRti::DtInetSocket> mySocket;
118 
120  DtInetBuffer myRecvBuffer;
121 
123  DtString myLastError;
124 
126  DtBoost::shared_ptr<DtMsgHeaderReader> myHeaderReader;
127 
128 };
129 
130 inline DtInetSockState DtMsgSocket::state() const
131 {
132  DtInetSockState state = DtInetSockState_NOT_INITIALIZED;
133  if(mySocket.get())
134  {
135  state = mySocket->state();
136  }
137  return state;
138 }
139 
140 inline void DtMsgSocket::printStateToStream(MAKRti::DtOutputStream& stream) const
141 {
142  MAKRti::DtString stateStr = "Socket State = ";
143  stateStr += state();
144  stream << stateStr.c_str() << std::endl;
145 }
146 
147 inline const DtString& DtMsgSocket::lastError() const
148 {
149  return myLastError;
150 }
151 
152 inline void DtMsgSocket::expandRecvBuffer( size_t sizeNeeded )
153 {
154  if(sizeNeeded > myRecvBuffer.size())
155  {
156  div_t ratio = div( (int)sizeNeeded, (int)myRecvBuffer.size() );
157  size_t newSize = myRecvBuffer.size() * ( ratio.quot + 1 );
158  myRecvBuffer.resize(newSize);
159  }
160 }
161 
162 inline DtInetSocket* DtMsgSocket::inetSocket()
163 {
164  return mySocket.get();
165 }
166 
167 #endif

Document ID: Generated on Fri Mar 14 19:08:55 EDT 2014 from SVN revision 137085
Copyright © 2005-2014 VT MÄK Inc. All Rights Reserved (www.mak.com)