예제 #1
0
        public Task InvokeWriteAsync(IChannelHandlerContext ctx, object msg)
        {
            Contract.Requires(msg != null);

            // todo: cancellation support
            //try
            //{
            //    if (!validatePromise(ctx, promise, true))
            //    {
            //        ReferenceCountUtil.release(msg);
            //        return;
            //    }
            //}
            //catch (RuntimeException e)
            //{
            //    ReferenceCountUtil.release(msg);
            //    throw e;
            //}

            if (this.executor.InEventLoop)
            {
                return(ChannelHandlerInvokerUtil.InvokeWriteNowAsync(ctx, msg));
            }
            else
            {
                var promise = new TaskCompletionSource();
                this.SafeExecuteOutbound(WriteTask.NewInstance(ctx, msg, promise), promise, msg);
                return(promise.Task);
            }
        }
예제 #2
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 (this.executor.InEventLoop)
            {
                return(ChannelHandlerInvokerUtil.InvokeWriteAsyncNow(ctx, msg));
            }
            else
            {
                var channel = (AbstractChannel)ctx.Channel;
                int size    = channel.EstimatorHandle.Size(msg);
                if (size > 0)
                {
                    ChannelOutboundBuffer 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);
                    }
                }
                return(this.SafeProcessOutboundMessageAsync(InvokeWriteAsyncFunc, ctx, msg));
            }
        }
 public void InvokeChannelInactive(IChannelHandlerContext ctx)
 {
     if (this.executor.InEventLoop)
     {
         ChannelHandlerInvokerUtil.InvokeChannelInactiveNow(ctx);
     }
     else
     {
         this.executor.Execute(c => ChannelHandlerInvokerUtil.InvokeChannelInactiveNow((IChannelHandlerContext)c), ctx);
     }
 }
 public void InvokeFlush(IChannelHandlerContext ctx)
 {
     if (this.executor.InEventLoop)
     {
         ChannelHandlerInvokerUtil.InvokeFlushNow(ctx);
     }
     else
     {
         this.executor.Execute(InvokeFlushAction, ctx);
     }
 }
 public void InvokeChannelWritabilityChanged(IChannelHandlerContext ctx)
 {
     if (this.executor.InEventLoop)
     {
         ChannelHandlerInvokerUtil.InvokeChannelWritabilityChangedNow(ctx);
     }
     else
     {
         this.executor.Execute(InvokeChannelWritabilityChangedAction, ctx);
     }
 }
 public void InvokeChannelReadComplete(IChannelHandlerContext ctx)
 {
     if (this.executor.InEventLoop)
     {
         ChannelHandlerInvokerUtil.InvokeChannelReadCompleteNow(ctx);
     }
     else
     {
         this.executor.Execute(InvokeChannelReadCompleteAction, ctx);
     }
 }
예제 #7
0
 public void InvokeChannelActive(IChannelHandlerContext ctx)
 {
     if (this.executor.InEventLoop)
     {
         ChannelHandlerInvokerUtil.InvokeChannelActiveNow(ctx);
     }
     else
     {
         this.executor.Execute(() => { ChannelHandlerInvokerUtil.InvokeChannelActiveNow(ctx); });
     }
 }
        public void InvokeChannelRead(IChannelHandlerContext ctx, object msg)
        {
            Contract.Requires(msg != null);

            if (this.executor.InEventLoop)
            {
                ChannelHandlerInvokerUtil.InvokeChannelReadNow(ctx, msg);
            }
            else
            {
                this.SafeProcessInboundMessage(InvokeChannelReadAction, ctx, msg);
            }
        }
        public void InvokeUserEventTriggered(IChannelHandlerContext ctx, object evt)
        {
            Contract.Requires(evt != null);

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

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

            if (this.executor.InEventLoop)
            {
                return(ChannelHandlerInvokerUtil.InvokeBindAsyncNow(ctx, localAddress));
            }
            else
            {
                return(this.SafeExecuteOutboundAsync(() => ChannelHandlerInvokerUtil.InvokeBindAsyncNow(ctx, localAddress)));
            }
        }
예제 #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.InvokeWriteNowAsync(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;
     }
 }
        public Task InvokeWriteAsync(IChannelHandlerContext ctx, object msg)
        {
            Contract.Requires(msg != null);
            // todo: check for cancellation
            //if (!validatePromise(ctx, promise, false)) {
            //    // promise cancelled
            //    return;
            //}

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

                try
                {
                    int size = channel.EstimatorHandle.Size(msg);
                    if (size > 0)
                    {
                        ChannelOutboundBuffer 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);
                        }
                    }

                    this.executor.Execute(InvokeWriteAsyncAction, promise, msg);
                }
                catch (Exception cause)
                {
                    ReferenceCountUtil.Release(msg); // todo: safe release?
                    promise.TrySetException(cause);
                }
                return(promise.Task);
            }
        }
        public void InvokeExceptionCaught(IChannelHandlerContext ctx, Exception cause)
        {
            Contract.Requires(cause != null);

            if (this.executor.InEventLoop)
            {
                ChannelHandlerInvokerUtil.InvokeExceptionCaughtNow(ctx, cause);
            }
            else
            {
                try
                {
                    this.executor.Execute((c, e) => ChannelHandlerInvokerUtil.InvokeExceptionCaughtNow((IChannelHandlerContext)c, (Exception)e), ctx, cause);
                }
                catch (Exception t)
                {
                    if (DefaultChannelPipeline.Logger.WarnEnabled)
                    {
                        DefaultChannelPipeline.Logger.Warn("Failed to submit an ExceptionCaught() event.", t);
                        DefaultChannelPipeline.Logger.Warn("The ExceptionCaught() event that was failed to submit was:", cause);
                    }
                }
            }
        }
예제 #15
0
        public void InvokeExceptionCaught(IChannelHandlerContext ctx, Exception cause)
        {
            Contract.Requires(cause != null);

            if (this.executor.InEventLoop)
            {
                ChannelHandlerInvokerUtil.InvokeExceptionCaughtNow(ctx, cause);
            }
            else
            {
                try
                {
                    this.executor.Execute(() => { ChannelHandlerInvokerUtil.InvokeExceptionCaughtNow(ctx, cause); });
                }
                catch (Exception t)
                {
                    if (ChannelEventSource.Log.IsWarningEnabled)
                    {
                        ChannelEventSource.Log.Warning("Failed to submit an exceptionCaught() event.", t);
                        ChannelEventSource.Log.Warning("The exceptionCaught() event that was failed to submit was:", cause);
                    }
                }
            }
        }