From 0149265ee83581cf2fb150dcd5d8734c02926261 Mon Sep 17 00:00:00 2001 From: CasperW Date: Sat, 21 Nov 2009 15:36:38 +0100 Subject: Improved avatar responsiveness. --- .../Region/ClientStack/LindenUDP/LLClientView.cs | 4 +- .../Region/ClientStack/LindenUDP/LLUDPServer.cs | 24 +++--- .../Region/ClientStack/LindenUDP/OpenSimUDPBase.cs | 89 +++++++++++++++++++--- 3 files changed, 91 insertions(+), 26 deletions(-) (limited to 'OpenSim/Region/ClientStack/LindenUDP') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index 49b9378..39eb968 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -3121,7 +3121,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP objupdate.ObjectData = new ObjectUpdatePacket.ObjectDataBlock[1]; objupdate.ObjectData[0] = CreateAvatarUpdateBlock(data); - OutPacket(objupdate, ThrottleOutPacketType.Task); } @@ -3172,8 +3171,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP terse.ObjectData[i] = m_avatarTerseUpdates.Dequeue(); } - // HACK: Using the task category until the tiered reprioritization code is in - OutPacket(terse, ThrottleOutPacketType.Task); + OutPacket(terse, ThrottleOutPacketType.State); } public void SendCoarseLocationUpdate(List users, List CoarseLocations) diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index 0b05ed9..4a7bdfe 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -571,23 +571,25 @@ namespace OpenSim.Region.ClientStack.LindenUDP //Sorry, i know it's not optimal, but until the LL client //manages packets correctly and re-orders them as required, this is necessary. - if (outgoingPacket.Type == PacketType.ImprovedTerseObjectUpdate - || outgoingPacket.Type == PacketType.ChatFromSimulator - || outgoingPacket.Type == PacketType.ObjectUpdate - || outgoingPacket.Type == PacketType.LayerData) + + // Put the UDP payload on the wire + if (outgoingPacket.Type == PacketType.ImprovedTerseObjectUpdate) { - sendSynchronous = true; + SyncBeginPrioritySend(buffer, 2); // highest priority } - - // Put the UDP payload on the wire - if (sendSynchronous == true) + else if (outgoingPacket.Type == PacketType.ObjectUpdate + || outgoingPacket.Type == PacketType.ChatFromSimulator + || outgoingPacket.Type == PacketType.LayerData) { - SyncBeginSend(buffer); + SyncBeginPrioritySend(buffer, 1); // medium priority } else { - AsyncBeginSend(buffer); + SyncBeginPrioritySend(buffer, 0); // normal priority } + + //AsyncBeginSend(buffer); + // Keep track of when this packet was sent out (right now) outgoingPacket.TickCount = Environment.TickCount & Int32.MaxValue; } @@ -862,7 +864,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP Buffer.BlockCopy(packetData, 0, buffer.Data, 0, length); - AsyncBeginSend(buffer); + SyncBeginPrioritySend(buffer, 1); //Setting this to a medium priority should help minimise resends } private bool IsClientAuthorized(UseCircuitCodePacket useCircuitCode, out AuthenticateResponse sessionInfo) 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; using System.Net; using System.Net.Sockets; using System.Threading; +using System.Collections.Generic; using log4net; namespace OpenMetaverse @@ -52,12 +53,25 @@ namespace OpenMetaverse /// Local IP address to bind to in server mode protected IPAddress m_localBindAddress; + /// + /// Standard queue for our outgoing SyncBeginPrioritySend + /// + private List m_standardQueue = new List(); + + /// + /// Prioritised queue for our outgoing SyncBeginPrioritySend + /// + private List m_priorityQueue = new List(); + /// UDP socket, used in either client or server mode private Socket m_udpSocket; /// Flag to process packets asynchronously or synchronously private bool m_asyncPacketHandling; + /// Are we currently sending data asynchronously? + private volatile bool m_sendingData = false; + /// The all important shutdown flag private volatile bool m_shutdownFlag = true; @@ -246,25 +260,48 @@ namespace OpenMetaverse } } - public void SyncBeginSend(UDPPacketBuffer buf) + public void SyncBeginPrioritySend(UDPPacketBuffer buf, int Priority) { if (!m_shutdownFlag) { - try + if (!m_sendingData) { - m_udpSocket.SendTo( - buf.Data, - 0, - buf.DataLength, - SocketFlags.None, - buf.RemoteEndPoint); + m_sendingData = true; + try + { + AsyncBeginSend(buf); + } + catch (SocketException) { } + catch (ObjectDisposedException) { } + } + else + { + if (Priority == 2) + { + lock (m_priorityQueue) + { + m_priorityQueue.Add(buf); + } + } + else + { + lock (m_standardQueue) + { + if (Priority != 0) + { + m_standardQueue.Insert(0, buf); + } + else + { + m_standardQueue.Add(buf); + } + } + } } - catch (SocketException) { } - catch (ObjectDisposedException) { } } } - public void AsyncBeginSend(UDPPacketBuffer buf) + private void AsyncBeginSend(UDPPacketBuffer buf) { if (!m_shutdownFlag) { @@ -288,8 +325,36 @@ namespace OpenMetaverse { try { -// UDPPacketBuffer buf = (UDPPacketBuffer)result.AsyncState; m_udpSocket.EndSendTo(result); + + if (m_sendingData) + { + lock (m_priorityQueue) + { + if (m_priorityQueue.Count > 0) + { + UDPPacketBuffer buf = m_priorityQueue[0]; + m_priorityQueue.RemoveAt(0); + AsyncBeginSend(buf); + } + else + { + lock (m_standardQueue) + { + if (m_standardQueue.Count > 0) + { + UDPPacketBuffer buf = m_standardQueue[0]; + m_standardQueue.RemoveAt(0); + AsyncBeginSend(buf); + } + else + { + m_sendingData = false; + } + } + } + } + } } catch (SocketException) { } catch (ObjectDisposedException) { } -- cgit v1.1