X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/ede91934442fd804d7b818971a44e3ad795cb01f..3a45cd9275dc9279e133deb0932402ae5f4d0b5f:/projects/stargazer/plugins/other/ping/ping.cpp diff --git a/projects/stargazer/plugins/other/ping/ping.cpp b/projects/stargazer/plugins/other/ping/ping.cpp index 3067e87e..ec137044 100644 --- a/projects/stargazer/plugins/other/ping/ping.cpp +++ b/projects/stargazer/plugins/other/ping/ping.cpp @@ -1,14 +1,13 @@ #include -#include #include +#include #include +#include "stg/user.h" +#include "stg/locker.h" +#include "stg/user_property.h" #include "ping.h" -#include "user.h" -#include "stg_locker.h" -#include "../../../settings.h" -#include "../../../user_property.h" class PING_CREATOR { @@ -88,21 +87,6 @@ if (ParseIntInRange(pvi->value[0], 5, 3600, &pingDelay)) return 0; } //----------------------------------------------------------------------------- -int PING_SETTINGS::ParseIntInRange(const std::string & str, int min, int max, int * val) -{ -if (str2x(str.c_str(), *val)) - { - errorStr = "Incorrect value \'" + str + "\'."; - return -1; - } -if (*val < min || *val > max) - { - errorStr = "Value \'" + str + "\' out of range."; - return -1; - } -return 0; -} -//----------------------------------------------------------------------------- PING::PING() : users(NULL), nonstop(false), @@ -178,12 +162,13 @@ if (!isRunning) pinger.Stop(); nonstop = false; //5 seconds to thread stops itself +struct timespec ts = {0, 200000000}; for (int i = 0; i < 25; i++) { if (!isRunning) break; - usleep(200000); + nanosleep(&ts, NULL); } //after 5 seconds waiting thread still running. now kill it @@ -207,7 +192,7 @@ users_iter = usersList.begin(); while (users_iter != usersList.end()) { UnSetUserNotifiers(*users_iter); - users_iter++; + ++users_iter; } return 0; @@ -220,22 +205,22 @@ return isRunning; //----------------------------------------------------------------------------- void * PING::Run(void * d) { -PING * ping = (PING*)d; +PING * ping = (PING *)d; ping->isRunning = true; -list::iterator iter; -uint32_t ip; -time_t t; +long delay = (10000000 * ping->pingSettings.GetPingDelay()) / 3 + 50000000; + while (ping->nonstop) { - iter = ping->usersList.begin(); + list::iterator iter = ping->usersList.begin(); { STG_LOCKER lock(&ping->mutex, __FILE__, __LINE__); while (iter != ping->usersList.end()) { if ((*iter)->GetProperty().ips.ConstData().OnlyOneIP()) { - ip = (*iter)->GetProperty().ips.ConstData()[0].ip; + uint32_t ip = (*iter)->GetProperty().ips.ConstData()[0].ip; + time_t t; if (ping->pinger.GetIPTime(ip, &t) == 0) { if (t) @@ -244,9 +229,10 @@ while (ping->nonstop) } else { - ip = (*iter)->GetCurrIP(); + uint32_t ip = (*iter)->GetCurrIP(); if (ip) { + time_t t; if (ping->pinger.GetIPTime(ip, &t) == 0) { if (t) @@ -254,17 +240,19 @@ while (ping->nonstop) } } } - iter++; + ++iter; } } + struct timespec ts = {delay / 1000000000, delay % 1000000000}; for (int i = 0; i < 100; i++) { if (ping->nonstop) { - usleep((10000*ping->pingSettings.GetPingDelay())/3 + 50000); + nanosleep(&ts, NULL); } } } + ping->isRunning = false; return NULL; } @@ -381,7 +369,7 @@ while (users_iter != usersList.end()) usersList.erase(users_iter); break; } - users_iter++; + ++users_iter; } } //-----------------------------------------------------------------------------