protected override void OnProtocolHeader(ProtocolHeader header) { #if DEBUG header.Trace(false); AmqpTrace.Provider.AmqpLogOperationVerbose(this, TraceOperation.Receive, header); #endif this.heartBeat.OnReceive(); if (this.UsageMeter != null) { this.UsageMeter.OnRead(this, 0, header.EncodeSize); } this.TransitState("R:HDR", StateTransition.ReceiveHeader); Exception exception = null; if (this.isInitiator) { if (!this.initialHeader.Equals(header)) { exception = new AmqpException(AmqpErrorCode.NotImplemented, AmqpResources.GetString(AmqpResources.AmqpProtocolVersionNotSupported, this.initialHeader.ToString(), header.ToString())); } } else { ProtocolHeader supportedHeader = this.amqpSettings.GetSupportedHeader(header); this.SendProtocolHeader(supportedHeader); if (!supportedHeader.Equals(header)) { exception = new AmqpException(AmqpErrorCode.NotImplemented, AmqpResources.GetString(AmqpResources.AmqpProtocolVersionNotSupported, this.initialHeader.ToString(), header.ToString())); } } if (exception != null) { this.CompleteOpen(false, exception); } }
void SendProtocolHeader(ProtocolHeader header) { #if DEBUG header.Trace(true); AmqpTrace.Provider.AmqpLogOperationVerbose(this, TraceOperation.Send, header); #endif this.TransitState("S:HDR", StateTransition.SendHeader); this.SendDatablock(header); }
void OnReadHeaderComplete(TransportAsyncCallbackArgs args) { if (args.Exception != null) { AmqpTrace.Provider.AmqpLogError(this, "ReadHeader", args.Exception.Message); this.Complete(args); return; } try { ProtocolHeader receivedHeader = new ProtocolHeader(); receivedHeader.Decode(new ByteBuffer(args.Buffer, args.Offset, args.Count)); #if DEBUG receivedHeader.Trace(false); AmqpTrace.Provider.AmqpLogOperationVerbose(this, TraceOperation.Receive, receivedHeader); #endif if (!receivedHeader.Equals(this.sentHeader)) { // TODO: need to reconnect with the reply version if supported throw new AmqpException(AmqpErrorCode.NotImplemented, AmqpResources.GetString(AmqpResources.AmqpProtocolVersionNotSupported, this.sentHeader, receivedHeader)); } // upgrade transport TransportBase secureTransport = this.settings.TransportProviders[this.providerIndex].CreateTransport(args.Transport, true); AmqpTrace.Provider.AmqpUpgradeTransport(this, args.Transport, secureTransport); args.Transport = secureTransport; IAsyncResult result = args.Transport.BeginOpen(this.timeoutHelper.RemainingTime(), this.OnTransportOpenCompete, args); if (result.CompletedSynchronously) { this.HandleTransportOpened(result); } } catch (Exception exp) { if (Fx.IsFatal(exp)) { throw; } AmqpTrace.Provider.AmqpLogError(this, "OnProtocolHeader", exp.Message); args.Exception = exp; this.Complete(args); } }