Beispiel #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);
        }
Beispiel #2
0
 public Task BroadcastPacket(OutPacket packet, IChannelMatcher matcher)
 {
     return(Task.WhenAll(Sockets
                         .Where(s => matcher.Matches(s.Channel))
                         .Select(s => s.SendPacket(packet))
                         ));
 }
Beispiel #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);
        }
Beispiel #4
0
 public IChannelGroup Flush(IChannelMatcher matcher)
 {
     foreach (IChannel c in _nonServerChannels.Values)
     {
         if (matcher.Matches(c))
         {
             _ = c.Flush();
         }
     }
     return(this);
 }
Beispiel #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);
        }
        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);
        }
Beispiel #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);
        }
        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);
        }
Beispiel #9
0
 public bool Matches(IChannel channel) => !_matcher.Matches(channel);