]> git.stg.codes - stg.git/blobdiff - stglibs/pinger.lib/pinger.cpp
Hide or add proper copy ctor and assignement operator, initialize
[stg.git] / stglibs / pinger.lib / pinger.cpp
index fabc089ed7886bf7c89791bb0671b943a847a82b..f36868063a2b2a02d6ad1c99e00b32e02a454e13 100644 (file)
@@ -15,8 +15,8 @@
 #include <stdio.h>
 
 #include "pinger.h"
-#include "common.h"
-#include "stg_locker.h"
+#include "stg/common.h"
+#include "stg/locker.h"
 
 #ifdef STG_TIME
 extern volatile time_t stgTime;
@@ -30,9 +30,18 @@ STG_PINGER::STG_PINGER(time_t d)
       isRunningSender(false),
       sendSocket(-1),
       recvSocket(-1),
-      pid(0)
+      sendThread(),
+      recvThread(),
+      pmSend(),
+      pid(0),
+      errorStr(),
+      pingIP(),
+      ipToAdd(),
+      ipToDel(),
+      mutex()
 {
     pthread_mutex_init(&mutex, NULL);
+    memset(&pmSend, 0, sizeof(pmSend));
 }
 //-----------------------------------------------------------------------------
 STG_PINGER::~STG_PINGER()
@@ -273,7 +282,7 @@ uint32_t STG_PINGER::RecvPing()
 //-----------------------------------------------------------------------------
 void * STG_PINGER::RunSendPing(void * d)
 {
-    STG_PINGER * pinger = (STG_PINGER*)d;
+    STG_PINGER * pinger = static_cast<STG_PINGER *>(d);
 
     pinger->isRunningSender = true;
     time_t lastPing = 0;
@@ -317,23 +326,18 @@ void * STG_PINGER::RunSendPing(void * d)
 //-----------------------------------------------------------------------------
 void * STG_PINGER::RunRecvPing(void * d)
 {
-    STG_PINGER * pinger = (STG_PINGER*)d;
+    STG_PINGER * pinger = static_cast<STG_PINGER *>(d);
 
     pinger->isRunningRecver = true;
 
-    uint32_t ip;
-    std::multimap<uint32_t, time_t>::iterator treeIterLower;
-    std::multimap<uint32_t, time_t>::iterator treeIterUpper;
-
     while (pinger->nonstop)
         {
-        ip = pinger->RecvPing();
+        uint32_t ip = pinger->RecvPing();
 
         if (ip)
             {
-            treeIterUpper = pinger->pingIP.upper_bound(ip);
-            treeIterLower = pinger->pingIP.lower_bound(ip);
-            int i = 0;
+            std::multimap<uint32_t, time_t>::iterator treeIterUpper = pinger->pingIP.upper_bound(ip);
+            std::multimap<uint32_t, time_t>::iterator treeIterLower = pinger->pingIP.lower_bound(ip);
             while (treeIterUpper != treeIterLower)
                 {
                 #ifdef STG_TIME
@@ -342,7 +346,6 @@ void * STG_PINGER::RunRecvPing(void * d)
                 treeIterLower->second = time(NULL);
                 #endif
                 ++treeIterLower;
-                i++;
                 }
             }