Commit b93be6d3 authored by Pavel Vainerman's avatar Pavel Vainerman

(MOdbusTCPMaster): небольшая оптимизация на вызов setKeepAlive()

parent 30f4fa70
......@@ -65,6 +65,7 @@ class ModbusTCPMaster:
std::string iaddr = { "" };
int port = { 0 };
bool force_disconnect = { false };
int keepAliveTimeout = { 1000 };
};
// -------------------------------------------------------------------------
#endif // ModbusTCPMaster_H_
......
......@@ -65,7 +65,14 @@ void ModbusTCPMaster::setChannelTimeout( timeout_t msec )
return;
tcp->setTimeout(msec);
tcp->setKeepAliveParams((msec > 1000 ? msec / 1000 : 1));
int oldKeepAlive = keepAliveTimeout;
keepAliveTimeout = (msec > 1000 ? msec / 1000 : 1);
// т.к. каждый раз не вызывать дорогой системный вызов
// смотрим меняется ли значение
if( oldKeepAlive != keepAliveTimeout )
tcp->setKeepAliveParams(keepAliveTimeout);
}
// -------------------------------------------------------------------------
mbErrCode ModbusTCPMaster::sendData( unsigned char* buf, size_t len )
......@@ -118,8 +125,7 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
if( res != erNoError )
return res;
if( tcp->isPending(ost::Socket::pendingOutput, timeout) )
break;
break;
}
if( dlog->is_info() )
......
......@@ -508,6 +508,7 @@ Utilities/codegen/skel.src.xml
Utilities/MBTester/Makefile.am
Utilities/MBTester/mbrtuslave.cc
Utilities/MBTester/mbrtutester.cc
Utilities/MBTester/mbtcptester.cc
Utilities/MBTester/MBSlave.cc
Utilities/MBTester/mbslave.cc
Utilities/MBTester/MBSlave.h
......
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