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
DtU32 maxSendMsgSize() const
Gets the maximum socket send size.
Definition: msgSocket.h:95
virtual DtInetSockState state() const
Returns the state of the socket.
Definition: msgSocket.h:130
DtString myLastError
Description of last error.
Definition: msgSocket.h:123
DtInetBuffer myRecvBuffer
The buffer to store received data in.
Definition: msgSocket.h:120
DtBoost::shared_ptr< DtMsgHeaderReader > myHeaderReader
Reads data from message header.
Definition: msgSocket.h:126
const DtString & lastError() const
Returns a description of the last error.
Definition: msgSocket.h:151
unsigned int descriptor() const
Get&#39;s the socket file descriptor.
Definition: msgSocket.h:98
DtInetSocket * inetSocket()
Returns a pointer to the DtInetSocket.
Definition: msgSocket.h:166
void expandRecvBuffer(size_t sizeNeeded)
Expands the receive buffer to accommodate the given size message.
Definition: msgSocket.h:156
void setRecvBufferSize(DtU32 size)
Sets the socket receive buffer size.
Definition: msgSocket.h:92
const DtInetEndpoint & localEndpoint() const
Gets the local endpoint for the socket.
Definition: msgSocket.h:86
The DtMsgSocket provides a wrapper around the DtInetSocket class to operate on messages rather than j...
Definition: msgSocket.h:29
std::auto_ptr< MAKRti::DtInetSocket > mySocket
The socket.
Definition: msgSocket.h:117
void printStateToStream(MAKRti::DtOutputStream &stream) const
prints state to stream
Definition: msgSocket.h:140
#define DT_DLL_RTIUTIL
Definition: rtiMsConfig.h:127
void setSendBufferSize(DtU32 size)
Sets the socket send buffer size.
Definition: msgSocket.h:89

Document ID: Generated on Thu May 11 15:55:32 EDT 2023 from SVN revision 254743
Copyright © 2005-2020 MAK Technologies Inc. All Rights Reserved (www.mak.com)