internal Session(Connection connection, Begin begin) { this.connection = connection; this.channel = connection.AddSession(this); this.handleMax = begin.HandleMax; this.localLinks = new Link[1]; this.remoteLinks = new Link[1]; this.incomingList = new LinkedList(); this.outgoingList = new LinkedList(); this.nextOutgoingId = uint.MaxValue - 2u; this.outgoingWindow = begin.IncomingWindow; this.incomingDeliveryId = uint.MaxValue; begin.NextOutgoingId = this.nextOutgoingId; this.state = State.BeginSent; this.SendBegin(begin); }
void OnTransfer(Transfer transfer, ByteBuffer buffer) { bool newDelivery; lock (this.ThisLock) { if (this.incomingWindow-- == 0) { this.SendFlow(new Flow()); } this.nextIncomingId++; newDelivery = transfer.HasDeliveryId && transfer.DeliveryId > this.incomingDeliveryId; if (newDelivery) { this.incomingDeliveryId = transfer.DeliveryId; } } Link link = this.GetLink(transfer.Handle); Delivery delivery = null; if (newDelivery) { delivery = new Delivery() { DeliveryId = transfer.DeliveryId, Link = link, Tag = transfer.DeliveryTag, Settled = transfer.Settled, State = transfer.State }; if (!delivery.Settled) { lock (this.ThisLock) { this.incomingList.Add(delivery); } } } link.OnTransfer(delivery, transfer, buffer); }
void OnDelivery(SequenceNumber deliveryId) { // called with lock held if (this.credit <= 0) { throw new AmqpException(ErrorCode.TransferLimitExceeded, Fx.Format(SRAmqp.DeliveryLimitExceeded, deliveryId)); } this.deliveryCount++; this.credit--; }
internal override void OnAttach(uint remoteHandle, Attach attach) { base.OnAttach(remoteHandle, attach); this.deliveryCount = attach.InitialDeliveryCount; }
internal void OnBegin(ushort remoteChannel, Begin begin) { lock (this.ThisLock) { if (this.state == State.BeginSent) { this.state = State.Opened; } else if (this.state == State.EndPipe) { this.state = State.EndSent; } else { throw new AmqpException(ErrorCode.IllegalState, Fx.Format(SRAmqp.AmqpIllegalOperationState, "OnBegin", this.state)); } this.outgoingWindow = begin.IncomingWindow; this.nextIncomingId = begin.NextOutgoingId; } if (begin.HandleMax < this.handleMax) { this.handleMax = begin.HandleMax; } if (this.onBegin != null) { this.onBegin(this, begin); } }
public int CompareTo(SequenceNumber value) { int delta = this.sequenceNumber - value.sequenceNumber; if (delta == int.MinValue) { // Behavior of comparing 0u-2147483648u, 1u-2147483649u, ... // is undefined, so we do not allow it. throw new AmqpException(ErrorCode.NotAllowed, Fx.Format(SRAmqp.InvalidSequenceNumberComparison, (uint)this.sequenceNumber, (uint)value.sequenceNumber)); } return delta; }