Marry AckData to LLQueItem, and store packet data and length there for

use everywhere. Each packet gets serialized only once now in PacketHandler
0.6.1-post-fixes
Melanie Thielker 2008-12-17 18:56:47 +00:00
parent ff7c8551ba
commit 0d3a9b45ae
2 changed files with 31 additions and 36 deletions

View File

@ -99,26 +99,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
//
private Dictionary<uint, uint> m_PendingAcks = new Dictionary<uint, uint>();
// 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<uint, AckData> m_NeedAck =
new Dictionary<uint, AckData>();
private Dictionary<uint, LLQueItem> m_NeedAck =
new Dictionary<uint, LLQueItem>();
/// <summary>
/// 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<AckData>
foreach (LLQueItem data in new List<LLQueItem>
(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<AckData>(m_NeedAck.Values))
foreach (LLQueItem data in new List<LLQueItem>(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<uint, AckData>();
m_NeedAck = new Dictionary<uint, LLQueItem>();
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<AckData>(m_NeedAck.Values))
foreach (LLQueItem data in new List<LLQueItem>(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}",

View File

@ -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;
}
}