delay'e
This commit is contained in:
24
Log.cpp
24
Log.cpp
@@ -15,6 +15,7 @@ Log::Log()
|
||||
this->objectName = NULL;
|
||||
|
||||
this->writeMutex = Log::getMutex();
|
||||
this->setDelay(1);
|
||||
}
|
||||
|
||||
LOG_COLOR Log::getColor() const
|
||||
@@ -93,6 +94,16 @@ void Log::setLogParams(int lineNumber, LOG_COLOR color, string delimiter)
|
||||
this->setDelimiter(delimiter);
|
||||
}
|
||||
|
||||
int Log::getDelay() const
|
||||
{
|
||||
return delayVal;
|
||||
}
|
||||
|
||||
void Log::setDelay(int delay)
|
||||
{
|
||||
this->delayVal = delay;
|
||||
}
|
||||
|
||||
pthread_mutex_t* Log::getMutex()
|
||||
{
|
||||
static pthread_mutex_t m;
|
||||
@@ -104,3 +115,16 @@ pthread_mutex_t* Log::getMutex()
|
||||
|
||||
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
Log.h
4
Log.h
@@ -28,6 +28,7 @@ class Log
|
||||
string delimiter;
|
||||
string *objectName;
|
||||
pthread_mutex_t *writeMutex;
|
||||
int delayVal;
|
||||
protected:
|
||||
string* getObjectName() const;
|
||||
void setObjectName(string* objectName);
|
||||
@@ -43,6 +44,9 @@ public:
|
||||
void setLineNumber(int lineNumber);
|
||||
void setLogParams(int lineNumber, LOG_COLOR color, string delimiter);
|
||||
static pthread_mutex_t * getMutex();
|
||||
void delay(int optional=-1);
|
||||
int getDelay() const;
|
||||
void setDelay(int delay);
|
||||
};
|
||||
|
||||
#endif /* LOG_H_ */
|
||||
|
||||
@@ -86,8 +86,7 @@ void NATRouter::onRecv()
|
||||
{
|
||||
// TUTAJ ew. implementacja obslugi pakietu adresowanego do routera
|
||||
}
|
||||
//usleep(500000);
|
||||
sleep(1);
|
||||
this->delay();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -96,7 +95,7 @@ void NATRouter::onRecv()
|
||||
this->print("onRecv() sleeping...");
|
||||
#endif
|
||||
}
|
||||
sleep(1);
|
||||
this->delay();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -148,7 +147,7 @@ void NATRouter::sNAT(Packet *packet)
|
||||
{
|
||||
//TESTOWO
|
||||
this->print("NAT table full, waiting 1s");
|
||||
sleep(1);
|
||||
this->delay(1);
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
this->print(ss.str());
|
||||
sleep(1);
|
||||
this->delay();
|
||||
this->send(*packet, true); // wysylam dalej
|
||||
natItem = NULL;
|
||||
}
|
||||
@@ -188,7 +187,7 @@ void NATRouter::dNAT(Packet* packet)
|
||||
natItem->increaseTimeout(5); // podbijam o kolejne 5 sekund skoro transmisja trwa
|
||||
|
||||
this->print(ss.str());
|
||||
sleep(1);
|
||||
this->delay();
|
||||
this->send(*packet, true); // wysylam dalej
|
||||
|
||||
natItem = NULL;
|
||||
|
||||
Reference in New Issue
Block a user