Example #1
0
        /// <summary>
        /// Used when sending a packet.
        /// </summary>
        internal void GetSLACKSlots(out SACKSlot slot1, out SACKSlot slot2, out SACKSlot slot3, out SACKSlot slot4)
        {
            slot1 = null;
            slot2 = null;
            slot3 = null;
            slot4 = null;

            lock (this)
            {
                if (_slots[0].StartPacketId < 0)
                {
                    return;
                }

                //---- Useful when some ACKs are loosed
                slot1 = _slots[0].Clone();
                _slots[0].ACKsCount = 0;
                Interlocked.Exchange(ref _acksCount, _acksCount - slot1.ACKsCount);

                CheckACKCount();

                //---- Add all the slots
                for (int index = 1; index < _slots.Count; index++)
                {
                    SACKSlot slot = _slots[index];
                    if (slot.ACKsCount > 0)
                    {
                        Interlocked.Exchange(ref _acksCount, _acksCount - slot.ACKsCount);
                        slot.ACKsCount = 0;

                        CheckACKCount();

                        if (slot2 == null)
                        {
                            slot2 = slot.Clone();
                        }
                        else if (slot3 == null)
                        {
                            slot3 = slot.Clone();
                        }
                        else if (slot4 == null)
                        {
                            slot4 = slot.Clone();
                            return;
                        }
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Used when "resending" or sending queued "ACKs"
        /// </summary>
        internal List <SACKSlot> PrepareACKList()
        {
            List <SACKSlot> list = new List <SACKSlot>();

            lock (this)
            {
                //---- Add all the slots, except the first one
                for (int index = 1; index < _slots.Count; index++)
                {
                    SACKSlot slot = _slots[index];
                    if (slot.ACKsCount > 0)
                    {
                        slot.ACKsCount = 0;
                        list.Add(slot.Clone());
                    }
                }

                //---- Add the first slot
                // Useful when some ACKs are loosed
                if (_slots[0].StartPacketId > -1)
                {
                    if (list.Count > 1 || _slots[0].ACKsCount > 0)
                    {
                        _slots[0].ACKsCount = 0;
                        list.Insert(0, _slots[0].Clone());
                    }
                }

                Interlocked.Exchange(ref _acksCount, 0);
            }

            CheckACKCount();

            return(list);
        }