예제 #1
0
 void Register0(TaskCompletionSource promise)
 {
     try
     {
         // check if the channel is still open as it could be closed input the mean time when the register
         // call was outside of the eventLoop
         if (!promise.SetUncancellable() || !EnsureOpen(promise))
         {
             PromiseUtil.SafeSetFailure(promise, ClosedChannelException.Instance, Logger);
             return;
         }
         bool firstRegistration = this.neverRegistered;
         this._channel.DoRegister();
         this.neverRegistered      = false;
         this._channel._registered = true;
         this._channel._eventLoop.AcceptNewTasks();
         PromiseUtil.SafeSetSuccess(promise, Logger);
         _channel._pipeline.FireChannelRegistered();
         // Only fire a channelActive if the channel has never been registered. This prevents firing
         // multiple channel actives if the channel is deregistered and re-registered.
         if (firstRegistration && this._channel.IsActive)
         {
             _channel._pipeline.FireChannelActive();
         }
     }
     catch (Exception t)
     {
         // Close the channel directly to avoid FD leak.
         CloseForcibly();
         _channel._closeTask.Complete();
         PromiseUtil.SafeSetFailure(promise, t, Logger);
     }
 }
예제 #2
0
        public bool Remove()
        {
            var e = _flushedEntry;

            if (e == null)
            {
                return(false);
            }
            var msg     = e.Message;
            var promise = e.Promise;
            var size    = e.PendingSize;

            RemoveEntry(e);

            if (!e.Cancelled)
            {
                // only release message, notify and decrement if it was not canceled before.
                ReferenceCountUtil.SafeRelease(msg);
                PromiseUtil.SafeSetSuccess(promise, Logger);
                DecrementPendingOutboundBytes(size, true);
            }

            e.Recycle();
            return(true);
        }
예제 #3
0
            public Task CloseAsync() //CancellationToken cancellationToken)
            {
                var promise = new TaskCompletionSource();

                if (!promise.SetUncancellable())
                {
                    return(promise.Task);
                }
                //if (cancellationToken.IsCancellationRequested)
                //{
                //    return TaskEx.Cancelled;
                //}

                if (this.outboundBuffer == null)
                {
                    // Only needed if no VoidChannelPromise.
                    if (promise != TaskCompletionSource.Void)
                    {
                        // This means close() was called before so we just register a listener and return
                        return(this._channel._closeTask.Task);
                    }
                    return(promise.Task);
                }

                if (this._channel._closeTask.Task.IsCompleted)
                {
                    // Closed already.
                    PromiseUtil.SafeSetSuccess(promise, Logger);
                    return(promise.Task);
                }

                bool wasActive = this._channel.IsActive;
                ChannelOutboundBuffer buffer = this.outboundBuffer;

                this.outboundBuffer = null; // Disallow adding any messages and flushes to outboundBuffer.

                try
                {
                    // Close the channel and fail the queued messages input all cases.
                    this.DoClose0(promise);
                }
                finally
                {
                    // Fail all the queued messages.
                    buffer.FailFlushed(ClosedChannelException.Instance, false);
                    buffer.Close(ClosedChannelException.Instance);
                }
                if (this.inFlush0)
                {
                    this.InvokeLater(() => this.FireChannelInactiveAndDeregister(wasActive));
                }
                else
                {
                    this.FireChannelInactiveAndDeregister(wasActive);
                }


                return(promise.Task);
            }
예제 #4
0
 public void SafeSetSuccess(TaskCompletionSource promise)
 {
     PromiseUtil.SafeSetSuccess(promise, Logger);
 }