예제 #1
0
        public void InvokeExceptionCaught(IChannelHandlerContext ctx, Exception cause)
        {
            Contract.Requires(cause != null);

            if (Executor.InEventLoop)
            {
                ChannelHandlerInvokerUtil.InvokeExceptionCaughtNow(ctx, cause);
            }
            else
            {
                try
                {
                    Executor.Execute(
                        (c, e) =>
                        ChannelHandlerInvokerUtil.InvokeExceptionCaughtNow((IChannelHandlerContext)c, (Exception)e),
                        ctx, cause);
                }
                catch (Exception t)
                {
                    if (DefaultChannelPipeline.Logger.IsWarningEnabled)
                    {
                        DefaultChannelPipeline.Logger.Warning(
                            "Failed to submit an ExceptionCaught() event. Cause: {0}", t);
                        DefaultChannelPipeline.Logger.Warning(
                            "The ExceptionCaught() event that was failed to submit was: {0}", cause);
                    }
                }
            }
        }
예제 #2
0
 public void InvokeChannelActive(IChannelHandlerContext ctx)
 {
     if (Executor.InEventLoop)
     {
         ChannelHandlerInvokerUtil.InvokeChannelActiveNow(ctx);
     }
     else
     {
         Executor.Execute(c => ChannelHandlerInvokerUtil.InvokeChannelActiveNow((IChannelHandlerContext)c), ctx);
     }
 }
예제 #3
0
 public void InvokeFlush(IChannelHandlerContext ctx)
 {
     if (Executor.InEventLoop)
     {
         ChannelHandlerInvokerUtil.InvokeFlushNow(ctx);
     }
     else
     {
         Executor.Execute(InvokeFlushAction, ctx);
     }
 }
예제 #4
0
 public void InvokeChannelWritabilityChanged(IChannelHandlerContext ctx)
 {
     if (Executor.InEventLoop)
     {
         ChannelHandlerInvokerUtil.InvokeChannelWritabilityChangedNow(ctx);
     }
     else
     {
         Executor.Execute(InvokeChannelWritabilityChangedAction, ctx);
     }
 }
예제 #5
0
 public void InvokeChannelReadComplete(IChannelHandlerContext ctx)
 {
     if (Executor.InEventLoop)
     {
         ChannelHandlerInvokerUtil.InvokeChannelReadCompleteNow(ctx);
     }
     else
     {
         Executor.Execute(InvokeChannelReadCompleteAction, ctx);
     }
 }
예제 #6
0
        public void InvokeChannelRead(IChannelHandlerContext ctx, object msg)
        {
            Contract.Requires(msg != null);

            if (Executor.InEventLoop)
            {
                ChannelHandlerInvokerUtil.InvokeChannelReadNow(ctx, msg);
            }
            else
            {
                SafeProcessInboundMessage(InvokeChannelReadAction, ctx, msg);
            }
        }
예제 #7
0
        public void InvokeUserEventTriggered(IChannelHandlerContext ctx, object evt)
        {
            Contract.Requires(evt != null);

            if (Executor.InEventLoop)
            {
                ChannelHandlerInvokerUtil.InvokeUserEventTriggeredNow(ctx, evt);
            }
            else
            {
                SafeProcessInboundMessage(InvokeUserEventTriggeredAction, ctx, evt);
            }
        }
예제 #8
0
        public Task InvokeDeregisterAsync(IChannelHandlerContext ctx)
        {
            // todo: check for cancellation
            //if (!validatePromise(ctx, promise, false)) {
            //    // promise cancelled
            //    return;
            //}

            if (Executor.InEventLoop)
            {
                return(ChannelHandlerInvokerUtil.InvokeDeregisterAsyncNow(ctx));
            }
            return(SafeExecuteOutboundAsync(() => ChannelHandlerInvokerUtil.InvokeDeregisterAsyncNow(ctx)));
        }
예제 #9
0
        public Task InvokeBindAsync(
            IChannelHandlerContext ctx, EndPoint localAddress)
        {
            Contract.Requires(localAddress != null);
            // todo: check for cancellation
            //if (!validatePromise(ctx, promise, false)) {
            //    // promise cancelled
            //    return;
            //}

            if (Executor.InEventLoop)
            {
                return(ChannelHandlerInvokerUtil.InvokeBindAsyncNow(ctx, localAddress));
            }
            return(SafeExecuteOutboundAsync(() => ChannelHandlerInvokerUtil.InvokeBindAsyncNow(ctx, localAddress)));
        }
예제 #10
0
        public Task InvokeWriteAsync(IChannelHandlerContext ctx, object msg)
        {
            Contract.Requires(msg != null);
            // todo: check for cancellation
            //if (!validatePromise(ctx, promise, false)) {
            //    // promise cancelled
            //    return;
            //}

            if (Executor.InEventLoop)
            {
                return(ChannelHandlerInvokerUtil.InvokeWriteAsyncNow(ctx, msg));
            }
            else
            {
                var promise = new TaskCompletionSource();
                this.SafeExecuteOutbound(WriteTask.NewInstance(ctx, msg, promise), promise, msg);
                return(promise.Task);
            }
        }
        public Task InvokeWriteAsync(IChannelHandlerContext ctx, object msg)
        {
            Contract.Requires(msg != null);
            // todo: check for cancellation
            //if (!validatePromise(ctx, promise, false)) {
            //    // promise cancelled
            //    return;
            //}

            if (Executor.InEventLoop)
            {
                return(ChannelHandlerInvokerUtil.InvokeWriteAsyncNow(ctx, msg));
            }
            var channel = (AbstractChannel)ctx.Channel;
            var promise = new TaskCompletionSource(ctx);

            try
            {
                var size = channel.EstimatorHandle.Size(msg);
                if (size > 0)
                {
                    var buffer = channel.Unsafe.OutboundBuffer;
                    // Check for null as it may be set to null if the channel is closed already
                    if (buffer != null)
                    {
                        buffer.IncrementPendingOutboundBytes(size);
                    }
                }

                Executor.Execute(InvokeWriteAsyncAction, promise, msg);
            }
            catch (Exception cause)
            {
                ReferenceCountUtil.Release(msg);
                promise.TrySetException(cause);
            }
            return(promise.Task);
        }
예제 #12
0
            public void Run()
            {
                try
                {
                    ChannelOutboundBuffer buffer = this.ctx.Channel.Unsafe.OutboundBuffer;
                    // Check for null as it may be set to null if the channel is closed already
                    if (EstimateTaskSizeOnSubmit)
                    {
                        buffer?.DecrementPendingOutboundBytes(this.size);
                    }
                    ChannelHandlerInvokerUtil.InvokeWriteAsyncNow(this.ctx, this.msg).LinkOutcome(this.promise);
                }
                finally
                {
                    // Set to null so the GC can collect them directly
                    this.ctx     = null;
                    this.msg     = null;
                    this.promise = null;

                    // recycle
                    _handle.Free(this);
                }
            }