Browse Source

delay'e

master
Piotr Dergun 7 years ago
parent
commit
d10c6de7eb
4 changed files with 34 additions and 6 deletions
  1. +24
    -0
      Log.cpp
  2. +4
    -0
      Log.h
  3. +5
    -6
      NATRouter.cpp
  4. +1
    -0
      Node.cpp

+ 24
- 0
Log.cpp View File

@ -15,6 +15,7 @@ Log::Log()
this->objectName = NULL; this->objectName = NULL;
this->writeMutex = Log::getMutex(); this->writeMutex = Log::getMutex();
this->setDelay(1);
} }
LOG_COLOR Log::getColor() const LOG_COLOR Log::getColor() const
@ -93,6 +94,16 @@ void Log::setLogParams(int lineNumber, LOG_COLOR color, string delimiter)
this->setDelimiter(delimiter); this->setDelimiter(delimiter);
} }
int Log::getDelay() const
{
return delayVal;
}
void Log::setDelay(int delay)
{
this->delayVal = delay;
}
pthread_mutex_t* Log::getMutex() pthread_mutex_t* Log::getMutex()
{ {
static pthread_mutex_t m; static pthread_mutex_t m;
@ -104,3 +115,16 @@ pthread_mutex_t* Log::getMutex()
return &m; return &m;
} }
void Log::delay(int optional)
{
int t = (optional > -1) ? optional : this->delayVal;
if (t == 0)
return;
if (t >= 10) // ns
usleep(t);
else
sleep(t); // s
}

+ 4
- 0
Log.h View File

@ -28,6 +28,7 @@ class Log
string delimiter; string delimiter;
string *objectName; string *objectName;
pthread_mutex_t *writeMutex; pthread_mutex_t *writeMutex;
int delayVal;
protected: protected:
string* getObjectName() const; string* getObjectName() const;
void setObjectName(string* objectName); void setObjectName(string* objectName);
@ -43,6 +44,9 @@ public:
void setLineNumber(int lineNumber); void setLineNumber(int lineNumber);
void setLogParams(int lineNumber, LOG_COLOR color, string delimiter); void setLogParams(int lineNumber, LOG_COLOR color, string delimiter);
static pthread_mutex_t * getMutex(); static pthread_mutex_t * getMutex();
void delay(int optional=-1);
int getDelay() const;
void setDelay(int delay);
}; };
#endif /* LOG_H_ */ #endif /* LOG_H_ */

+ 5
- 6
NATRouter.cpp View File

@ -86,8 +86,7 @@ void NATRouter::onRecv()
{ {
// TUTAJ ew. implementacja obslugi pakietu adresowanego do routera // TUTAJ ew. implementacja obslugi pakietu adresowanego do routera
} }
//usleep(500000);
sleep(1);
this->delay();
} }
else else
{ {
@ -96,7 +95,7 @@ void NATRouter::onRecv()
this->print("onRecv() sleeping..."); this->print("onRecv() sleeping...");
#endif #endif
} }
sleep(1);
this->delay();
} }
} }
@ -148,7 +147,7 @@ void NATRouter::sNAT(Packet *packet)
{ {
//TESTOWO //TESTOWO
this->print("NAT table full, waiting 1s"); this->print("NAT table full, waiting 1s");
sleep(1);
this->delay(1);
} }
// wstawiam do tablicy NAT info ze port zarezerowany na odbior // wstawiam do tablicy NAT info ze port zarezerowany na odbior
@ -164,7 +163,7 @@ void NATRouter::sNAT(Packet *packet)
packet->setSrcPort(port); // zamieniam port lokalny na WAN'owy - z tablicy NAT packet->setSrcPort(port); // zamieniam port lokalny na WAN'owy - z tablicy NAT
this->print(ss.str()); this->print(ss.str());
sleep(1);
this->delay();
this->send(*packet, true); // wysylam dalej this->send(*packet, true); // wysylam dalej
natItem = NULL; natItem = NULL;
} }
@ -188,7 +187,7 @@ void NATRouter::dNAT(Packet* packet)
natItem->increaseTimeout(5); // podbijam o kolejne 5 sekund skoro transmisja trwa natItem->increaseTimeout(5); // podbijam o kolejne 5 sekund skoro transmisja trwa
this->print(ss.str()); this->print(ss.str());
sleep(1);
this->delay();
this->send(*packet, true); // wysylam dalej this->send(*packet, true); // wysylam dalej
natItem = NULL; natItem = NULL;

+ 1
- 0
Node.cpp View File

@ -94,6 +94,7 @@ Node::Node()
this->setGatewayIp("0.0.0.0"); this->setGatewayIp("0.0.0.0");
this->setObjectName(&this->hostname); this->setObjectName(&this->hostname);
this->setDelay(1);
} }
Node::~Node() Node::~Node()

Loading…
Cancel
Save