public DefaultChannelPipeline(ChannelBase channel)
 {
     _isReg     = false;
     _channel   = channel;
     _head      = new HeadContext(_channel);
     _tail      = new TailContext(_channel);
     _head.Next = _tail;
     _tail.Prev = _head;
 }
        private void SyncRemove(ChannleHandlerContext context)
        {
            ChannleHandlerContext prevContext = context.Prev;
            ChannleHandlerContext nextContext = context.Next;

            prevContext.Next = nextContext;
            nextContext.Prev = prevContext;

            context.Handler.HandlerUninstalled(context);
        }
        private void SyncAddFirst(IChannelHandler handler)
        {
            DefaultChannelHandlerContext newContext  = new DefaultChannelHandlerContext(_channel, handler);
            ChannleHandlerContext        nextContext = this._head.Next;

            newContext.Next  = nextContext;
            newContext.Prev  = this._head;
            this._head.Next  = newContext;
            nextContext.Prev = newContext;

            newContext.Handler.HandlerInstalled(newContext);
        }
 /// <summary>
 /// 从尾部开始删除
 /// </summary>
 /// <param name="ctx"></param>
 private void SyncClear(ChannleHandlerContext ctx)
 {
     for (;;)
     {
         if (ctx == this._head)
         {
             break;
         }
         SyncRemove(ctx);
         ctx = ctx.Prev;
     }
 }
        private void SyncAddLast(IChannelHandler handler)
        {
            DefaultChannelHandlerContext newContext  = new DefaultChannelHandlerContext(_channel, handler);
            ChannleHandlerContext        prevContext = this._tail.Prev;

            newContext.Prev  = prevContext;
            newContext.Next  = this._tail;
            this._tail.Prev  = newContext;
            prevContext.Next = newContext;

            newContext.Handler.HandlerInstalled(newContext);
        }
        private void SyncRemove(Type handlertype)
        {
            ChannleHandlerContext nextContext = _head.Next;

            while (nextContext != _tail)
            {
                if (handlertype.IsInstanceOfType(nextContext))
                {
                    SyncRemove(nextContext);
                }
                nextContext = nextContext.Next;
            }
        }
 public IChannelPipeline Remove(ChannleHandlerContext context)
 {
     if (!_isReg)
     {
         SyncRemove(context);
         return(this);
     }
     if (_channel.Loop.InCurrentThread())
     {
         SyncRemove(context);
     }
     else
     {
         _channel.Loop.Execute(new DefaultRunnable <ChannleHandlerContext>(SyncRemove, context));
     }
     return(this);
 }