Example #1
0
        private static void DoPing(object o)
        {
            PingerJob job = o as PingerJob;

            job.Run();
        }
Example #2
0
        public override void OnRun()
        {
            Dictionary<string, ServerInfo> servers;

            for (; ; )
            {
                if (GetCanRun() == false)
                {
                    Sleep(1000);
                }
                else
                {
                    // 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");

                    lock (Engine.Servers)
                        servers = new Dictionary<string, ServerInfo>(Engine.Servers);

                    bool startOne = false;

                    foreach (ServerInfo infoServer in servers.Values)
                    {
                        if (GetCanRun() == false)
                            break;

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

                        int delay = delaySuccess;
                        if (infoServer.PingFailedConsecutive > 0)
                            delay = delayRetry;

                        if(timeNow - infoServer.LastPingTest >= delay)
                        {
                            bool canPingServer = enabled;
                            if (infoServer.IpEntry == "")
                                canPingServer = false;
                            if (infoServer.WarningClosed != "")
                                canPingServer = false;

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

                                    PingerJob job = new PingerJob();
                                    job.Server = infoServer;
                                    /*
                                    lock (Jobs)
                                    {
                                        Jobs.Add(job);
                                    }
                                    job.Start();
                                    */

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

                        if (CancelRequested)
                            return;
                    }

                    if (startOne)
                        Sleep(100); // Waiting for a queue slot
                    else
                        Sleep(1000); // Waiting for a ping need
                }

                if (CancelRequested)
                    return;

            }
        }
Example #3
0
        public override void OnRun()
        {
            Dictionary <string, ConnectionInfo> servers;

            for (;;)
            {
                if (GetCanRun() == false)
                {
                    Sleep(1000);
                }
                else
                {
                    // 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");

                    lock (Engine.Connections)
                        servers = new Dictionary <string, ConnectionInfo>(Engine.Connections);

                    bool startOne = false;

                    foreach (ConnectionInfo infoServer in servers.Values)
                    {
                        if (GetCanRun() == false)
                        {
                            break;
                        }

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

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

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

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

                                    PingerJob job = new PingerJob();
                                    job.Server = infoServer;

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

                        if (CancelRequested)
                        {
                            return;
                        }
                    }

                    if (startOne)
                    {
                        Sleep(100);                         // Waiting for a queue slot
                    }
                    else
                    {
                        Sleep(1000);                         // Waiting for a ping need
                    }
                }

                if (CancelRequested)
                {
                    return;
                }
            }
        }