//-----------------------------------------------------------------------------
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()
ipToDel.erase(ipToDel.begin(), ipToDel.end());
}
//-----------------------------------------------------------------------------
-int STG_PINGER::GetPingIPNum()
+int STG_PINGER::GetPingIPNum() const
{
return pingIP.size();
}
//-----------------------------------------------------------------------------
-void STG_PINGER::GetAllIP(vector<PING_IP_TIME> *)
+/*void STG_PINGER::GetAllIP(vector<PING_IP_TIME> *) const
{
//STG_LOCKER lock(&mutex, __FILE__, __LINE__);
-}
+}*/
//-----------------------------------------------------------------------------
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<uint32_t, time_t>::iterator treeIter;
+ multimap<uint32_t, time_t>::const_iterator treeIter;
treeIter = pingIP.find(ip);
if (treeIter == pingIP.end())
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;
}
return NULL;
}
//-----------------------------------------------------------------------------
-
#ifndef PINGER_H
#define PINGER_H
-#include <time.h>
+#include <ctime>
#include <string>
#include <vector>
#include <list>
int Stop();
void AddIP(uint32_t ip);
void DelIP(uint32_t ip);
- int GetPingIPNum();
- void GetAllIP(vector<PING_IP_TIME> * ipTime);
+ int GetPingIPNum() const;
+ //void GetAllIP(vector<PING_IP_TIME> * 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;
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<uint32_t, time_t> pingIP;
list<uint32_t> ipToAdd;
list<uint32_t> ipToDel;
- pthread_mutex_t mutex;
+ mutable pthread_mutex_t mutex;
};
//-----------------------------------------------------------------------------
#endif
-
-