Commit 5dec0299 authored by Pavel Vainerman's avatar Pavel Vainerman Committed by Pavel Vainerman

(unet): minor fixes

parent 3b725a99
......@@ -512,7 +512,7 @@ void UNetReceiver::readEvent( ev::io& watcher ) noexcept
}
}
// -----------------------------------------------------------------------------
void UNetReceiver::checkConnection()
bool UNetReceiver::checkConnection()
{
bool tout = false;
......@@ -530,12 +530,21 @@ void UNetReceiver::checkConnection()
if( w )
{
if( tout )
slEvent(w, evTimeout);
else
slEvent(w, evOK);
try
{
if (tout)
slEvent(w, evTimeout);
else
slEvent(w, evOK);
}
catch( std::exception& ex )
{
unetcrit << myname << "(checkConnection): exception: " << ex.what() << endl;
}
}
}
return !tout;
}
// -----------------------------------------------------------------------------
void UNetReceiver::updateEvent( ev::periodic& tm, int revents ) noexcept
......@@ -552,7 +561,10 @@ void UNetReceiver::updateEvent( ev::periodic& tm, int revents ) noexcept
// взводим таймер опять..
tm.again();
// собственно обработка события
// смотрим есть ли связь..
bool recvOk = checkConnection();
// обновление данных в SM
try
{
update();
......@@ -562,16 +574,13 @@ void UNetReceiver::updateEvent( ev::periodic& tm, int revents ) noexcept
unetcrit << myname << "(updateEvent): " << ex.what() << std::endl;
}
// смотрим есть ли связь..
checkConnection();
if( sidRespond != DefaultObjectId )
{
try
{
if( isInitOK() )
{
bool r = respondInvert ? !isRecvOK() : isRecvOK();
bool r = respondInvert ? !recvOk : recvOk;
shm->localSetValue(itRespond, sidRespond, ( r ? 1 : 0 ), shm->ID());
}
}
......
......@@ -189,7 +189,7 @@ namespace uniset
void initIterators() noexcept;
bool createConnection( bool throwEx = false );
void checkConnection();
bool checkConnection();
size_t rnext( size_t num );
private:
......
#include <cstdlib>
#include <errno.h>
#include <getopt.h>
#include <cstring>
#include <iostream>
......@@ -68,7 +67,7 @@ int main(int argc, char* argv[])
int verb = 0;
std::string addr = "";
int port = 0;
int usecpause = 2000000;
int usecpause = 200000;
timeout_t tout = UniSetTimer::WaitUpTime;
bool broadcast = true;
int procID = 1;
......@@ -108,7 +107,7 @@ int main(int argc, char* argv[])
cout << "[-y|--prof] num - Print receive statistics every NUM packets (for -r only)" << endl;
cout << "[-a|--a-data] id1=val1,id2=val2,... - Analog data. Send: id1=id1,id2=id2,.. for analog sensors" << endl;
cout << "[-i|--d-data] id1=val1,id2=val2,... - Digital data. Send: id1=id1,id2=id2,.. for digital sensors" << endl;
cout << "[-u|--pack-num] num - first packet numbrt (default: 1)" << endl;
cout << "[-u|--pack-num] num - first packet number (default: 1)" << endl;
cout << endl;
return 0;
......@@ -255,7 +254,7 @@ int main(int argc, char* argv[])
continue;
}
size_t ret = udp.receiveBytes(&pack, sizeof(pack) );
size_t ret = udp.receiveBytes(&pack, sizeof(pack));
if( ret < 0 )
{
......@@ -281,7 +280,9 @@ int main(int argc, char* argv[])
{
if( prev_num != (pack.header.num - 1) )
cerr << "WARNING! Incorrect sequence of packets! current=" << pack.header.num
<< " prev=" << prev_num << endl;
<< " prev=" << prev_num
<< " lost: " << std::labs(pack.header.num - prev_num)
<< endl;
prev_num = pack.header.num;
}
......
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