Ejemplo n.º 1
0
 internal void RemoveChannel(QpServerChannel channel)
 {
     lock (channelList)
         if (channelList.Contains(channel))
         {
             channelList.Remove(channel);
             Channels = channelList.ToArray();
         }
     lock (auchenticatedChannelList)
         if (auchenticatedChannelList.Contains(channel))
         {
             auchenticatedChannelList.Remove(channel);
             AuchenticatedChannels = auchenticatedChannelList.ToArray();
         }
 }
Ejemplo n.º 2
0
        protected void OnNewChannelConnected(Stream stream, string channelName, CancellationToken token)
        {
            var channel = new QpServerChannel(this, stream, channelName, token, options.Clone());

            //将通道加入到全部通道列表里面
            lock (channelList)
            {
                channelList.Add(channel);
                Channels = channelList.ToArray();
            }

            //认证通过后,才将通道添加到已认证通道列表里面
            channel.Auchenticated += (sender, e) =>
            {
                lock (auchenticatedChannelList)
                {
                    auchenticatedChannelList.Add(channel);
                    AuchenticatedChannels = auchenticatedChannelList.ToArray();
                }
            };
            channel.Disconnected += (sender, e) =>
            {
                if (LogUtils.LogConnection)
                {
                    LogUtils.Log("[Connection]{0} Disconnected.", channelName);
                }
                RemoveChannel(channel);
                try { stream.Dispose(); }
                catch { }
                ChannelDisconnected?.Invoke(this, channel);
            };
            Task.Run(() =>
            {
                ChannelConnected?.Invoke(this, channel);
            });
        }