Commit 316d7772 authored by Pavel Vainerman's avatar Pavel Vainerman Committed by Pavel Vainerman

(modbus): make style

parent 08cccaf0
...@@ -139,7 +139,7 @@ namespace uniset ...@@ -139,7 +139,7 @@ namespace uniset
return i; return i;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
size_t ModbusTCPCore::readDataFD( int fd, std::queue<unsigned char>& qrecv, size_t max , size_t attempts ) size_t ModbusTCPCore::readDataFD( int fd, std::queue<unsigned char>& qrecv, size_t max, size_t attempts )
{ {
bool commfail = false; bool commfail = false;
......
...@@ -115,6 +115,7 @@ namespace uniset ...@@ -115,6 +115,7 @@ namespace uniset
try try
{ {
auto tmpSock = make_shared<UTCPSocket>(iaddr, port); auto tmpSock = make_shared<UTCPSocket>(iaddr, port);
if( sock ) if( sock )
sock.reset(); sock.reset();
...@@ -148,10 +149,12 @@ namespace uniset ...@@ -148,10 +149,12 @@ namespace uniset
asyncResetSockTimeout.start(); asyncResetSockTimeout.start();
ioTimer.set(loop); ioTimer.set(loop);
if( tmTime_msec != UniSetTimer::WaitUpTime ) if( tmTime_msec != UniSetTimer::WaitUpTime )
ioTimer.start(0, tmTime); ioTimer.start(0, tmTime);
sockTimeout.set(loop); sockTimeout.set(loop);
if( socketTimeout_msec > 0 && socketTimeout_msec != UniSetTimer::WaitUpTime ) if( socketTimeout_msec > 0 && socketTimeout_msec != UniSetTimer::WaitUpTime )
sockTimeout.start(0, tmSockTimeout); sockTimeout.start(0, tmSockTimeout);
} }
...@@ -263,15 +266,18 @@ namespace uniset ...@@ -263,15 +266,18 @@ namespace uniset
void ModbusTCPServer::setSocketTimeout( timeout_t msec ) void ModbusTCPServer::setSocketTimeout( timeout_t msec )
{ {
socketTimeout_msec = msec; socketTimeout_msec = msec;
if( msec == UniSetTimer::WaitUpTime || msec == 0 ) if( msec == UniSetTimer::WaitUpTime || msec == 0 )
{ {
socketTimeout_msec = 0; socketTimeout_msec = 0;
if( sockTimeout.is_active() ) if( sockTimeout.is_active() )
sockTimeout.stop(); sockTimeout.stop();
} }
else else
{ {
tmSockTimeout = (double)msec / 1000.; tmSockTimeout = (double)msec / 1000.;
if( sockTimeout.is_active() ) if( sockTimeout.is_active() )
sockTimeout.start( 0, tmSockTimeout ); sockTimeout.start( 0, tmSockTimeout );
} }
...@@ -417,11 +423,13 @@ namespace uniset ...@@ -417,11 +423,13 @@ namespace uniset
{ {
if( dlog->is_crit() ) if( dlog->is_crit() )
dlog->crit() << myname << "(ModbusTCPServer::onSocketTimeout): invalid event" << endl; dlog->crit() << myname << "(ModbusTCPServer::onSocketTimeout): invalid event" << endl;
return; return;
} }
{ {
std::lock_guard<std::mutex> l(sMutex); std::lock_guard<std::mutex> l(sMutex);
if( !slist.empty()) if( !slist.empty())
{ {
if( dlog->is_info() ) if( dlog->is_info() )
...@@ -438,6 +446,7 @@ namespace uniset ...@@ -438,6 +446,7 @@ namespace uniset
try try
{ {
createSocket(); createSocket();
if( io.is_active() ) if( io.is_active() )
io.stop(); io.stop();
......
...@@ -315,7 +315,7 @@ namespace uniset ...@@ -315,7 +315,7 @@ namespace uniset
return 0; return 0;
} }
} }
catch( const uniset::CommFailed& ex ){} catch( const uniset::CommFailed& ex ) {}
if( !cancelled && dlog->is_info() ) if( !cancelled && dlog->is_info() )
dlog->info() << peername << "(getNextData): client disconnected" << endl; dlog->info() << peername << "(getNextData): client disconnected" << endl;
...@@ -384,7 +384,7 @@ namespace uniset ...@@ -384,7 +384,7 @@ namespace uniset
} }
while( len == 0 && !pt.checkTime() ); while( len == 0 && !pt.checkTime() );
} }
catch( const uniset::CommFailed& ex ){} catch( const uniset::CommFailed& ex ) {}
if( len < mhead.len ) if( len < mhead.len )
{ {
......
...@@ -1617,7 +1617,7 @@ namespace uniset ...@@ -1617,7 +1617,7 @@ namespace uniset
{ {
addr = a; addr = a;
func = fnWriteOutputRegisters; func = fnWriteOutputRegisters;
memset(data,0,sizeof(data)); memset(data, 0, sizeof(data));
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
bool WriteOutputMessage::addData( ModbusData d ) bool WriteOutputMessage::addData( ModbusData d )
...@@ -1869,7 +1869,7 @@ namespace uniset ...@@ -1869,7 +1869,7 @@ namespace uniset
return os << (*m); return os << (*m);
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
ForceSingleCoilMessage::ForceSingleCoilMessage( ModbusAddr a, ModbusData r , bool cmd ): ForceSingleCoilMessage::ForceSingleCoilMessage( ModbusAddr a, ModbusData r, bool cmd ):
start(r) start(r)
{ {
addr = a; addr = a;
...@@ -2040,7 +2040,7 @@ namespace uniset ...@@ -2040,7 +2040,7 @@ namespace uniset
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
WriteSingleOutputMessage::WriteSingleOutputMessage( ModbusAddr a, ModbusData r , ModbusData d ): WriteSingleOutputMessage::WriteSingleOutputMessage( ModbusAddr a, ModbusData r, ModbusData d ):
start(r), start(r),
data(d) data(d)
{ {
......
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