Ejemplo n.º 1
0
        public Task NewCloseFuture(IChannelMatcher matcher)
        {
            if (matcher is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.matcher);
            }
            var futures = new Dictionary <IChannel, Task>(ChannelComparer.Default);

            foreach (IChannel c in _nonServerChannels.Values)
            {
                if (matcher.Matches(c))
                {
                    futures.Add(c, c.CloseCompletion);
                }
            }
            foreach (IChannel c in _serverChannels.Values)
            {
                if (matcher.Matches(c))
                {
                    futures.Add(c, c.CloseCompletion);
                }
            }

            return(new DefaultChannelGroupCompletionSource(this, futures /*, this.executor*/).Task);
        }
Ejemplo n.º 2
0
 public Task BroadcastPacket(OutPacket packet, IChannelMatcher matcher)
 {
     return(Task.WhenAll(Sockets
                         .Where(s => matcher.Matches(s.Channel))
                         .Select(s => s.SendPacket(packet))
                         ));
 }
Ejemplo n.º 3
0
        public Task WriteAndFlushAsync(object message, IChannelMatcher matcher, bool voidPromise)
        {
            if (message is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.message);
            }
            if (matcher is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.matcher);
            }

            Task result;

            if (voidPromise)
            {
                foreach (IChannel c in _nonServerChannels.Values)
                {
                    if (matcher.Matches(c))
                    {
                        _ = c.WriteAndFlushAsync(SafeDuplicate(message), c.VoidPromise());
                    }
                }

                result = TaskUtil.Completed;
            }
            else
            {
                var futures = new Dictionary <IChannel, Task>(_nonServerChannels.Count, ChannelComparer.Default);
                foreach (IChannel c in _nonServerChannels.Values)
                {
                    if (matcher.Matches(c))
                    {
                        futures.Add(c, c.WriteAndFlushAsync(SafeDuplicate(message)));
                    }
                }

                result = new DefaultChannelGroupCompletionSource(this, futures /*, this.executor*/).Task;
            }

            _ = ReferenceCountUtil.Release(message);
            return(result);
        }
Ejemplo n.º 4
0
 public IChannelGroup Flush(IChannelMatcher matcher)
 {
     foreach (IChannel c in _nonServerChannels.Values)
     {
         if (matcher.Matches(c))
         {
             _ = c.Flush();
         }
     }
     return(this);
 }
Ejemplo n.º 5
0
        public Task NewCloseFuture(IChannelMatcher matcher)
        {
            Contract.Requires(matcher != null);
            var futures = new Dictionary <IChannel, Task>();

            foreach (IChannel c in this.nonServerChannels.Values)
            {
                if (matcher.Matches(c))
                {
                    futures.Add(c, c.CloseCompletion);
                }
            }
            foreach (IChannel c in this.serverChannels.Values)
            {
                if (matcher.Matches(c))
                {
                    futures.Add(c, c.CloseCompletion);
                }
            }

            return(new DefaultChannelGroupCompletionSource(this, futures /*, this.executor*/).Task);
        }
Ejemplo n.º 6
0
        public Task DeregisterAsync(IChannelMatcher matcher)
        {
            var futures = new Dictionary <IChannel, Task>();

            foreach (IChannel c in this.nonServerChannels.Values)
            {
                if (matcher.Matches(c))
                {
                    futures.Add(c, c.DeregisterAsync());
                }
            }

            return(new DefaultChannelGroupCompletionSource(this, futures /*, this.executor*/).Task);
        }
Ejemplo n.º 7
0
        public Task CloseAsync(IChannelMatcher matcher)
        {
            if (matcher is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.matcher);
            }
            var futures = new Dictionary <IChannel, Task>(ChannelComparer.Default);

            if (_stayClosed)
            {
                // It is important to set the closed to true, before closing channels.
                // Our invariants are:
                // closed=true happens-before ChannelGroup.close()
                // ChannelGroup.add() happens-before checking closed==true
                //
                // See https://github.com/netty/netty/issues/4020
                _ = Interlocked.Exchange(ref _closed, SharedConstants.True);
            }

            foreach (IChannel c in _nonServerChannels.Values)
            {
                if (matcher.Matches(c))
                {
                    futures.Add(c, c.CloseAsync());
                }
            }
            foreach (IChannel c in _serverChannels.Values)
            {
                if (matcher.Matches(c))
                {
                    futures.Add(c, c.CloseAsync());
                }
            }

            return(new DefaultChannelGroupCompletionSource(this, futures /*, this.executor*/).Task);
        }
Ejemplo n.º 8
0
        public Task WriteAsync(object message, IChannelMatcher matcher)
        {
            var futures = new Dictionary <IChannel, Task>();

            foreach (IChannel c in this.nonServerChannels.Values)
            {
                if (matcher.Matches(c))
                {
                    futures.Add(c, c.WriteAsync(SafeDuplicate(message)));
                }
            }

            ReferenceCountUtil.Release(message);
            return(new DefaultChannelGroupCompletionSource(this, futures /*, this.executor*/).Task);
        }
Ejemplo n.º 9
0
 public bool Matches(IChannel channel) => !_matcher.Matches(channel);