void WriteDelivery()

in src/SenderLink.cs [320:380]


        void WriteDelivery(Delivery delivery)
        {
            while (delivery != null)
            {
                delivery.Handle = this.Handle;
                if (delivery.Tag == null)
                {
                    lock (this.ThisLock)
                    {
                        delivery.Tag = Delivery.GetDeliveryTag(this.deliveryCount);
                    }
                }

                try
                {
                    bool settled = delivery.Settled;
                    this.Session.SendDelivery(delivery);
                    if (settled && delivery.OnOutcome != null)
                    {
                        delivery.OnOutcome(this, delivery.Message, new Accepted(), delivery.UserToken);
                    }
                }
                catch
                {
                    lock (this.ThisLock)
                    {
                        this.writing = false;
                    }

                    throw;
                }

                bool shouldClose = false;
                lock (this.ThisLock)
                {
                    delivery = (Delivery)this.outgoingList.First;
                    if (delivery == null || this.credit == 0)
                    {
                        shouldClose = this.CloseCalled;
                        delivery = null;
                        this.writing = false;
                    }
                    else if (this.credit > 0)
                    {
                        this.outgoingList.Remove(delivery);
                        this.credit--;
                        this.deliveryCount++;
                    }
                }

                if (shouldClose)
                {
                    Error error = this.Error;
                    this.OnAbort(error);
                    if (base.OnClose(error))
                    {
                        this.NotifyClosed(error);
                    }
                }
            }
        }