gwnavruntime/visualdebug/internal/socketdispatcher.h Source File

socketdispatcher.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 #pragma once
8 
10 
11 #ifdef KY_ENABLE_SOCKETS
14 
15 namespace Kaim
16 {
17 
18 class File;
19 
20 enum SocketDispatchMode
21 {
22  SocketDispatch_NetworkOnly = 0, //< data are sent to and received from the network exclusively
23  SocketDispatch_SendToFile = 1, //< data are sent to file and receive calls always give a Heartbeat message
24  SocketDispatch_ReceiveFromFile = 2, //< data are received from file exclusively, and sent to nowhere.
25 };
26 
27 class SocketDispatcherFactory : public Net::AMP::SocketImplFactory
28 {
29  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
30 
31 public:
32  // @param file must be ready for write and read
33  SocketDispatcherFactory(SocketDispatchMode mode, File* file, KyInt32 fileBytesLimit)
34  : m_mode(mode)
35  , m_file(file)
36  , m_fileBytesLimit(fileBytesLimit)
37  {
38  // check that a file is passed if the given mode requires one!
39  KY_ASSERT( m_mode == SocketDispatch_NetworkOnly || m_file != nullptr );
40 
41  // cap the file size in MB to prevent KyInt32 overflow when it will be converted to Bytes
42  // minus 10MB since writing ends when the file size is above the limit,
43  // and we don't expect that a buffer of 10MB be given to Net::AMP::Socket::Send()
44  KyInt32 capLimit = (2047-10) * 1024 * 1024; // cap to 2037 MBytes
45  if (m_fileBytesLimit <= 0 || m_fileBytesLimit >= capLimit)
46  m_fileBytesLimit = capLimit;
47  }
48 
49  virtual ~SocketDispatcherFactory() {}
50 
51  virtual Net::AMP::SocketInterface* Create();
52  virtual void Destroy(Net::AMP::SocketInterface* socketImpl);
53 
54 private:
55  SocketDispatchMode m_mode;
56  File* m_file;
57  KyInt32 m_fileBytesLimit;
58 };
59 
60 }
61 
62 #endif
63 
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:132
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
std::int32_t KyInt32
int32_t
Definition: types.h:24