Example #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);
                    }
                }
            }
        }
Example #2
0
 public void InvokeChannelActive(IChannelHandlerContext ctx)
 {
     if (Executor.InEventLoop)
     {
         ChannelHandlerInvokerUtil.InvokeChannelActiveNow(ctx);
     }
     else
     {
         Executor.Execute(c => ChannelHandlerInvokerUtil.InvokeChannelActiveNow((IChannelHandlerContext)c), ctx);
     }
 }
Example #3
0
 public void InvokeFlush(IChannelHandlerContext ctx)
 {
     if (Executor.InEventLoop)
     {
         ChannelHandlerInvokerUtil.InvokeFlushNow(ctx);
     }
     else
     {
         Executor.Execute(InvokeFlushAction, ctx);
     }
 }
Example #4
0
 public void InvokeChannelWritabilityChanged(IChannelHandlerContext ctx)
 {
     if (Executor.InEventLoop)
     {
         ChannelHandlerInvokerUtil.InvokeChannelWritabilityChangedNow(ctx);
     }
     else
     {
         Executor.Execute(InvokeChannelWritabilityChangedAction, ctx);
     }
 }
Example #5
0
 public void InvokeChannelReadComplete(IChannelHandlerContext ctx)
 {
     if (Executor.InEventLoop)
     {
         ChannelHandlerInvokerUtil.InvokeChannelReadCompleteNow(ctx);
     }
     else
     {
         Executor.Execute(InvokeChannelReadCompleteAction, ctx);
     }
 }
Example #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);
            }
        }
Example #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);
            }
        }
Example #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)));
        }
Example #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)));
        }
Example #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);
        }
Example #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);
                }
            }