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
int maxDiff = conf->getArgPInt("--" + prefix + "-maxdifferense", it.getProp("maxDifferense"), 100);
int maxProcessingCount = conf->getArgPInt("--" + prefix + "-maxprocessingcount", it.getProp("maxProcessingCount"), 100);
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");
......@@ -340,6 +341,7 @@ UNetExchange::UNetExchange(uniset::ObjectId objId, uniset::ObjectId shmId, const
r->setReceivePause(recvpause);
r->setUpdatePause(updatepause);
r->setCheckConnectionPause(checkConnectionPause);
r->setInitPause(initpause);
r->setMaxDifferens(maxDiff);
r->setMaxProcessingCount(maxProcessingCount);
r->setRespondID(resp_id, resp_invert);
......@@ -370,6 +372,7 @@ UNetExchange::UNetExchange(uniset::ObjectId objId, uniset::ObjectId shmId, const
r2->setReceivePause(recvpause);
r2->setUpdatePause(updatepause);
r2->setCheckConnectionPause(checkConnectionPause);
r2->setInitPause(initpause);
r2->setMaxDifferens(maxDiff);
r2->setMaxProcessingCount(maxProcessingCount);
r2->setRespondID(resp2_id, resp_invert);
......@@ -536,7 +539,9 @@ void UNetExchange::ReceiverInfo::step( const std::shared_ptr<SMInterface>& shm,
if( respondInvert )
resp = !resp;
shm->localSetValue(itRespond, sidRespond, resp, shm->ID());
// сохраняем только если закончилось время на начальную инициализацию
if( (r1 && r1->isInitOK()) || (r2 && r2->isInitOK()) )
shm->localSetValue(itRespond, sidRespond, resp, shm->ID());
}
}
catch( const std::exception& ex )
......
......@@ -83,6 +83,8 @@ UNetReceiver::UNetReceiver(const std::string& s_host, int _port, const std::shar
evStatistic.set<UNetReceiver, &UNetReceiver::statisticsEvent>(this);
evUpdate.set<UNetReceiver, &UNetReceiver::updateEvent>(this);
ptInitOK.setTiming(initPause);
}
// -----------------------------------------------------------------------------
UNetReceiver::~UNetReceiver()
......@@ -144,6 +146,12 @@ void UNetReceiver::setEvrunTimeout( timeout_t msec ) noexcept
evrunTimeout = msec;
}
// -----------------------------------------------------------------------------
void UNetReceiver::setInitPause( timeout_t msec ) noexcept
{
initPause = msec;
ptInitOK.setTiming(initPause);
}
// -----------------------------------------------------------------------------
void UNetReceiver::setRespondID( uniset::ObjectId id, bool invert ) noexcept
{
sidRespond = id;
......@@ -166,6 +174,11 @@ void UNetReceiver::setLockUpdate( bool st ) noexcept
ptPrepare.reset();
}
// -----------------------------------------------------------------------------
bool UNetReceiver::isInitOK() const noexcept
{
return ptInitOK.checkTime();
}
// -----------------------------------------------------------------------------
void UNetReceiver::resetTimeout() noexcept
{
std::lock_guard<std::mutex> l(tmMutex);
......@@ -238,7 +251,10 @@ void UNetReceiver::start()
}
if( upStrategy == useUpdateThread && !upThread->isRunning() )
{
ptInitOK.reset();
upThread->start();
}
}
else
forceUpdate();
......@@ -248,6 +264,7 @@ void UNetReceiver::evprepare( const ev::loop_ref& eloop ) noexcept
{
evStatistic.set(eloop);
evStatistic.start(0, 1.0); // раз в сек
ptInitOK.reset();
if( upStrategy == useUpdateEventLoop )
{
......
......@@ -119,6 +119,8 @@ namespace uniset
return lockUpdate;
}
bool isInitOK() const noexcept;
void resetTimeout() noexcept;
inline bool isRecvOK() const noexcept
......@@ -138,6 +140,7 @@ namespace uniset
void setCheckConnectionPause( timeout_t msec ) noexcept;
void setMaxDifferens( unsigned long set ) noexcept;
void setEvrunTimeout(timeout_t msec ) noexcept;
void setInitPause( timeout_t msec ) noexcept;
void setRespondID( uniset::ObjectId id, bool invert = false ) noexcept;
void setLostPacketsID( uniset::ObjectId id ) noexcept;
......@@ -278,10 +281,12 @@ namespace uniset
PassiveTimer ptRecvTimeout;
PassiveTimer ptPrepare;
PassiveTimer ptInitOK;
timeout_t recvTimeout = { 5000 }; // msec
timeout_t prepareTime = { 2000 };
timeout_t evrunTimeout = { 15000 };
timeout_t lostTimeout = { 200 };
timeout_t initPause = { 5000 }; // пауза на начальную инициализацию
PassiveTimer ptLostTimeout;
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