/// <summary>
        /// Processes the client
        /// </summary>
        /// <param name="state"></param>
        private void ProcessDataRequests(object state)
        {
            try
            {
                while (m_isRunning && !m_listener.Pending())
                {
                    Thread.Sleep(10);
                }
                if (!m_isRunning)
                {
                    m_listener.Stop();
                    Log.Publish(MessageLevel.Info, "Socket Listener Stopped");
                    return;
                }

                TcpClient client = m_listener.AcceptTcpClient();
                Log.Publish(MessageLevel.Info, "Client Connection", "Client connection attempted from: " + client.Client.RemoteEndPoint.ToString());

                Thread th = new Thread(ProcessDataRequests);
                th.IsBackground = true;
                th.Start();

                SnapNetworkServer networkServerProcessing;
                using (Logger.AppendStackMessages(Log.InitialStackMessages))
                {
                    networkServerProcessing = new SnapNetworkServer(m_authenticator, client, m_server);
                }
                lock (m_clients)
                {
                    if (m_isRunning)
                    {
                        m_clients.Add(networkServerProcessing);
                    }
                    else
                    {
                        TryShutdownSocket(client);
                        client.Close();
                        return;
                    }
                }
                try
                {
                    networkServerProcessing.ProcessClient();
                }
                finally
                {
                    // If we made it this far, the client must have been added to the
                    // list of active clients. In the past, errors in ProcessClient have
                    // caused a leak here, so the try-finally should help protect against that
                    lock (m_clients)
                    {
                        m_clients.Remove(networkServerProcessing);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Publish(MessageLevel.Critical, "Client Processing Failed", "An unhandled Exception occured while processing clients", null, ex);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Processes the client
        /// </summary>
        /// <param name="state"></param>
        private void ProcessDataRequests(object state)
        {
            try
            {
                while (m_isRunning && !m_listener.Pending())
                {
                    Thread.Sleep(10);
                }
                if (!m_isRunning)
                {
                    m_listener.Stop();
                    Log.Publish(MessageLevel.Info, "Socket Listener Stopped");
                    return;
                }

                TcpClient client = m_listener.AcceptTcpClient();
                Log.Publish(MessageLevel.Info, "Client Connection", "Client connection attempted from: " + client.Client.RemoteEndPoint.ToString());

                Thread th = new Thread(ProcessDataRequests);
                th.IsBackground = true;
                th.Start();

                SnapNetworkServer networkServerProcessing;
                using (Logger.AppendStackMessages(Log.InitialStackMessages))
                {
                    networkServerProcessing = new SnapNetworkServer(m_authenticator, client, m_server);
                }
                lock (m_clients)
                {
                    if (m_isRunning)
                    {
                        m_clients.Add(networkServerProcessing);
                    }
                    else
                    {
                        client.Client.Shutdown(SocketShutdown.Both);
                        client.Close();
                        return;
                    }
                }
                networkServerProcessing.ProcessClient();
                lock (m_clients)
                {
                    m_clients.Remove(networkServerProcessing);
                }
            }
            catch (Exception ex)
            {
                Log.Publish(MessageLevel.Critical, "Client Processing Failed", "An unhandled Exception occured while processing clients", null, ex);
            }
        }
        /// <summary>
        /// Processes the client
        /// </summary>
        /// <param name="state"></param>
        private void ProcessDataRequests(object state)
        {
            try
            {
                while (m_isRunning && !m_listener.Pending())
                {
                    Thread.Sleep(10);
                }
                if (!m_isRunning)
                {
                    m_listener.Stop();
                    Log.Publish(MessageLevel.Info, "Socket Listener Stopped");
                    return;
                }

                TcpClient client = m_listener.AcceptTcpClient();
                Log.Publish(MessageLevel.Info, "Client Connection", "Client connection attempted from: " + client.Client.RemoteEndPoint.ToString());

                Thread th = new Thread(ProcessDataRequests);
                th.IsBackground = true;
                th.Start();

                SnapNetworkServer networkServerProcessing;
                using (Logger.AppendStackMessages(Log.InitialStackMessages))
                {
                    networkServerProcessing = new SnapNetworkServer(m_authenticator, client, m_server);
                }
                lock (m_clients)
                {
                    if (m_isRunning)
                    {
                        m_clients.Add(networkServerProcessing);
                    }
                    else
                    {
                        client.Client.Shutdown(SocketShutdown.Both);
                        client.Close();
                        return;
                    }
                }
                networkServerProcessing.ProcessClient();
                lock (m_clients)
                {
                    m_clients.Remove(networkServerProcessing);
                }

            }
            catch (Exception ex)
            {
                Log.Publish(MessageLevel.Critical, "Client Processing Failed", "An unhandled Exception occured while processing clients", null, ex);
            }

        }