MAK RTIspy API Documentation for HLA Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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(), int port = 0) = 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  unsigned 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  if (!lastError().isEmpty())
146  {
147  stream << lastError().c_str() << std::endl;
148  }
149 }
150 
151 inline const DtString& DtMsgSocket::lastError() const
152 {
153  return myLastError;
154 }
155 
156 inline void DtMsgSocket::expandRecvBuffer( size_t sizeNeeded )
157 {
158  if(sizeNeeded > myRecvBuffer.size())
159  {
160  div_t ratio = div( (int)sizeNeeded, (int)myRecvBuffer.size() );
161  size_t newSize = myRecvBuffer.size() * ( ratio.quot + 1 );
162  myRecvBuffer.resize(newSize);
163  }
164 }
165 
166 inline DtInetSocket* DtMsgSocket::inetSocket()
167 {
168  return mySocket.get();
169 }
170 
171 #endif

Document ID: Generated on Mon Jul 9 10:30:41 EDT 2018 from SVN revision 190224
Copyright © 2005-2018 VT MÄK Inc. All Rights Reserved (www.mak.com)