Пример #1
0
        public INotifyToken Send(byte[] packet)
        {
            if (sent.Count >= MaxSentQueue)
            {
                throw new InvalidOperationException("Sent queue is full");
            }

            ushort sequence = ackSystem.Send(packet);

            // todo use pool to stop allocations
            var token = new NotifyToken(sequence);

            sent.Enqueue(token);
            return(token);
        }
Пример #2
0
        private void NotifySent(ReceivedPacket received)
        {
            while (sent.Count > 0)
            {
                NotifyToken token = sent.Peek();

                int distance = (int)ackSystem.sequencer.Distance(received.receivedSequence, token.Sequence);

                // negative distance means next is sent after last ack, so nothing to ack yet
                if (distance < 0)
                {
                    return;
                }

                // positive distance means it should have been acked, or mark it as lost
                sent.Dequeue();

                // if distance above size then it is outside of mask, so set as lost
                bool lost = OutsideOfMask(distance) || NotInMask(distance, received.receivedMask);

                token.Notify(!lost);
            }
        }