Commit a46fcef3 authored by Pavel Vainerman's avatar Pavel Vainerman

(UNetUDP): небольшой рефакторинг, подправил тесты, добавил вывод дополнительной

информации в getShortInfo().
parent 1826c476
...@@ -270,6 +270,7 @@ void UNetReceiver::real_update() ...@@ -270,6 +270,7 @@ void UNetReceiver::real_update()
if( !ptLostTimeout.checkTime() ) if( !ptLostTimeout.checkTime() )
return; return;
unetwarn << myname << "(update): lostTimeout(" << ptLostTimeout.getInterval() << ")! pnum=" << p.num << " lost " << sub << " packets " << endl;
lostPackets += sub; lostPackets += sub;
} }
else if( p.num == pnum ) else if( p.num == pnum )
...@@ -286,7 +287,10 @@ void UNetReceiver::real_update() ...@@ -286,7 +287,10 @@ void UNetReceiver::real_update()
{ {
// считаем сколько пакетов потеряли.. // считаем сколько пакетов потеряли..
if( p.num > pnum ) if( p.num > pnum )
{
lostPackets += sub; lostPackets += sub;
unetwarn << myname << "(update): sub=" << sub << " > maxDifferenst(" << maxDifferens << ")! lost " << sub << " packets " << endl;
}
} }
} }
...@@ -546,7 +550,7 @@ void UNetReceiver::initIterators() ...@@ -546,7 +550,7 @@ void UNetReceiver::initIterators()
{ {
for( auto mit = d_icache_map.begin(); mit != d_icache_map.end(); ++mit ) for( auto mit = d_icache_map.begin(); mit != d_icache_map.end(); ++mit )
{ {
CacheList& d_icache(mit->second.cache); CacheVec& d_icache(mit->second.cache);
for( auto && it : d_icache ) for( auto && it : d_icache )
shm->initIterator(it.ioit); shm->initIterator(it.ioit);
...@@ -554,7 +558,7 @@ void UNetReceiver::initIterators() ...@@ -554,7 +558,7 @@ void UNetReceiver::initIterators()
for( auto mit = a_icache_map.begin(); mit != a_icache_map.end(); ++mit ) for( auto mit = a_icache_map.begin(); mit != a_icache_map.end(); ++mit )
{ {
CacheList& a_icache(mit->second.cache); CacheVec& a_icache(mit->second.cache);
for( auto && it : a_icache ) for( auto && it : a_icache )
shm->initIterator(it.ioit); shm->initIterator(it.ioit);
...@@ -666,7 +670,18 @@ const std::string UNetReceiver::getShortInfo() const ...@@ -666,7 +670,18 @@ const std::string UNetReceiver::getShortInfo() const
s << setw(15) << std::right << getAddress() << ":" << std::left << setw(6) << getPort() s << setw(15) << std::right << getAddress() << ":" << std::left << setw(6) << getPort()
<< ( isLockUpdate() ? "PASSIVE" : "ACTIVE" ) << ( isLockUpdate() ? "PASSIVE" : "ACTIVE" )
<< " recvOK=" << isRecvOK() << " recvOK=" << isRecvOK()
<< " lostPackets=" << setw(6) << getLostPacketsNum(); << " lostPackets=" << setw(6) << getLostPacketsNum()
<< endl
<< "\t["
<< " recvTimeout=" << setw(6) << recvTimeout
<< " prepareTime=" << setw(6) << prepareTime
<< " lostTimeout=" << setw(6) << lostTimeout
<< " recvpause=" << setw(6) << recvpause
<< " updatepause=" << setw(6) << updatepause
<< " maxDifferens=" << setw(6) << maxDifferens
<< " maxProcessingCount=" << setw(6) << maxProcessingCount
<< " waitClean=" << waitClean
<< " ]";
return std::move(s.str()); return std::move(s.str());
} }
......
...@@ -224,7 +224,7 @@ class UNetReceiver: ...@@ -224,7 +224,7 @@ class UNetReceiver:
id(UniSetTypes::DefaultObjectId), iotype(UniversalIO::UnknownIOType) {} id(UniSetTypes::DefaultObjectId), iotype(UniversalIO::UnknownIOType) {}
}; };
typedef std::vector<CacheItem> CacheList; typedef std::vector<CacheItem> CacheVec;
struct CacheInfo struct CacheInfo
{ {
CacheInfo(): CacheInfo():
...@@ -232,8 +232,9 @@ class UNetReceiver: ...@@ -232,8 +232,9 @@ class UNetReceiver:
{ {
} }
bool cache_init_ok; bool cache_init_ok;
CacheList cache; CacheVec cache;
}; };
// ключом является UDPMessage::getDataID()
typedef std::unordered_map<long, CacheInfo> CacheMap; typedef std::unordered_map<long, CacheInfo> CacheMap;
CacheMap d_icache_map; /*!< кэш итераторов для булевых */ CacheMap d_icache_map; /*!< кэш итераторов для булевых */
CacheMap a_icache_map; /*!< кэш итераторов для аналоговых */ CacheMap a_icache_map; /*!< кэш итераторов для аналоговых */
......
...@@ -465,8 +465,15 @@ const std::string UNetSender::getShortInfo() const ...@@ -465,8 +465,15 @@ const std::string UNetSender::getShortInfo() const
ostringstream s; ostringstream s;
s << setw(15) << std::right << getAddress() << ":" << std::left << setw(6) << getPort() s << setw(15) << std::right << getAddress() << ":" << std::left << setw(6) << getPort()
<< " packetnum=" << packetnum << " lastpacknum=" << packetnum
<< " lastcrc=" << setw(6) << lastcrc; << " lastcrc=" << setw(6) << lastcrc
<< " items=" << maxItem
<< endl
<< "\t packs: [sendfactor]=count: "
<< endl;
for( auto i = mypacks.begin(); i != mypacks.end(); ++i )
s << " \t\t[" << i->first << "]=" << i->second.size() << endl;
return std::move(s.str()); return std::move(s.str());
} }
......
#!/bin/sh #!/bin/sh
uniset2-start.sh -f ./uniset2-unetexchange --unet-name UNetExchange \ uniset2-start.sh -f ./uniset2-unetexchange --unet-name UNetExchange --unet-run-logserver \
--confile test.xml --smemory-id SharedMemory \ --confile test.xml --smemory-id SharedMemory \
--unet-filter-field rs --unet-filter-value 2 --unet-maxdifferense 40 --unet-sendpause 1000 \ --unet-filter-field rs --unet-filter-value 2 --unet-maxdifferense 40 --unet-sendpause 1000 \
--dlog-add-levels info,crit,warn --unet-log-add-levels info,crit,warn --dlog-add-levels info,crit,warn --unet-log-add-levels info,crit,warn
......
...@@ -319,13 +319,13 @@ TEST_CASE("[UNetUDP]: check packets 'hole'", "[unetudp][udphole]") ...@@ -319,13 +319,13 @@ TEST_CASE("[UNetUDP]: check packets 'hole'", "[unetudp][udphole]")
int lastnum = s_numpack - 1; int lastnum = s_numpack - 1;
// искуственно делаем дырку в два пакета // искусственно делаем дырку в два пакета
s_numpack = lastnum + 3; s_numpack = lastnum + 3;
UniSetUDP::UDPMessage pack_hole; UniSetUDP::UDPMessage pack_hole;
pack_hole.addAData(8, 30); pack_hole.addAData(8, 30);
send(pack_hole); // пакет с дыркой send(pack_hole); // пакет с дыркой
msleep(120); msleep(80);
REQUIRE( ui->getValue(8) == 15 ); REQUIRE( ui->getValue(8) == 15 );
REQUIRE( ui->getValue(node2_lostpackets_as) == nlost ); REQUIRE( ui->getValue(node2_lostpackets_as) == nlost );
...@@ -333,7 +333,7 @@ TEST_CASE("[UNetUDP]: check packets 'hole'", "[unetudp][udphole]") ...@@ -333,7 +333,7 @@ TEST_CASE("[UNetUDP]: check packets 'hole'", "[unetudp][udphole]")
UniSetUDP::UDPMessage pack1; UniSetUDP::UDPMessage pack1;
pack1.addAData(8, 21); pack1.addAData(8, 21);
send(pack1); // заполняем первую дырку..// дырка закроется.. пакет тут же обработается send(pack1); // заполняем первую дырку..// дырка закроется.. пакет тут же обработается
msleep(120); msleep(100);
REQUIRE( ui->getValue(8) == 21 ); REQUIRE( ui->getValue(8) == 21 );
REQUIRE( ui->getValue(node2_lostpackets_as) == nlost ); REQUIRE( ui->getValue(node2_lostpackets_as) == nlost );
......
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