/// <summary> /// Acquires a new processing context for the given channel and settings. /// </summary> /// <param name="channel">The channel to acquire the context for.</param> /// <param name="settings">The type of the context.</param> /// <returns>An acquired <see cref="ProcessingContext"/>.</returns> internal static ProcessingContext Acquire(Emitter.Connection channel, ProcessingSettings settings) { // Acquire a new procesing context var context = Pool.Acquire(); // Fills a new pipeline; var processors = settings.Processors; for (int i = 0; i < processors.Length; ++i) { context.Processors[i] = processors[i]; } context.Count = processors.Length; // Fills the fields accordingly context.Channel = channel; context.Settings = settings; context.Segments = settings.Segments; context.BufferProvider = settings.BufferProvider; context.Session = null; context.Buffer = null; context.ReceiveLock = settings.Segments; return(context); }
public ConnectionContext(ConnectionContext context) : base(context) { this.SocketInput = context.SocketInput; this.SocketOutput = context.SocketOutput; this.RemoteEndPoint = context.RemoteEndPoint; this.LocalEndPoint = context.LocalEndPoint; this.ConnectionId = context.ConnectionId; this.DecodingSettings = new ProcessingSettings(ProcessingType.Decoding, context.Binding.Decoding); this.EncodingSettings = new ProcessingSettings(ProcessingType.Encoding, context.Binding.Encoding); }
/// <summary> /// Recycles the context. /// </summary> public override void Recycle() { // Reset properties this.Settings = null; this.Channel = null; this.Buffer = null; this.Segments = null; this.BufferProvider = null; this.Current = 0; this.Count = 0; this.ReceiveLock = null; // If we have a session object set if (this.Session != null) { // Attempt to release or dispose the session if (this.Session is RecyclableObject) { ((RecyclableObject)this.Session).TryRelease(); } else if (this.Session is IDisposable) { ((IDisposable)this.Session).Dispose(); } } // Reset the session this.Session = null; // If we have a packet set, attempt to release it if (this.Packet != null && this.Packet.Lifetime == PacketLifetime.Automatic && this.Packet.IsPooled) { this.Packet.TryRelease(); this.Packet = null; } }
public ConnectionContext(ListenerContext context) : base(context) { this.DecodingSettings = new ProcessingSettings(ProcessingType.Decoding, context.Binding.Decoding); this.EncodingSettings = new ProcessingSettings(ProcessingType.Encoding, context.Binding.Encoding); }