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 "internalTypes.h"
19 #include <vlutil/vlInetSocket.h>
20 #include <vlutil/vlPrint.h>
21 #include <list>
22 
23 #include "msgHeaderReader.h"
24 
29 {
30 public:
31 
34  DtMsgSocket(std::shared_ptr<DtMsgHeaderReader> hdrReader,
35  size_t recvBuffSize);
36 
39  DtMsgSocket(DtUniquePtr<MAKRti::DtInetSocket> socket,
40  std::shared_ptr<DtMsgHeaderReader> hdrReader, size_t recvBuffSize);
41 
43  virtual ~DtMsgSocket();
44 
46  virtual int sendMessage(caddr_t msg, size_t msgSize, bool deleteAfterSend,
47  const MAKRti::DtInetAddr& destAddr = MAKRti::DtInetAddr::inaddrAny(), int port = 0) = 0;
48 
51  virtual bool flush() = 0;
52 
54  virtual int recvMessage(caddr_t *buffptr) = 0;
55 
58  virtual int recvMessageWithSrc(caddr_t *buffptr, MAKRti::DtInetEndpoint& src) = 0;
59 
61  virtual bool closeSocket();
62 
64  virtual MAKRti::DtInetSockState state() const;
65 
67  void printStateToStream(MAKRti::DtOutputStream& stream) const;
68 
70  const MAKRti::DtString& lastError() const;
71 
73  virtual void enableBundling(size_t maxBundleSize) = 0;
74 
76  virtual void disableBundling() = 0;
77 
79  virtual void enableCompression(MAKRti::DtU8 compressionLevel) = 0;
80 
82  virtual void disableCompression() = 0;
83 
85  const MAKRti::DtInetEndpoint& localEndpoint() const { return mySocket->localEndpoint(); }
86 
88  void setSendBufferSize(MAKRti::DtU32 size) { mySocket->setSendBufferSize(size); }
89 
91  void setRecvBufferSize(MAKRti::DtU32 size) { mySocket->setReceiveBufferSize(size); }
92 
94  MAKRti::DtU32 maxSendMsgSize() const { return mySocket->getSendBufferSize(); }
95 
97  unsigned int descriptor() const { return mySocket->descriptor(); }
98 
100  MAKRti::DtInetSocket* inetSocket();
101 
102 private:
103 
105  DtMsgSocket(const DtMsgSocket&);
106  DtMsgSocket& operator=(const DtMsgSocket&);
107 
108 protected:
109 
111  void expandRecvBuffer( size_t sizeNeeded );
112 
113 protected:
114 
116  DtUniquePtr<MAKRti::DtInetSocket> mySocket;
117 
119  MAKRti::DtInetBuffer myRecvBuffer;
120 
122  MAKRti::DtString myLastError;
123 
125  std::shared_ptr<DtMsgHeaderReader> myHeaderReader;
126 
127 };
128 
129 inline MAKRti::DtInetSockState DtMsgSocket::state() const
130 {
131  MAKRti::DtInetSockState state = MAKRti::DtInetSockState_NOT_INITIALIZED;
132  if(mySocket.get())
133  {
134  state = mySocket->state();
135  }
136  return state;
137 }
138 
139 inline void DtMsgSocket::printStateToStream(MAKRti::DtOutputStream& stream) const
140 {
141  MAKRti::DtString stateStr = "Socket State = ";
142  stateStr += state();
143  stream << stateStr.c_str() << std::endl;
144  if (!lastError().isEmpty())
145  {
146  stream << lastError().c_str() << std::endl;
147  }
148 }
149 
150 inline const MAKRti::DtString& DtMsgSocket::lastError() const
151 {
152  return myLastError;
153 }
154 
155 inline void DtMsgSocket::expandRecvBuffer( size_t sizeNeeded )
156 {
157  if(sizeNeeded > myRecvBuffer.size())
158  {
159  div_t ratio = div( (int)sizeNeeded, (int)myRecvBuffer.size() );
160  size_t newSize = myRecvBuffer.size() * ( ratio.quot + 1 );
161  myRecvBuffer.resize(newSize);
162  }
163 }
164 
165 inline MAKRti::DtInetSocket* DtMsgSocket::inetSocket()
166 {
167  return mySocket.get();
168 }
169 
170 #endif
void setRecvBufferSize(MAKRti::DtU32 size)
Sets the socket receive buffer size.
Definition: msgSocket.h:91
unsigned int descriptor() const
Get&#39;s the socket file descriptor.
Definition: msgSocket.h:97
const MAKRti::DtInetEndpoint & localEndpoint() const
Gets the local endpoint for the socket.
Definition: msgSocket.h:85
virtual MAKRti::DtInetSockState state() const
Returns the state of the socket.
Definition: msgSocket.h:129
MAKRti::DtU32 maxSendMsgSize() const
Gets the maximum socket send size.
Definition: msgSocket.h:94
void expandRecvBuffer(size_t sizeNeeded)
Expands the receive buffer to accommodate the given size message.
Definition: msgSocket.h:155
MAKRti::DtString myLastError
Description of last error.
Definition: msgSocket.h:122
const MAKRti::DtString & lastError() const
Returns a description of the last error.
Definition: msgSocket.h:150
The DtMsgSocket provides a wrapper around the MAKRti::DtInetSocket class to operate on messages rathe...
Definition: msgSocket.h:28
std::shared_ptr< DtMsgHeaderReader > myHeaderReader
Reads data from message header.
Definition: msgSocket.h:125
DtUniquePtr< MAKRti::DtInetSocket > mySocket
The socket.
Definition: msgSocket.h:116
void setSendBufferSize(MAKRti::DtU32 size)
Sets the socket send buffer size.
Definition: msgSocket.h:88
MAKRti::DtInetBuffer myRecvBuffer
The buffer to store received data in.
Definition: msgSocket.h:119
The declaration of internal types.
void printStateToStream(MAKRti::DtOutputStream &stream) const
prints state to stream
Definition: msgSocket.h:139
#define DT_DLL_RTIUTIL
Definition: rtiMsConfig.h:160
MAKRti::DtInetSocket * inetSocket()
Returns a pointer to the MAKRti::DtInetSocket.
Definition: msgSocket.h:165

Document ID: Generated on Sun Jul 20 16:15:30 EDT 2025 from SVN revision 277985
Copyright © 2005-2025 MAK Technologies Inc. All Rights Reserved (www.mak.com)