aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs
diff options
context:
space:
mode:
authorCasperW2009-11-21 15:36:38 +0100
committerMelanie2009-11-21 16:50:33 +0000
commit0149265ee83581cf2fb150dcd5d8734c02926261 (patch)
tree2671c9d6d6ba862aa542bf8f5254f59b5556b6b5 /OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs
parentMerge branch 'master' into careminster (diff)
downloadopensim-SC-0149265ee83581cf2fb150dcd5d8734c02926261.zip
opensim-SC-0149265ee83581cf2fb150dcd5d8734c02926261.tar.gz
opensim-SC-0149265ee83581cf2fb150dcd5d8734c02926261.tar.bz2
opensim-SC-0149265ee83581cf2fb150dcd5d8734c02926261.tar.xz
Improved avatar responsiveness.
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs89
1 files changed, 77 insertions, 12 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs b/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs
index 63579ac..45d9170 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/OpenSimUDPBase.cs
@@ -29,6 +29,7 @@ using System;
29using System.Net; 29using System.Net;
30using System.Net.Sockets; 30using System.Net.Sockets;
31using System.Threading; 31using System.Threading;
32using System.Collections.Generic;
32using log4net; 33using log4net;
33 34
34namespace OpenMetaverse 35namespace OpenMetaverse
@@ -52,12 +53,25 @@ 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 /// Prioritised queue for our outgoing SyncBeginPrioritySend
63 /// </summary>
64 private List<UDPPacketBuffer> m_priorityQueue = new List<UDPPacketBuffer>();
65
55 /// <summary>UDP socket, used in either client or server mode</summary> 66 /// <summary>UDP socket, used in either client or server mode</summary>
56 private Socket m_udpSocket; 67 private Socket m_udpSocket;
57 68
58 /// <summary>Flag to process packets asynchronously or synchronously</summary> 69 /// <summary>Flag to process packets asynchronously or synchronously</summary>
59 private bool m_asyncPacketHandling; 70 private bool m_asyncPacketHandling;
60 71
72 /// <summary>Are we currently sending data asynchronously?</summary>
73 private volatile bool m_sendingData = false;
74
61 /// <summary>The all important shutdown flag</summary> 75 /// <summary>The all important shutdown flag</summary>
62 private volatile bool m_shutdownFlag = true; 76 private volatile bool m_shutdownFlag = true;
63 77
@@ -246,25 +260,48 @@ namespace OpenMetaverse
246 } 260 }
247 } 261 }
248 262
249 public void SyncBeginSend(UDPPacketBuffer buf) 263 public void SyncBeginPrioritySend(UDPPacketBuffer buf, int Priority)
250 { 264 {
251 if (!m_shutdownFlag) 265 if (!m_shutdownFlag)
252 { 266 {
253 try 267 if (!m_sendingData)
254 { 268 {
255 m_udpSocket.SendTo( 269 m_sendingData = true;
256 buf.Data, 270 try
257 0, 271 {
258 buf.DataLength, 272 AsyncBeginSend(buf);
259 SocketFlags.None, 273 }
260 buf.RemoteEndPoint); 274 catch (SocketException) { }
275 catch (ObjectDisposedException) { }
276 }
277 else
278 {
279 if (Priority == 2)
280 {
281 lock (m_priorityQueue)
282 {
283 m_priorityQueue.Add(buf);
284 }
285 }
286 else
287 {
288 lock (m_standardQueue)
289 {
290 if (Priority != 0)
291 {
292 m_standardQueue.Insert(0, buf);
293 }
294 else
295 {
296 m_standardQueue.Add(buf);
297 }
298 }
299 }
261 } 300 }
262 catch (SocketException) { }
263 catch (ObjectDisposedException) { }
264 } 301 }
265 } 302 }
266 303
267 public void AsyncBeginSend(UDPPacketBuffer buf) 304 private void AsyncBeginSend(UDPPacketBuffer buf)
268 { 305 {
269 if (!m_shutdownFlag) 306 if (!m_shutdownFlag)
270 { 307 {
@@ -288,8 +325,36 @@ namespace OpenMetaverse
288 { 325 {
289 try 326 try
290 { 327 {
291// UDPPacketBuffer buf = (UDPPacketBuffer)result.AsyncState;
292 m_udpSocket.EndSendTo(result); 328 m_udpSocket.EndSendTo(result);
329
330 if (m_sendingData)
331 {
332 lock (m_priorityQueue)
333 {
334 if (m_priorityQueue.Count > 0)
335 {
336 UDPPacketBuffer buf = m_priorityQueue[0];
337 m_priorityQueue.RemoveAt(0);
338 AsyncBeginSend(buf);
339 }
340 else
341 {
342 lock (m_standardQueue)
343 {
344 if (m_standardQueue.Count > 0)
345 {
346 UDPPacketBuffer buf = m_standardQueue[0];
347 m_standardQueue.RemoveAt(0);
348 AsyncBeginSend(buf);
349 }
350 else
351 {
352 m_sendingData = false;
353 }
354 }
355 }
356 }
357 }
293 } 358 }
294 catch (SocketException) { } 359 catch (SocketException) { }
295 catch (ObjectDisposedException) { } 360 catch (ObjectDisposedException) { }