aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorDan Lake2011-04-21 15:40:32 -0700
committerDan Lake2011-04-21 15:40:32 -0700
commit7f28dd4b3195e020eed51fa1229083123935125b (patch)
tree107c7d01b4d27ff72f7e5f70d13ebf95d2564e70 /OpenSim
parentMerge branch 'master' into queuetest (diff)
downloadopensim-SC-7f28dd4b3195e020eed51fa1229083123935125b.zip
opensim-SC-7f28dd4b3195e020eed51fa1229083123935125b.tar.gz
opensim-SC-7f28dd4b3195e020eed51fa1229083123935125b.tar.bz2
opensim-SC-7f28dd4b3195e020eed51fa1229083123935125b.tar.xz
Refactor UnackedPacketCollection so ProcessQueues will handle Adds, Acks, and Removes in that order.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs4
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs56
2 files changed, 34 insertions, 26 deletions
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs
index bd58ddc..aff90c5 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs
@@ -672,7 +672,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
672 if (packet.Header.AppendedAcks && packet.Header.AckList != null) 672 if (packet.Header.AppendedAcks && packet.Header.AckList != null)
673 { 673 {
674 for (int i = 0; i < packet.Header.AckList.Length; i++) 674 for (int i = 0; i < packet.Header.AckList.Length; i++)
675 udpClient.NeedAcks.Remove(packet.Header.AckList[i], now, packet.Header.Resent); 675 udpClient.NeedAcks.Acknowledge(packet.Header.AckList[i], now, packet.Header.Resent);
676 } 676 }
677 677
678 // Handle PacketAck packets 678 // Handle PacketAck packets
@@ -681,7 +681,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
681 PacketAckPacket ackPacket = (PacketAckPacket)packet; 681 PacketAckPacket ackPacket = (PacketAckPacket)packet;
682 682
683 for (int i = 0; i < ackPacket.Packets.Length; i++) 683 for (int i = 0; i < ackPacket.Packets.Length; i++)
684 udpClient.NeedAcks.Remove(ackPacket.Packets[i].ID, now, packet.Header.Resent); 684 udpClient.NeedAcks.Acknowledge(ackPacket.Packets[i].ID, now, packet.Header.Resent);
685 685
686 // We don't need to do anything else with PacketAck packets 686 // We don't need to do anything else with PacketAck packets
687 return; 687 return;
diff --git a/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs b/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs
index 90a87fa..793aefe 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs
@@ -65,7 +65,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
65 /// <summary>Holds packets that need to be added to the unacknowledged list</summary> 65 /// <summary>Holds packets that need to be added to the unacknowledged list</summary>
66 private LocklessQueue<OutgoingPacket> m_pendingAdds = new LocklessQueue<OutgoingPacket>(); 66 private LocklessQueue<OutgoingPacket> m_pendingAdds = new LocklessQueue<OutgoingPacket>();
67 /// <summary>Holds information about pending acknowledgements</summary> 67 /// <summary>Holds information about pending acknowledgements</summary>
68 private LocklessQueue<PendingAck> m_pendingRemoves = new LocklessQueue<PendingAck>(); 68 private LocklessQueue<PendingAck> m_pendingAcknowledgements = new LocklessQueue<PendingAck>();
69 /// <summary>Holds information about pending removals</summary>
70 private LocklessQueue<uint> m_pendingRemoves = new LocklessQueue<uint>();
69 71
70 /// <summary> 72 /// <summary>
71 /// Add an unacked packet to the collection 73 /// Add an unacked packet to the collection
@@ -92,9 +94,9 @@ namespace OpenSim.Region.ClientStack.LindenUDP
92 /// <param name="currentTime">Current value of Environment.TickCount</param> 94 /// <param name="currentTime">Current value of Environment.TickCount</param>
93 /// <remarks>This does not immediately acknowledge the packet, it only 95 /// <remarks>This does not immediately acknowledge the packet, it only
94 /// queues the ack so it can be handled in a thread-safe way later</remarks> 96 /// queues the ack so it can be handled in a thread-safe way later</remarks>
95 public void Remove(uint sequenceNumber, int currentTime, bool fromResend) 97 public void Acknowledge(uint sequenceNumber, int currentTime, bool fromResend)
96 { 98 {
97 m_pendingRemoves.Enqueue(new PendingAck(sequenceNumber, currentTime, fromResend)); 99 m_pendingAcknowledgements.Enqueue(new PendingAck(sequenceNumber, currentTime, fromResend));
98 } 100 }
99 101
100 /// <summary> 102 /// <summary>
@@ -105,21 +107,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP
105 /// </summary> 107 /// </summary>
106 /// <param name="sequenceNumber">Sequence number of the packet to 108 /// <param name="sequenceNumber">Sequence number of the packet to
107 /// acknowledge</param> 109 /// acknowledge</param>
108 /// <remarks>The packet is removed from the collection immediately. 110 /// <remarks>The does not immediately remove the packet, it only queues the removal
109 /// This function is not threadsafe. It must be called by the thread calling GetExpiredPackets.</remarks> 111 /// so it can be handled in a thread safe way later</remarks>
110 public void Remove(uint sequenceNumber) 112 public void Remove(uint sequenceNumber)
111 { 113 {
112 OutgoingPacket removedPacket; 114 m_pendingRemoves.Enqueue(sequenceNumber);
113 if (m_packets.TryGetValue(sequenceNumber, out removedPacket))
114 {
115 if (removedPacket != null)
116 {
117 m_packets.Remove(sequenceNumber);
118
119 // Update stats
120 Interlocked.Add(ref removedPacket.Client.UnackedBytes, -removedPacket.Buffer.DataLength);
121 }
122 }
123 } 115 }
124 116
125 /// <summary> 117 /// <summary>
@@ -179,15 +171,15 @@ namespace OpenSim.Region.ClientStack.LindenUDP
179 m_packets[pendingAdd.SequenceNumber] = pendingAdd; 171 m_packets[pendingAdd.SequenceNumber] = pendingAdd;
180 172
181 // Process all the pending removes, including updating statistics and round-trip times 173 // Process all the pending removes, including updating statistics and round-trip times
182 PendingAck pendingRemove; 174 PendingAck pendingAcknowledgement;
183 OutgoingPacket ackedPacket; 175 while (m_pendingAcknowledgements.TryDequeue(out pendingAcknowledgement))
184 while (m_pendingRemoves.TryDequeue(out pendingRemove))
185 { 176 {
186 if (m_packets.TryGetValue(pendingRemove.SequenceNumber, out ackedPacket)) 177 OutgoingPacket ackedPacket;
178 if (m_packets.TryGetValue(pendingAcknowledgement.SequenceNumber, out ackedPacket))
187 { 179 {
188 if (ackedPacket != null) 180 if (ackedPacket != null)
189 { 181 {
190 m_packets.Remove(pendingRemove.SequenceNumber); 182 m_packets.Remove(pendingAcknowledgement.SequenceNumber);
191 183
192 // As with other network applications, assume that an acknowledged packet is an 184 // As with other network applications, assume that an acknowledged packet is an
193 // indication that the network can handle a little more load, speed up the transmission 185 // indication that the network can handle a little more load, speed up the transmission
@@ -196,16 +188,32 @@ namespace OpenSim.Region.ClientStack.LindenUDP
196 // Update stats 188 // Update stats
197 Interlocked.Add(ref ackedPacket.Client.UnackedBytes, -ackedPacket.Buffer.DataLength); 189 Interlocked.Add(ref ackedPacket.Client.UnackedBytes, -ackedPacket.Buffer.DataLength);
198 190
199 if (!pendingRemove.FromResend) 191 if (!pendingAcknowledgement.FromResend)
200 { 192 {
201 // Calculate the round-trip time for this packet and its ACK 193 // Calculate the round-trip time for this packet and its ACK
202 int rtt = pendingRemove.RemoveTime - ackedPacket.TickCount; 194 int rtt = pendingAcknowledgement.RemoveTime - ackedPacket.TickCount;
203 if (rtt > 0) 195 if (rtt > 0)
204 ackedPacket.Client.UpdateRoundTrip(rtt); 196 ackedPacket.Client.UpdateRoundTrip(rtt);
205 } 197 }
206 } 198 }
207 } 199 }
208 } 200 }
201
202 uint pendingRemove;
203 while(m_pendingRemoves.TryDequeue(out pendingRemove))
204 {
205 OutgoingPacket removedPacket;
206 if (m_packets.TryGetValue(pendingRemove, out removedPacket))
207 {
208 if (removedPacket != null)
209 {
210 m_packets.Remove(pendingRemove);
211
212 // Update stats
213 Interlocked.Add(ref removedPacket.Client.UnackedBytes, -removedPacket.Buffer.DataLength);
214 }
215 }
216 }
209 } 217 }
210 } 218 }
211} \ No newline at end of file 219}