gwnavruntime/visualdebug/internal/socketdispatcher.h Source File

socketdispatcher.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 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 // primary contact: BRGR - secondary contact: NOBODY
8 
9 #ifndef Navigation_SocketDispatcher_H
10 #define Navigation_SocketDispatcher_H
11 
13 
14 #ifdef KY_ENABLE_SOCKETS
17 
18 namespace Kaim
19 {
20 
21 class File;
22 
23 enum SocketDispatchMode
24 {
25  SocketDispatch_NetworkOnly = 0, //< data are sent to and received from the network exclusively
26  SocketDispatch_SendToFile = 1, //< data are sent to file and receive calls always give a Heartbeat message
27  SocketDispatch_ReceiveFromFile = 2, //< data are received from file exclusively, and sent to nowhere.
28 };
29 
30 class SocketDispatcherFactory : public Net::AMP::SocketImplFactory
31 {
32  KY_DEFINE_NEW_DELETE_OPERATORS(Stat_Default_Mem)
33 
34 public:
35  // @param file must be ready for write and read
36  SocketDispatcherFactory(SocketDispatchMode mode, File* file, KyInt32 fileBytesLimit)
37  : m_mode(mode)
38  , m_file(file)
39  , m_fileBytesLimit(fileBytesLimit)
40  {
41  // check that a file is passed if the given mode requires one!
42  KY_ASSERT( m_mode == SocketDispatch_NetworkOnly || m_file != KY_NULL );
43 
44  // cap the file size in MB to prevent KyInt32 overflow when it will be converted to Bytes
45  // minus 10MB since writing ends when the file size is above the limit,
46  // and we don't expect that a buffer of 10MB be given to Net::AMP::Socket::Send()
47  KyInt32 capLimit = (2047-10) * 1024 * 1024; // cap to 2037 MBytes
48  if (m_fileBytesLimit <= 0 || m_fileBytesLimit >= capLimit)
49  m_fileBytesLimit = capLimit;
50  }
51 
52  virtual ~SocketDispatcherFactory() {}
53 
54  virtual Net::AMP::SocketInterface* Create();
55  virtual void Destroy(Net::AMP::SocketInterface* socketImpl);
56 
57 private:
58  SocketDispatchMode m_mode;
59  File* m_file;
60  KyInt32 m_fileBytesLimit;
61 };
62 
63 }
64 
65 #endif
66 
67 #endif // Navigation_SocketDispatcher_H
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
#define KY_NULL
Null value.
Definition: types.h:247
Definition: gamekitcrowddispersion.h:20
#define KY_DEFINE_NEW_DELETE_OPERATORS(MemStat)
This macro defines new and delete operators.
Definition: memory.h:137