private void ProcessQueues() { // Process all the pending adds OutgoingPacket pendingAdd; while (m_pendingAdds.TryDequeue(out pendingAdd)) { m_packets[pendingAdd.SequenceNumber] = pendingAdd; } // Process all the pending removes, including updating statistics and round-trip times PendingAck pendingRemove; OutgoingPacket ackedPacket; while (m_pendingRemoves.TryDequeue(out pendingRemove)) { if (m_packets.TryGetValue(pendingRemove.SequenceNumber, out ackedPacket)) { m_packets.Remove(pendingRemove.SequenceNumber); // Update stats System.Threading.Interlocked.Add(ref ackedPacket.Agent.UnackedBytes, -ackedPacket.Buffer.DataLength); if (!pendingRemove.FromResend) { // Calculate the round-trip time for this packet and its ACK int rtt = pendingRemove.RemoveTime - ackedPacket.TickCount; if (rtt > 0) { ackedPacket.Agent.UpdateRoundTrip(rtt); } } } } }
private void ProcessQueues() { // Process all the pending adds OutgoingPacket pendingAdd; while (m_pendingAdds.TryDequeue(out pendingAdd)) { if (pendingAdd != null) { m_packets[pendingAdd.SequenceNumber] = pendingAdd; } } // Process all the pending removes, including updating statistics and round-trip times PendingAck pendingAcknowledgement; while (m_pendingAcknowledgements.TryDequeue(out pendingAcknowledgement)) { //m_log.DebugFormat("[UNACKED PACKET COLLECTION]: Processing ack {0}", pendingAcknowledgement.SequenceNumber); OutgoingPacket ackedPacket; if (m_packets.TryGetValue(pendingAcknowledgement.SequenceNumber, out ackedPacket)) { if (ackedPacket != null) { m_packets.Remove(pendingAcknowledgement.SequenceNumber); // As with other network applications, assume that an acknowledged packet is an // indication that the network can handle a little more load, speed up the transmission ackedPacket.Client.FlowThrottle.AcknowledgePackets(1); // Update stats Interlocked.Add(ref ackedPacket.Client.UnackedBytes, -ackedPacket.Buffer.DataLength); if (!pendingAcknowledgement.FromResend) { // Calculate the round-trip time for this packet and its ACK int rtt = pendingAcknowledgement.RemoveTime - ackedPacket.TickCount; if (rtt > 0) { ackedPacket.Client.UpdateRoundTrip(rtt); } } } else { // m_log.WarnFormat("[UNACKED PACKET COLLECTION]: found null packet for sequence number {0} to ack", // pendingAcknowledgement.SequenceNumber); } } else { // m_log.WarnFormat("[UNACKED PACKET COLLECTION]: Could not find packet with sequence number {0} to ack", // pendingAcknowledgement.SequenceNumber); } } uint pendingRemove; while (m_pendingRemoves.TryDequeue(out pendingRemove)) { OutgoingPacket removedPacket; if (m_packets.TryGetValue(pendingRemove, out removedPacket)) { if (removedPacket != null) { m_packets.Remove(pendingRemove); // Update stats Interlocked.Add(ref removedPacket.Client.UnackedBytes, -removedPacket.Buffer.DataLength); } } } }