Example #1
0
        /// <summary>
        /// Closes all outbound connections related to the current live agent client
        /// </summary>
        private void CloseClient(LiveSessionPublisher deadClient)
        {
            if (deadClient == null)
            {
                return;
            }

            //we are going to release every connection related to this client.  They might not all be - some might be local.
            var deadClientOptions = deadClient.GetOptions();

            if (deadClientOptions != null)
            {
                lock (m_DeadClients)
                {
                    //move everything to the dead collection and then we unregister that guy (this is what the iterators expect)
                    lock (m_ActiveClients)
                    {
                        foreach (var activeClient in m_ActiveClients)
                        {
                            if ((activeClient.GetOptions().Equals(deadClientOptions)) &&
                                (m_DeadClients.Contains(activeClient) == false))
                            {
                                m_DeadClients.Add(activeClient);
                            }
                        }
                    }

                    lock (m_PendingClients)
                    {
                        foreach (var pendingClient in m_PendingClients)
                        {
                            if ((pendingClient.GetOptions().Equals(deadClientOptions)) &&
                                (m_DeadClients.Contains(pendingClient) == false))
                            {
                                m_DeadClients.Add(pendingClient);
                            }
                        }
                        m_PendingClients.Clear();
                    }
                }

                //now we can kill them all
                DropDeadConnections();
            }

            deadClient.Dispose();
        }
Example #2
0
        /// <summary>
        /// Inheritors should override this method to implement custom Close functionality
        /// </summary>
        /// <remarks>Code in this method is protected by a Queue Lock.
        /// This method is called with the Message Dispatch thread exclusively.</remarks>
        protected override void OnClose()
        {
            if (m_IsClosed)
            {
                return;
            }

            if (m_DiscoveryFileMonitor != null)
            {
                try
                {
                    m_DiscoveryFileMonitor.FileChanged -= DiscoveryFileMonitorOnFileChanged;
                    m_DiscoveryFileMonitor.FileDeleted -= DiscoveryFileMonitorOnFileDeleted;
                    m_DiscoveryFileMonitor.Stop();
                }
                catch
                {
                }
            }

            //move everything to the dead collection and then we unregister that guy (this is what the iterators expect)
            lock (m_DeadClients)
            {
                lock (m_ActiveClients)
                {
                    foreach (NetworkWriter activeClient in m_ActiveClients)
                    {
                        if (m_DeadClients.Contains(activeClient) == false)
                        {
                            m_DeadClients.Add(activeClient);
                        }
                    }
                    m_ActiveClients.Clear();
                    m_Buffer.Clear();
                }

                lock (m_PendingClients)
                {
                    foreach (NetworkWriter pendingClient in m_PendingClients)
                    {
                        if (m_DeadClients.Contains(pendingClient) == false)
                        {
                            m_DeadClients.Add(pendingClient);
                        }
                    }
                    m_PendingClients.Clear();
                }
            }

            //now we can kill them all
            DropDeadConnections();

            //Now ditch our local proxies.  We've already stopped the file monitor so new ones shouldn't be showing up.
            //Despite that we don't like holding locks if we don't have to.
            List <LiveSessionPublisher> registeredProxies = null;

            lock (m_LocalProxyConnections)
            {
                if (m_LocalProxyConnections.Count > 0)
                {
                    registeredProxies = new List <LiveSessionPublisher>(m_LocalProxyConnections.Values);
                    m_LocalProxyConnections.Clear();
                }
            }

            if (registeredProxies != null)
            {
                foreach (var localProxyConnection in registeredProxies)
                {
                    localProxyConnection.Close();
                }
            }

            if (m_Client != null)
            {
                m_Client.Dispose();
                m_Client = null;
            }

            if (m_HubConnection != null)
            {
                m_HubConnection.Dispose();
                m_HubConnection = null;
            }

            m_IsClosed = true;
        }