SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UDPForwarder.h
Go to the documentation of this file.
1 /*
2 * Original work: Copyright (c) 2014, Oculus VR, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2017, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
19
20
21
22 #include "NativeFeatureIncludes.h"
23 #if _RAKNET_SUPPORT_UDPForwarder==1
24
25 #ifndef __UDP_FORWARDER_H
26 #define __UDP_FORWARDER_H
27
28 #include "Export.h"
29 #include "types.h"
30 #include "SocketIncludes.h"
31 #include "UDPProxyCommon.h"
32 #include "SimpleMutex.h"
33 #include "string.h"
34 #include "thread.h"
35 #include "DS_Queue.h"
36 #include "DS_OrderedList.h"
37 #include "LocklessTypes.h"
38 #include "DS_ThreadsafeAllocatingQueue.h"
39
40 namespace SLNet
41 {
42
43 enum UDPForwarderResult
44 {
45 UDPFORWARDER_FORWARDING_ALREADY_EXISTS,
46 UDPFORWARDER_NO_SOCKETS,
47 UDPFORWARDER_BIND_FAILED,
48 UDPFORWARDER_INVALID_PARAMETERS,
49 UDPFORWARDER_NOT_RUNNING,
50 UDPFORWARDER_SUCCESS,
51 UDPFORWARDER_RESULT_COUNT
52 };
53
56 class RAK_DLL_EXPORT UDPForwarder
57 {
58 public:
59 UDPForwarder();
60 virtual ~UDPForwarder();
61
64 void Startup(void);
65
67 void Shutdown(void);
68
72 void SetMaxForwardEntries(unsigned short maxEntries);
73
75 int GetMaxForwardEntries(void) const;
76
78 int GetUsedForwardEntries(void) const;
79
92 UDPForwarderResult StartForwarding(
93 SystemAddress source, SystemAddress destination, SLNet::TimeMS timeoutOnNoDataMS,
94 const char *forceHostAddress, unsigned short socketFamily,
95 unsigned short *forwardingPort, __UDPSOCKET__ *forwardingSocket);
96
100 void StopForwarding(SystemAddress source, SystemAddress destination);
101
102
103 struct ForwardEntry
104 {
105 ForwardEntry();
106 ~ForwardEntry();
107 SystemAddress addr1Unconfirmed, addr2Unconfirmed, addr1Confirmed, addr2Confirmed;
108 SLNet::TimeMS timeLastDatagramForwarded;
109 __UDPSOCKET__ socket;
110 SLNet::TimeMS timeoutOnNoDataMS;
111 short socketFamily;
112 };
113
114
115 protected:
116 friend RAK_THREAD_DECLARATION(UpdateUDPForwarderGlobal);
117
118 void UpdateUDPForwarder(void);
119 void RecvFrom(SLNet::TimeMS curTime, ForwardEntry *forwardEntry);
120
121 struct StartForwardingInputStruct
122 {
123 SystemAddress source;
124 SystemAddress destination;
125 SLNet::TimeMS timeoutOnNoDataMS;
126 RakString forceHostAddress;
127 unsigned short socketFamily;
128 unsigned int inputId;
129 };
130
131 DataStructures::ThreadsafeAllocatingQueue<StartForwardingInputStruct> startForwardingInput;
132
133 struct StartForwardingOutputStruct
134 {
135 unsigned short forwardingPort;
136 __UDPSOCKET__ forwardingSocket;
137 UDPForwarderResult result;
138 unsigned int inputId;
139 };
140 DataStructures::Queue<StartForwardingOutputStruct> startForwardingOutput;
141 SimpleMutex startForwardingOutputMutex;
142
143 struct StopForwardingStruct
144 {
145 SystemAddress source;
146 SystemAddress destination;
147 };
148 DataStructures::ThreadsafeAllocatingQueue<StopForwardingStruct> stopForwardingCommands;
149 unsigned int nextInputId;
150
151 // New entries are added to forwardListNotUpdated
152 DataStructures::List<ForwardEntry*> forwardListNotUpdated;
153 // SimpleMutex forwardListNotUpdatedMutex;
154
155 unsigned short maxForwardEntries;
156 SLNet::LocklessUint32_t isRunning, threadRunning;
157
158 };
159
160 } // End namespace
161
162 #endif
163
164 #endif // #if _RAKNET_SUPPORT_UDPForwarder==1