Commit fc266eae authored by Pavel Vainerman's avatar Pavel Vainerman

(UNetExchange): первая версия реализации "паузы на начальную инициализацию"

(после которой обновляется состояние датчиков о наличии связи).
parent 56392381
...@@ -85,6 +85,7 @@ UNetExchange::UNetExchange(uniset::ObjectId objId, uniset::ObjectId shmId, const ...@@ -85,6 +85,7 @@ UNetExchange::UNetExchange(uniset::ObjectId objId, uniset::ObjectId shmId, const
int maxDiff = conf->getArgPInt("--" + prefix + "-maxdifferense", it.getProp("maxDifferense"), 100); int maxDiff = conf->getArgPInt("--" + prefix + "-maxdifferense", it.getProp("maxDifferense"), 100);
int maxProcessingCount = conf->getArgPInt("--" + prefix + "-maxprocessingcount", it.getProp("maxProcessingCount"), 100); int maxProcessingCount = conf->getArgPInt("--" + prefix + "-maxprocessingcount", it.getProp("maxProcessingCount"), 100);
int checkConnectionPause = conf->getArgPInt("--" + prefix + "-checkconnection-pause", it.getProp("checkConnectionPause"), 10000); int checkConnectionPause = conf->getArgPInt("--" + prefix + "-checkconnection-pause", it.getProp("checkConnectionPause"), 10000);
int initpause = conf->getArgPInt("--" + prefix + "-initpause", it.getProp("initpause"), 5000);
std::string updateStrategy = conf->getArg2Param("--" + prefix + "-update-strategy", it.getProp("updateStrategy"), "evloop"); std::string updateStrategy = conf->getArg2Param("--" + prefix + "-update-strategy", it.getProp("updateStrategy"), "evloop");
...@@ -340,6 +341,7 @@ UNetExchange::UNetExchange(uniset::ObjectId objId, uniset::ObjectId shmId, const ...@@ -340,6 +341,7 @@ UNetExchange::UNetExchange(uniset::ObjectId objId, uniset::ObjectId shmId, const
r->setReceivePause(recvpause); r->setReceivePause(recvpause);
r->setUpdatePause(updatepause); r->setUpdatePause(updatepause);
r->setCheckConnectionPause(checkConnectionPause); r->setCheckConnectionPause(checkConnectionPause);
r->setInitPause(initpause);
r->setMaxDifferens(maxDiff); r->setMaxDifferens(maxDiff);
r->setMaxProcessingCount(maxProcessingCount); r->setMaxProcessingCount(maxProcessingCount);
r->setRespondID(resp_id, resp_invert); r->setRespondID(resp_id, resp_invert);
...@@ -370,6 +372,7 @@ UNetExchange::UNetExchange(uniset::ObjectId objId, uniset::ObjectId shmId, const ...@@ -370,6 +372,7 @@ UNetExchange::UNetExchange(uniset::ObjectId objId, uniset::ObjectId shmId, const
r2->setReceivePause(recvpause); r2->setReceivePause(recvpause);
r2->setUpdatePause(updatepause); r2->setUpdatePause(updatepause);
r2->setCheckConnectionPause(checkConnectionPause); r2->setCheckConnectionPause(checkConnectionPause);
r2->setInitPause(initpause);
r2->setMaxDifferens(maxDiff); r2->setMaxDifferens(maxDiff);
r2->setMaxProcessingCount(maxProcessingCount); r2->setMaxProcessingCount(maxProcessingCount);
r2->setRespondID(resp2_id, resp_invert); r2->setRespondID(resp2_id, resp_invert);
...@@ -536,6 +539,8 @@ void UNetExchange::ReceiverInfo::step( const std::shared_ptr<SMInterface>& shm, ...@@ -536,6 +539,8 @@ void UNetExchange::ReceiverInfo::step( const std::shared_ptr<SMInterface>& shm,
if( respondInvert ) if( respondInvert )
resp = !resp; resp = !resp;
// сохраняем только если закончилось время на начальную инициализацию
if( (r1 && r1->isInitOK()) || (r2 && r2->isInitOK()) )
shm->localSetValue(itRespond, sidRespond, resp, shm->ID()); shm->localSetValue(itRespond, sidRespond, resp, shm->ID());
} }
} }
......
...@@ -83,6 +83,8 @@ UNetReceiver::UNetReceiver(const std::string& s_host, int _port, const std::shar ...@@ -83,6 +83,8 @@ UNetReceiver::UNetReceiver(const std::string& s_host, int _port, const std::shar
evStatistic.set<UNetReceiver, &UNetReceiver::statisticsEvent>(this); evStatistic.set<UNetReceiver, &UNetReceiver::statisticsEvent>(this);
evUpdate.set<UNetReceiver, &UNetReceiver::updateEvent>(this); evUpdate.set<UNetReceiver, &UNetReceiver::updateEvent>(this);
ptInitOK.setTiming(initPause);
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
UNetReceiver::~UNetReceiver() UNetReceiver::~UNetReceiver()
...@@ -144,6 +146,12 @@ void UNetReceiver::setEvrunTimeout( timeout_t msec ) noexcept ...@@ -144,6 +146,12 @@ void UNetReceiver::setEvrunTimeout( timeout_t msec ) noexcept
evrunTimeout = msec; evrunTimeout = msec;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void UNetReceiver::setInitPause( timeout_t msec ) noexcept
{
initPause = msec;
ptInitOK.setTiming(initPause);
}
// -----------------------------------------------------------------------------
void UNetReceiver::setRespondID( uniset::ObjectId id, bool invert ) noexcept void UNetReceiver::setRespondID( uniset::ObjectId id, bool invert ) noexcept
{ {
sidRespond = id; sidRespond = id;
...@@ -166,6 +174,11 @@ void UNetReceiver::setLockUpdate( bool st ) noexcept ...@@ -166,6 +174,11 @@ void UNetReceiver::setLockUpdate( bool st ) noexcept
ptPrepare.reset(); ptPrepare.reset();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool UNetReceiver::isInitOK() const noexcept
{
return ptInitOK.checkTime();
}
// -----------------------------------------------------------------------------
void UNetReceiver::resetTimeout() noexcept void UNetReceiver::resetTimeout() noexcept
{ {
std::lock_guard<std::mutex> l(tmMutex); std::lock_guard<std::mutex> l(tmMutex);
...@@ -238,8 +251,11 @@ void UNetReceiver::start() ...@@ -238,8 +251,11 @@ void UNetReceiver::start()
} }
if( upStrategy == useUpdateThread && !upThread->isRunning() ) if( upStrategy == useUpdateThread && !upThread->isRunning() )
{
ptInitOK.reset();
upThread->start(); upThread->start();
} }
}
else else
forceUpdate(); forceUpdate();
} }
...@@ -248,6 +264,7 @@ void UNetReceiver::evprepare( const ev::loop_ref& eloop ) noexcept ...@@ -248,6 +264,7 @@ void UNetReceiver::evprepare( const ev::loop_ref& eloop ) noexcept
{ {
evStatistic.set(eloop); evStatistic.set(eloop);
evStatistic.start(0, 1.0); // раз в сек evStatistic.start(0, 1.0); // раз в сек
ptInitOK.reset();
if( upStrategy == useUpdateEventLoop ) if( upStrategy == useUpdateEventLoop )
{ {
......
...@@ -119,6 +119,8 @@ namespace uniset ...@@ -119,6 +119,8 @@ namespace uniset
return lockUpdate; return lockUpdate;
} }
bool isInitOK() const noexcept;
void resetTimeout() noexcept; void resetTimeout() noexcept;
inline bool isRecvOK() const noexcept inline bool isRecvOK() const noexcept
...@@ -138,6 +140,7 @@ namespace uniset ...@@ -138,6 +140,7 @@ namespace uniset
void setCheckConnectionPause( timeout_t msec ) noexcept; void setCheckConnectionPause( timeout_t msec ) noexcept;
void setMaxDifferens( unsigned long set ) noexcept; void setMaxDifferens( unsigned long set ) noexcept;
void setEvrunTimeout(timeout_t msec ) noexcept; void setEvrunTimeout(timeout_t msec ) noexcept;
void setInitPause( timeout_t msec ) noexcept;
void setRespondID( uniset::ObjectId id, bool invert = false ) noexcept; void setRespondID( uniset::ObjectId id, bool invert = false ) noexcept;
void setLostPacketsID( uniset::ObjectId id ) noexcept; void setLostPacketsID( uniset::ObjectId id ) noexcept;
...@@ -278,10 +281,12 @@ namespace uniset ...@@ -278,10 +281,12 @@ namespace uniset
PassiveTimer ptRecvTimeout; PassiveTimer ptRecvTimeout;
PassiveTimer ptPrepare; PassiveTimer ptPrepare;
PassiveTimer ptInitOK;
timeout_t recvTimeout = { 5000 }; // msec timeout_t recvTimeout = { 5000 }; // msec
timeout_t prepareTime = { 2000 }; timeout_t prepareTime = { 2000 };
timeout_t evrunTimeout = { 15000 }; timeout_t evrunTimeout = { 15000 };
timeout_t lostTimeout = { 200 }; timeout_t lostTimeout = { 200 };
timeout_t initPause = { 5000 }; // пауза на начальную инициализацию
PassiveTimer ptLostTimeout; PassiveTimer ptLostTimeout;
size_t lostPackets = { 0 }; /*!< счётчик потерянных пакетов */ size_t lostPackets = { 0 }; /*!< счётчик потерянных пакетов */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment