From 5924017d951d69132f2b8522dfa04927abc417d0 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 8 Dec 2010 16:03:35 +0200 Subject: [PATCH] =?utf8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD?= =?utf8?q?=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD?= =?utf8?q?=D0=B3=20=D0=B1=D0=B8=D0=B1=D0=BB=D0=B8=D0=BE=D1=82=D0=B5=D0=BA?= =?utf8?q?=D0=B8=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D0=B8?= =?utf8?q?=20ICMP,=20=D0=BD=D0=B5=D0=BA=D0=BE=D1=82=D0=BE=D1=80=D1=8B?= =?utf8?q?=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20=D1=81=D0=B4?= =?utf8?q?=D0=B5=D0=BB=D0=B0=D0=BD=D1=8B=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82?= =?utf8?q?=D0=B0=D0=BD=D1=82=D0=BD=D1=8B=D0=BC=D0=B8,=20=D0=B4=D0=BE=D0=B1?= =?utf8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=B8=D0=BD=D0=B8=D1=86?= =?utf8?q?=D0=B8=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=87?= =?utf8?q?=D0=BB=D0=B5=D0=BD=D0=BE=D0=B2=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= =?utf8?q?=D0=B0=20=D0=B2=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83?= =?utf8?q?=D0=BA=D1=82=D0=BE=D1=80=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- stglibs/pinger.lib/pinger.cpp | 24 ++++++++++++++---------- stglibs/pinger.lib/pinger.h | 33 +++++++++++++++------------------ 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/stglibs/pinger.lib/pinger.cpp b/stglibs/pinger.lib/pinger.cpp index 9169b4e6..edbcd11e 100644 --- a/stglibs/pinger.lib/pinger.cpp +++ b/stglibs/pinger.lib/pinger.cpp @@ -24,10 +24,15 @@ extern volatile time_t stgTime; //----------------------------------------------------------------------------- STG_PINGER::STG_PINGER(time_t d) + : delay(d), + nonstop(false), + isRunningRecver(false), + isRunningSender(false), + sendSocket(-1), + recvSocket(-1), + pid(0) { - delay = d; pthread_mutex_init(&mutex, NULL); - pid = 0; } //----------------------------------------------------------------------------- STG_PINGER::~STG_PINGER() @@ -172,15 +177,15 @@ void STG_PINGER::RealDelIP() ipToDel.erase(ipToDel.begin(), ipToDel.end()); } //----------------------------------------------------------------------------- -int STG_PINGER::GetPingIPNum() +int STG_PINGER::GetPingIPNum() const { return pingIP.size(); } //----------------------------------------------------------------------------- -void STG_PINGER::GetAllIP(vector *) +/*void STG_PINGER::GetAllIP(vector *) const { //STG_LOCKER lock(&mutex, __FILE__, __LINE__); -} +}*/ //----------------------------------------------------------------------------- void STG_PINGER::PrintAllIP() { @@ -199,10 +204,10 @@ void STG_PINGER::PrintAllIP() } //----------------------------------------------------------------------------- -int STG_PINGER::GetIPTime(uint32_t ip, time_t * t) +int STG_PINGER::GetIPTime(uint32_t ip, time_t * t) const { STG_LOCKER lock(&mutex, __FILE__, __LINE__); - multimap::iterator treeIter; + multimap::const_iterator treeIter; treeIter = pingIP.find(ip); if (treeIter == pingIP.end()) @@ -217,12 +222,12 @@ void STG_PINGER::SetDelayTime(time_t d) delay = d; } //----------------------------------------------------------------------------- -time_t STG_PINGER::GetDelayTime() +time_t STG_PINGER::GetDelayTime() const { return delay; } //----------------------------------------------------------------------------- -string STG_PINGER::GetStrError() +string STG_PINGER::GetStrError() const { return errorStr; } @@ -385,4 +390,3 @@ void * STG_PINGER::RunRecvPing(void * d) return NULL; } //----------------------------------------------------------------------------- - diff --git a/stglibs/pinger.lib/pinger.h b/stglibs/pinger.lib/pinger.h index 4349eb07..1398332d 100644 --- a/stglibs/pinger.lib/pinger.h +++ b/stglibs/pinger.lib/pinger.h @@ -7,7 +7,7 @@ #ifndef PINGER_H #define PINGER_H -#include +#include #include #include #include @@ -94,15 +94,23 @@ public: int Stop(); void AddIP(uint32_t ip); void DelIP(uint32_t ip); - int GetPingIPNum(); - void GetAllIP(vector * ipTime); + int GetPingIPNum() const; + //void GetAllIP(vector * ipTime) const; void PrintAllIP(); - int GetIPTime(uint32_t ip, time_t * t); + int GetIPTime(uint32_t ip, time_t * t) const; void SetDelayTime(time_t delay); - time_t GetDelayTime(); - string GetStrError(); + time_t GetDelayTime() const; + string GetStrError() const; private: + uint16_t PingCheckSum(void * data, int len); + int SendPing(uint32_t ip); + uint32_t RecvPing(); + void RealAddIP(); + void RealDelIP(); + + static void * RunSendPing(void * d); + static void * RunRecvPing(void * d); int delay; bool nonstop; @@ -116,24 +124,13 @@ private: PING_MESSAGE pmSend; uint32_t pid; - uint16_t PingCheckSum(void * data, int len); - int SendPing(uint32_t ip); - uint32_t RecvPing(); - void RealAddIP(); - void RealDelIP(); - - static void * RunSendPing(void * d); - static void * RunRecvPing(void * d); - string errorStr; multimap pingIP; list ipToAdd; list ipToDel; - pthread_mutex_t mutex; + mutable pthread_mutex_t mutex; }; //----------------------------------------------------------------------------- #endif - - -- 2.44.2