예제 #1
0
        private void RemoveChannel(IMessageChannel ch)
        {
            NetworkMessageChannel channel = ch as NetworkMessageChannel;

            lock (listenList)
            {
                listenList.Remove(channel.InternalSocket);
                channelsMap.Remove(channel.InternalSocket);

                if (ch is NetworkMessageChannel)
                {
                    channelsList.Remove(channel);

                    if (channel is TCPMessageChannel)
                    {
                        channelsTypeMap[ChannelType.TCP].Remove(channel);
                    }
                    else if (channel is UDPMessageChannel)
                    {
                        channelsTypeMap[ChannelType.UDP].Remove(channel);
                    }

                    else if (channel is MulticastMessageChannel)
                    {
                        channelsTypeMap[ChannelType.MULTICAST].Remove(channel);
                    }
                }
                else if (ch is MemoryMessageChannel)
                {
                    channelsTypeMap[ChannelType.MEMORY].Remove(channel);
                }
                else
                {
                    throw new Exception("Unknown Message Channel");
                }
                //FireChannelRemove(channel);
            }
        }
예제 #2
0
        private void AddChannel(IMessageChannel ch)
        {
            lock (listenList)
            {
                if (ch is NetworkMessageChannel)
                {
                    NetworkMessageChannel channel = ch as NetworkMessageChannel;

                    listenList.Add(channel.InternalSocket);
                    channelsMap.Add(channel.InternalSocket, channel);
                    channelsList.Add(channel);

                    if (channel is TCPMessageChannel)
                    {
                        if (!channelsTypeMap.ContainsKey(ChannelType.TCP))
                        {
                            channelsTypeMap.Add(ChannelType.TCP, new List <IMessageChannel>());
                        }
                        channelsTypeMap[ChannelType.TCP].Add(channel);
                    }
                    else if (channel is UDPMessageChannel)
                    {
                        if (!channelsTypeMap.ContainsKey(ChannelType.UDP))
                        {
                            channelsTypeMap.Add(ChannelType.UDP, new List <IMessageChannel>());
                        }
                        if ((channel as UDPMessageChannel).udpRemoteAddress != null)
                        {
                            channelsTypeMap[ChannelType.UDP].Add(channel);
                        }
                    }

                    else if (channel is MulticastMessageChannel)
                    {
                        if (!channelsTypeMap.ContainsKey(ChannelType.MULTICAST))
                        {
                            channelsTypeMap.Add(ChannelType.MULTICAST, new List <IMessageChannel>());
                        }
                        if ((channel as MulticastMessageChannel).udpMulticastAddress != null)
                        {
                            channelsTypeMap[ChannelType.MULTICAST].Add(channel);
                        }
                    }
                }
                else if (ch is MemoryMessageChannel)
                {
                    MemoryMessageChannel channel = ch as MemoryMessageChannel;
                    if (!channelsTypeMap.ContainsKey(ChannelType.MEMORY))
                    {
                        channelsTypeMap.Add(ChannelType.MEMORY, new List <IMessageChannel>());
                    }
                    channelsTypeMap[ChannelType.MEMORY].Add(channel);
                }
                else
                {
                    throw new Exception("Unknown Message Channel");
                }

                FireChannelAvailable(ch);

                if (listenList.Count == 1)
                {
                    // Signal the calling thread to continue.
                    clientConnected.Set();
                }
            }
        }