diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs | 107 |
1 files changed, 105 insertions, 2 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs b/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs index d2779ba..de2cd24 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs | |||
@@ -29,6 +29,7 @@ using System; | |||
29 | using System.Net; | 29 | using System.Net; |
30 | using System.Net.Sockets; | 30 | using System.Net.Sockets; |
31 | using System.Threading; | 31 | using System.Threading; |
32 | using System.Collections.Generic; | ||
32 | using log4net; | 33 | using log4net; |
33 | 34 | ||
34 | namespace OpenMetaverse | 35 | namespace OpenMetaverse |
@@ -52,12 +53,30 @@ namespace OpenMetaverse | |||
52 | /// <summary>Local IP address to bind to in server mode</summary> | 53 | /// <summary>Local IP address to bind to in server mode</summary> |
53 | protected IPAddress m_localBindAddress; | 54 | protected IPAddress m_localBindAddress; |
54 | 55 | ||
56 | /// <summary> | ||
57 | /// Standard queue for our outgoing SyncBeginPrioritySend | ||
58 | /// </summary> | ||
59 | private List<UDPPacketBuffer> m_standardQueue = new List<UDPPacketBuffer>(); | ||
60 | |||
61 | /// <summary> | ||
62 | /// Medium priority queue for our outgoing SyncBeginPrioritySend | ||
63 | /// </summary> | ||
64 | private List<UDPPacketBuffer> m_mediumPriorityQueue = new List<UDPPacketBuffer>(); | ||
65 | |||
66 | /// <summary> | ||
67 | /// Prioritised queue for our outgoing SyncBeginPrioritySend | ||
68 | /// </summary> | ||
69 | private List<UDPPacketBuffer> m_priorityQueue = new List<UDPPacketBuffer>(); | ||
70 | |||
55 | /// <summary>UDP socket, used in either client or server mode</summary> | 71 | /// <summary>UDP socket, used in either client or server mode</summary> |
56 | private Socket m_udpSocket; | 72 | private Socket m_udpSocket; |
57 | 73 | ||
58 | /// <summary>Flag to process packets asynchronously or synchronously</summary> | 74 | /// <summary>Flag to process packets asynchronously or synchronously</summary> |
59 | private bool m_asyncPacketHandling; | 75 | private bool m_asyncPacketHandling; |
60 | 76 | ||
77 | /// <summary>Are we currently sending data asynchronously?</summary> | ||
78 | private volatile bool m_sendingData = false; | ||
79 | |||
61 | /// <summary>The all important shutdown flag</summary> | 80 | /// <summary>The all important shutdown flag</summary> |
62 | private volatile bool m_shutdownFlag = true; | 81 | private volatile bool m_shutdownFlag = true; |
63 | 82 | ||
@@ -246,7 +265,51 @@ namespace OpenMetaverse | |||
246 | } | 265 | } |
247 | } | 266 | } |
248 | 267 | ||
249 | public void AsyncBeginSend(UDPPacketBuffer buf) | 268 | public void SyncBeginPrioritySend(UDPPacketBuffer buf, int Priority) |
269 | { | ||
270 | if (!m_shutdownFlag) | ||
271 | { | ||
272 | if (!m_sendingData) | ||
273 | { | ||
274 | m_sendingData = true; | ||
275 | try | ||
276 | { | ||
277 | AsyncBeginSend(buf); | ||
278 | } | ||
279 | catch (SocketException) { } | ||
280 | catch (ObjectDisposedException) { } | ||
281 | } | ||
282 | else | ||
283 | { | ||
284 | if (Priority == 2) | ||
285 | { | ||
286 | lock (m_priorityQueue) | ||
287 | { | ||
288 | m_priorityQueue.Add(buf); | ||
289 | } | ||
290 | } | ||
291 | else | ||
292 | { | ||
293 | if (Priority != 0) | ||
294 | { | ||
295 | lock (m_mediumPriorityQueue) | ||
296 | { | ||
297 | m_mediumPriorityQueue.Add(buf); | ||
298 | } | ||
299 | } | ||
300 | else | ||
301 | { | ||
302 | lock (m_standardQueue) | ||
303 | { | ||
304 | m_standardQueue.Add(buf); | ||
305 | } | ||
306 | } | ||
307 | } | ||
308 | } | ||
309 | } | ||
310 | } | ||
311 | |||
312 | private void AsyncBeginSend(UDPPacketBuffer buf) | ||
250 | { | 313 | { |
251 | if (!m_shutdownFlag) | 314 | if (!m_shutdownFlag) |
252 | { | 315 | { |
@@ -270,8 +333,48 @@ namespace OpenMetaverse | |||
270 | { | 333 | { |
271 | try | 334 | try |
272 | { | 335 | { |
273 | // UDPPacketBuffer buf = (UDPPacketBuffer)result.AsyncState; | ||
274 | m_udpSocket.EndSendTo(result); | 336 | m_udpSocket.EndSendTo(result); |
337 | |||
338 | if (m_sendingData) | ||
339 | { | ||
340 | lock (m_priorityQueue) | ||
341 | { | ||
342 | if (m_priorityQueue.Count > 0) | ||
343 | { | ||
344 | UDPPacketBuffer buf = m_priorityQueue[0]; | ||
345 | m_priorityQueue.RemoveAt(0); | ||
346 | AsyncBeginSend(buf); | ||
347 | } | ||
348 | else | ||
349 | { | ||
350 | lock (m_mediumPriorityQueue) | ||
351 | { | ||
352 | if (m_mediumPriorityQueue.Count > 0) | ||
353 | { | ||
354 | UDPPacketBuffer buf = m_mediumPriorityQueue[0]; | ||
355 | m_mediumPriorityQueue.RemoveAt(0); | ||
356 | AsyncBeginSend(buf); | ||
357 | } | ||
358 | else | ||
359 | { | ||
360 | lock (m_standardQueue) | ||
361 | { | ||
362 | if (m_standardQueue.Count > 0) | ||
363 | { | ||
364 | UDPPacketBuffer buf = m_standardQueue[0]; | ||
365 | m_standardQueue.RemoveAt(0); | ||
366 | AsyncBeginSend(buf); | ||
367 | } | ||
368 | else | ||
369 | { | ||
370 | m_sendingData = false; | ||
371 | } | ||
372 | } | ||
373 | } | ||
374 | } | ||
375 | } | ||
376 | } | ||
377 | } | ||
275 | } | 378 | } |
276 | catch (SocketException) { } | 379 | catch (SocketException) { } |
277 | catch (ObjectDisposedException) { } | 380 | catch (ObjectDisposedException) { } |