Exemplo n.º 1
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="nonAcked">TBD</param>
 /// <param name="nacked">TBD</param>
 /// <param name="maxSeq">TBD</param>
 /// <returns>TBD</returns>
 public AckedSendBuffer <T> Copy(List <T> nonAcked = null, List <T> nacked = null, SeqNo maxSeq = null)
 {
     return(new AckedSendBuffer <T>(Capacity, maxSeq ?? MaxSeq)
     {
         Nacked = nacked ?? Nacked.ToArray().ToList(), NonAcked = nonAcked ?? NonAcked.ToArray().ToList()
     });
 }
Exemplo n.º 2
0
        /// <summary>
        /// Processes an incoming acknowledgement and returns a new buffer with only unacknowledged elements remaining.
        /// </summary>
        /// <param name="ack">The received acknowledgement</param>
        /// <exception cref="ResendUnfulfillableException">Thrown if we couldn't fit all of the nacks stored inside <see cref="Ack"/> onto the buffer.</exception>
        /// <returns>An updated buffer containing the remaining unacknowledged messages</returns>
        public AckedSendBuffer <T> Acknowledge(Ack ack)
        {
            var newNacked = new List <T>(Nacked.Concat(NonAcked)).Where(x => ack.Nacks.Contains(x.Seq)).ToList();

            if (newNacked.Count < ack.Nacks.Count)
            {
                throw new ResendUnfulfillableException();
            }
            else
            {
                return(Copy(nonAcked: NonAcked.Where(x => x.Seq > ack.CumulativeAck).ToList(), nacked: newNacked));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Processes an incoming acknowledgement and returns a new buffer with only unacknowledged elements remaining.
        /// </summary>
        /// <param name="ack">The received acknowledgement</param>
        /// <exception cref="ResendUnfulfillableException">Thrown if we couldn't fit all of the nacks stored inside <see cref="Ack"/> onto the buffer.</exception>
        /// <returns>An updated buffer containing the remaining unacknowledged messages</returns>
        public AckedSendBuffer <T> Acknowledge(Ack ack)
        {
            if (ack.CumulativeAck > MaxSeq)
            {
                throw new ArgumentException(nameof(ack), $"Highest SEQ so far was {MaxSeq} but cumulative ACK is {ack.CumulativeAck}");
            }

            var newNacked = ack.Nacks.Count == 0
                ? ImmutableList <T> .Empty
                : Nacked.AddRange(NonAcked).Where(x => ack.Nacks.Contains(x.Seq)).ToImmutableList();

            if (newNacked.Count < ack.Nacks.Count)
            {
                throw new ResendUnfulfillableException();
            }
            else
            {
                return(Copy(nonAcked: NonAcked.Where(x => x.Seq > ack.CumulativeAck).ToImmutableList(), nacked: newNacked));
            }
        }