aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs')
-rw-r--r--OpenSim/Region/ClientStack/LindenUDP/UnackedPacketCollection.cs56
1 files changed, 32 insertions, 24 deletions
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}