8 #include <sys/socket.h>
24 #else #ifdef USE_BOOST
25 #include <boost/thread.hpp>
26 #include <boost/signals2/mutex.hpp>
29 #include "NetBuffer.h"
30 #include "NetConnectionType.h"
31 #include "NetChannel.h"
33 #include "LibraryMessageType.h"
37 #define NET_SLEEP(x) Wait (x / 1000.0)
39 #define NET_SLEEP(x) usleep(x * 1000.0);
42 #define SEND_FAILED_BUFFER_ALREADY_SENT -1000000000
43 #define SEND_FAILED_BUFFER_INVALID -1000000001
44 #define SEND_FAILED_UNKNOWN_ERROR -10000000002
46 #define MAX_RECEIVE_BUFFER_SIZE 1024
47 #define MAX_MESSAGE_TRACK 256 // 256 gives us ample time to wait for an ACK. ~ 5 messages per frame * 50 frames per second gives us 6 extra packets.
50 using namespace Network;
59 enum InternalMessageType
65 struct MessageAwaitingACK
74 NetConnection* recipient;
87 NetPeer(
char * ip,
int port, NetConnectionType connType);
96 int Open(
int options=0, ...);
112 void SendRaw(
NetBuffer* nb, NetConnection* nc);
113 virtual void CheckMessages();
117 vector<NetConnection*> m_netConnections;
118 void InternalPlatformConnectionListSynchronizationEnter();
119 void InternalPlatformConnectionListSynchronizationLeave();
121 static const double kResendPacketTime;
124 static INT32 InternalPlatformUpdateTaskWrapper(UINT32 instance);
125 static INT32 InternalPlatformMessageVerificationTaskWrapper(UINT32 instance);
127 #else #ifdef USE_BOOST
128 static INT32 InternalPlatformUpdateTaskWrapper(
NetPeer* instance);
129 static INT32 InternalPlatformMessageVerificationTaskWrapper(
NetPeer* instance);
132 void InternalPlatformQueueSynchronizationCreate();
133 void InternalPlatformQueueSynchronizationEnter();
135 void InternalPlatformQueueSynchronizationLeave();
137 void InternalPlatformConnectionListSynchronizationCreate();
140 void InternalPlatformReliableUnorderedQueueSynchronizationCreate();
141 void InternalPlatformReliableUnorderedQueueSynchronizationEnter();
142 void InternalPlatformReliableUnorderedQueueSynchronizationLeave();
145 void InternalPlatformReliableSequencedQueueSynchronizationCreate();
146 void InternalPlatformReliableSequencedQueueSynchronizationEnter();
147 void InternalPlatformReliableSequencedQueueSynchronizationLeave();
150 void InternalPlatformReliableInOrderQueueSynchronizationCreate();
151 void InternalPlatformReliableInOrderQueueSynchronizationEnter();
152 void InternalPlatformReliableInOrderQueueSynchronizationLeave();
154 void InternalPlatformCreateUpdateTasks();
155 void InternalPlatformRunUpdateTasks();
156 void InternalPlatformDestroyUpdateTasks();
162 SEM_ID m_msgQueueMutex;
164 SEM_ID m_connectionListMutex;
166 SEM_ID m_reliableUnorderedQueueMutex, m_reliableSequencedQueueMutex, m_reliableInOrderQueueMutex;
168 Task* m_internalUpdateTask;
169 Task* m_internalMessageVerificationTask;
171 #else #ifdef USE_BOOST
172 boost::signals2::mutex* m_msgQueueMutex;
173 boost::signals2::mutex* m_connectionListMutex;
174 boost::signals2::mutex* m_reliableUnorderedQueueMutex, *m_reliableSequencedQueueMutex, *m_reliableInOrderQueueMutex;
176 boost::thread* m_internalUpdateTask;
177 boost::thread* m_internalMessageVerificationTask;
180 queue<NetBuffer*> m_receivedMessages;
182 NetConnectionType m_connType;
187 sockaddr_in m_socketEndpoint;
189 map<int, MessageAwaitingACK> m_reliableUnordered[16];
190 map<int, MessageAwaitingACK> m_reliableSequenced[16];
191 map<int, MessageAwaitingACK> m_reliableOrdered[16];
193 int* m_lastUnreliableSequenced;
194 int* m_lastReliableSequenced;
196 int m_currentReliableUnorderedCounter;
197 int m_currentReliableSequencedCounter;
198 int m_currentReliableOrderedCounter;
199 int m_currentUnreliableSequencedCounter;