From 0d3a9b45aecdccf5920f1100a407be25c4324b88 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Wed, 17 Dec 2008 18:56:47 +0000 Subject: Marry AckData to LLQueItem, and store packet data and length there for use everywhere. Each packet gets serialized only once now in PacketHandler --- .../ClientStack/LindenUDP/LLPacketHandler.cs | 64 ++++++++++------------ OpenSim/Region/ClientStack/LindenUDP/LLQueItem.cs | 3 + 2 files changed, 31 insertions(+), 36 deletions(-) (limited to 'OpenSim/Region/ClientStack/LindenUDP') diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLPacketHandler.cs b/OpenSim/Region/ClientStack/LindenUDP/LLPacketHandler.cs index 4e8d4f9..83e77b7 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLPacketHandler.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLPacketHandler.cs @@ -99,26 +99,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP // private Dictionary m_PendingAcks = new Dictionary(); - // Dictionary of the packets that need acks from the client. - // - private class AckData - { - public AckData(Packet packet, Object identifier, int tickCount, int resends) - { - Packet = packet; - Identifier = identifier; - TickCount = tickCount; - Resends = resends; - } - - public Packet Packet; - public Object Identifier; - public int TickCount; - public int Resends; - } - - private Dictionary m_NeedAck = - new Dictionary(); + private Dictionary m_NeedAck = + new Dictionary(); /// /// The number of milliseconds that can pass before a packet that needs an ack is resent. @@ -314,6 +296,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP item.throttleType = throttlePacketType; item.TickCount = System.Environment.TickCount; item.Identifier = id; + item.Resends = 0; + item.Bytes = packet.ToBytes(); + item.Length = item.Bytes.Length; m_PacketQueue.Enqueue(item); m_PacketsSent++; @@ -333,7 +318,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (m_DropSafeTimeout > now || intervalMs > 500) // We were frozen! { - foreach (AckData data in new List + foreach (LLQueItem data in new List (m_NeedAck.Values)) { if (m_DropSafeTimeout > now) @@ -364,7 +349,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP int resent = 0; - foreach (AckData data in new List(m_NeedAck.Values)) + foreach (LLQueItem data in new List(m_NeedAck.Values)) { Packet packet = data.Packet; @@ -629,7 +614,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP private void ProcessAck(uint id) { - AckData data; + LLQueItem data; Packet packet; lock (m_NeedAck) @@ -639,10 +624,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP if (!m_NeedAck.TryGetValue(id, out data)) return; - packet = data.Packet; - m_NeedAck.Remove(id); - m_UnackedBytes -= packet.ToBytes().Length; + m_UnackedBytes -= data.Length; } } @@ -676,7 +659,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP lock (m_NeedAck) { foreach (uint key in m_NeedAck.Keys) - info.needAck.Add(key, m_NeedAck[key].Packet.ToBytes()); + info.needAck.Add(key, m_NeedAck[key].Bytes); } LLQueItem[] queitems = m_PacketQueue.GetQueueArray(); @@ -684,7 +667,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP for (int i = 0; i < queitems.Length; i++) { if (queitems[i].Incoming == false) - info.out_packets.Add(queitems[i].Packet.ToBytes()); + info.out_packets.Add(queitems[i].Bytes); } info.sequence = m_Sequence; @@ -695,7 +678,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP public void SetClientInfo(ClientInfo info) { m_PendingAcks = info.pendingAcks; - m_NeedAck = new Dictionary(); + m_NeedAck = new Dictionary(); Packet packet = null; int packetEnd = 0; @@ -714,7 +697,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP { } - m_NeedAck.Add(key, new AckData(packet, null, System.Environment.TickCount, 0)); + LLQueItem item = new LLQueItem(); + item.Packet = packet; + item.Incoming = false; + item.throttleType = 0; + item.TickCount = System.Environment.TickCount; + item.Identifier = 0; + item.Resends = 0; + item.Bytes = packet.ToBytes(); + item.Length = item.Bytes.Length; + m_NeedAck.Add(key, item); } m_Sequence = info.sequence; @@ -738,7 +730,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP private void DropResend(Object id) { - foreach (AckData data in new List(m_NeedAck.Values)) + foreach (LLQueItem data in new List(m_NeedAck.Values)) { if (data.Identifier != null && data.Identifier == id) { @@ -774,12 +766,12 @@ namespace OpenSim.Region.ClientStack.LindenUDP // We want to see that packet arrive if it's reliable if (packet.Header.Reliable) { - m_UnackedBytes += packet.ToBytes().Length; + m_UnackedBytes += item.Length; // Keep track of when this packet was sent out - m_NeedAck[packet.Header.Sequence] = new AckData(packet, - item.Identifier, System.Environment.TickCount, - 0); + item.TickCount = System.Environment.TickCount; + + m_NeedAck[packet.Header.Sequence] = item; } } } @@ -789,7 +781,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP Abort(); // Actually make the byte array and send it - byte[] sendbuffer = packet.ToBytes(); + byte[] sendbuffer = item.Bytes; //m_log.DebugFormat( // "[CLIENT]: In {0} sending packet {1}", diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLQueItem.cs b/OpenSim/Region/ClientStack/LindenUDP/LLQueItem.cs index 494d62b..8df176f 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLQueItem.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLQueItem.cs @@ -42,5 +42,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP public ThrottleOutPacketType throttleType; public int TickCount; public Object Identifier; + public int Resends; + public Byte[] Bytes; + public int Length; } } -- cgit v1.1