private void setConnectSuccess(IChannelHandlerContext context)
        {
            finished = true;

            cancelConnectTimeoutFuture();

            if (connectPromise.IsCompleted)
            {
                bool removedCodec = true;

                removedCodec &= safeRemoveEncoder(context);

                context.FireUserEventTriggered(new ProxyConnectionEvent(protocol(), authScheme(), proxyAddress, destinationAddress));

                removedCodec &= safeRemoveDecoder(context);

                if (removedCodec)
                {
                    writePendingWrites();

                    if (flushedPrematurely)
                    {
                        context.Flush();
                    }
                    //connectPromise.TrySetResult(ctx.Channel);
                }
                else
                {
                    // We are at inconsistent state because we failed to remove all codec handlers.
                    Exception cause = new ProxyConnectException("failed to remove all codec handlers added by the proxy handler; bug?", new Exception("failed to remove all codec handlers added by the proxy handler; bug?"));

                    failPendingWritesAndClose(cause);
                }
            }
        }
 public override void ChannelInactive(IChannelHandlerContext context)
 {
     if (finished)
     {
         context.FireChannelInactive();
     }
     else
     {
         // Disconnected before connected to the destination.
         ctx_c          = context;
         ConnectFailure = new ProxyConnectException("Disconnected", new Exception("disconnected"));
     }
 }