public ProtocolHeader ExtractProtocolHeader(ByteBuffer buffer) { if (buffer.Length < AmqpConstants.ProtocolHeaderSize) { return null; } ProtocolHeader header = new ProtocolHeader(); header.Decode(buffer); return 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); } }
void OnReceiveFrameBuffer(ByteBuffer buffer) { if (this.State <= AmqpObjectState.OpenClosePipe) { Fx.Assert(buffer.Length == AmqpConstants.ProtocolHeaderSize, "protocol header size is wrong"); try { ProtocolHeader header = new ProtocolHeader(); header.Decode(buffer); this.OnProtocolHeader(header); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } AmqpTrace.Provider.AmqpLogError(this, "OnProtocolHeader", exception.Message); this.TerminalException = exception; this.Abort(); } } else { try { this.OnFrameBuffer(buffer); } catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } AmqpTrace.Provider.AmqpLogError(this, "OnFrame", exception.Message); this.SafeClose(exception); } } }