Ejemplo n.º 1
0
        PipeFilterResult DoFilter_BeforeWriting(ref SmartBuffer buffer, SortedSet <PipeFilter> filters, CancellationToken cancellationToken)
        {
            PipeFilterResult rt = default;

            foreach (var f in filters)
            {
                _logger?.LogInformation($"DefaultPipe DoFilter_BeforeWriting {f.ToString()}...");
                PipeFilterContext ctx = new PipeFilterContext(f.Client, buffer.Memory, buffer.SignificantLength);
                try
                {
                    rt = f.BeforeWriting(ctx);
                    if (!rt.Continue || cancellationToken.IsCancellationRequested)
                    {
                        buffer.Dispose();
                        rt.Buffer?.Dispose();
                        break;
                    }
                    buffer.Dispose();
                    buffer = rt.Buffer;
                    //next filter
                }
                catch (Exception ex)
                {
                    _logger?.LogError(ex, $"DefaultPipe DoFilter_BeforeWriting {f.ToString()} error.");
                    buffer.Dispose();
                    rt = new PipeFilterResult(ctx.Client, null, false);
                    break;
                }
            }

            return(rt);
        }
Ejemplo n.º 2
0
        public override PipeFilterResult AfterReading(PipeFilterContext ctx)
        {
            _logger?.LogInformation($"TestPipeFilter AfterReading data={ctx.Memory.ToArray().ToHexString()}");
            var newBuff = SmartBuffer.Rent(ctx.Memory.Length - 4);

            ctx.Memory.Slice(4).CopyTo(newBuff.Memory);
            newBuff.SignificantLength = ctx.Memory.Length - 4;
            return(new PipeFilterResult(ctx.Client, newBuff, true));
        }
Ejemplo n.º 3
0
        public override PipeFilterResult BeforeWriting(PipeFilterContext ctx)
        {
            _logger?.LogInformation($"TestPipeFilter BeforeWriting data={ctx.Memory.ToArray().ToHexString()}");
            var newBuff = SmartBuffer.Rent(ctx.Memory.Length + 4);
            var p       = newBuff.Memory.Span;

            p[0] = 0x12;
            p[1] = 0x34;
            p[4] = 0xAB;
            p[3] = 0xCD;
            ctx.Memory.CopyTo(newBuff.Memory.Slice(4));
            newBuff.SignificantLength = ctx.Memory.Length + 4;
            return(new PipeFilterResult(ctx.Client, newBuff, true));
        }
Ejemplo n.º 4
0
 public abstract PipeFilterResult BeforeWriting(PipeFilterContext filterContext);
Ejemplo n.º 5
0
 public abstract PipeFilterResult AfterReading(PipeFilterContext filterContext);