示例#1
0
        public override void OnRun()
        {
            if (GetCanRun() == false)
            {
                m_timeEvery = 1000;
            }
            else
            {
                List <ConnectionInfo> connections = GetConnectionsToPing();

                // Note: If Pinger is not enabled, works like all ping results is 0.
                bool enabled = GetEnabled();

                int timeNow   = Utils.UnixTimeStamp();
                int jobsLimit = Engine.Instance.Storage.GetInt("pinger.jobs");

                bool startOne = false;

                foreach (ConnectionInfo connectionInfo in connections)
                {
                    if (GetCanRun() == false)
                    {
                        break;
                    }

                    int delaySuccess = GetPingerDelaySuccess(connectionInfo);
                    int delayRetry   = GetPingerDelayRetry(connectionInfo);

                    int delay = delaySuccess;
                    if (connectionInfo.PingFailedConsecutive > 0)
                    {
                        delay = delayRetry;
                    }

                    if (timeNow - connectionInfo.LastPingTest >= delay)
                    {
                        bool canPingServer = enabled;
                        if (connectionInfo.CanPing() == false)
                        {
                            canPingServer = false;
                        }

                        if (canPingServer)
                        {
                            if (Jobs.Count < jobsLimit)
                            {
                                connectionInfo.LastPingTest = timeNow;

                                PingerJob job = new PingerJob();
                                job.Server = connectionInfo;
                                lock (Jobs)
                                    Jobs.Add(job);

                                ThreadPool.QueueUserWorkItem(new WaitCallback(DoPing), job);
                                startOne = true;
                            }
                        }
                        else
                        {
                            if (connectionInfo.Ping != -1)
                            {
                                //connectionInfo.LastPingTest = timeNow; // <2.13.4
                                connectionInfo.LastPingTest          = 0;
                                connectionInfo.PingTests             = 0;
                                connectionInfo.PingFailedConsecutive = 0;
                                connectionInfo.Ping            = -1;
                                connectionInfo.LastPingResult  = connectionInfo.LastPingTest;
                                connectionInfo.LastPingSuccess = connectionInfo.LastPingTest;
                                Engine.Instance.MarkServersListUpdated();
                            }
                        }
                    }

                    if (m_cancelRequested)
                    {
                        return;
                    }
                }

                if (startOne)
                {
                    m_timeEvery = 100;
                }
                else
                {
                    m_timeEvery = 1000;
                }

                for (; ;)
                {
                    lock (Jobs)
                        if (Jobs.Count == 0)
                        {
                            break;
                        }
                    Sleep(100);
                }
            }
        }
示例#2
0
        private static void DoPing(object o)
        {
            PingerJob job = o as PingerJob;

            job.Run();
        }