Commit 4940bae0 authored by Pavel Vainerman's avatar Pavel Vainerman

(ModbusTCPSession): попытка убрать sleep-ы в обработке запросов

parent f1f55d9f
......@@ -612,7 +612,9 @@ void MBSlave::execute_tcp()
// для обновления пороговых датчиков
tcpserver->signal_post_receive().connect( sigc::mem_fun(this, &MBSlave::postReceiveEvent) );
mbinfo << myname << "(execute_tcp): run tcpserver.." << endl;
mbinfo << myname << "(execute_tcp): run tcpserver ("
<< tcpserver->getInetAddress() << ":" << tcpserver->getInetPort()
<<")" << endl;
tcpCancelled = false;
......
......@@ -104,6 +104,8 @@ class ModbusTCPServer:
return tmTime;
}
void iowait( timeout_t msec ); // ожидание (при этом время отдаётся eventloop-у)
protected:
// функция receive пока не поддерживается...
......@@ -157,6 +159,8 @@ class ModbusTCPServer:
timeout_t tmTime_msec = { TIMEOUT_INF }; // время по умолчанию для таймера (TimerSignal)
double tmTime = { 0.0 };
PassiveTimer ptWait;
private:
// транслирование сигналов от Sessions..
void postReceiveEvent( ModbusRTU::mbErrCode res );
......
......@@ -57,6 +57,8 @@ class ModbusTCPSession:
virtual bool isActive() override;
void iowait( timeout_t msec );
protected:
virtual ModbusRTU::mbErrCode realReceive( const std::unordered_set<ModbusRTU::ModbusAddr>& vmbaddr, timeout_t msecTimeout ) override;
......@@ -139,6 +141,8 @@ class ModbusTCPSession:
FinalSlot slFin;
std::atomic_bool cancelled = { false };
PassiveTimer pt;
PassiveTimer ptWait;
};
// -------------------------------------------------------------------------
#endif // ModbusTCPSession_H_
......
......@@ -196,6 +196,13 @@ void ModbusTCPServer::setTimer( timeout_t msec )
}
}
// -------------------------------------------------------------------------
void ModbusTCPServer::iowait( timeout_t msec )
{
ptWait.setTiming(msec);
while( !ptWait.checkTime() )
io.loop.iteration();
}
// -------------------------------------------------------------------------
void ModbusTCPServer::ioAccept(ev::io& watcher, int revents)
{
if (EV_ERROR & revents)
......
......@@ -89,6 +89,13 @@ void ModbusTCPSession::setSessionTimeout( double t )
ioTimeout.start(t);
}
// -------------------------------------------------------------------------
void ModbusTCPSession::iowait( timeout_t msec )
{
ptWait.setTiming(msec);
while( !ptWait.checkTime() )
io.loop.iteration();
}
// -------------------------------------------------------------------------
void ModbusTCPSession::run( ev::loop_ref& loop )
{
if( dlog->is_info() )
......@@ -225,7 +232,7 @@ ModbusRTU::mbErrCode ModbusTCPSession::realReceive( const std::unordered_set<Mod
printProcessingTime();
}
else if( aftersend_msec > 0 )
msleep(aftersend_msec);
iowait(aftersend_msec);
return res;
}
......@@ -321,14 +328,14 @@ mbErrCode ModbusTCPSession::tcp_processing( ModbusTCP::MBAPHeader& mhead )
return erInvalidFormat;
}
len = ModbusTCPCore::readDataFD( sock->getSocket(), qrecv, mhead.len );
if( len == 0 )
pt.setTiming(10);
do
{
// делаем ещё одну попытку чтения через некоторое время
msleep(5);
len = ModbusTCPCore::readDataFD( sock->getSocket(), qrecv, mhead.len );
if( len == 0 )
io.loop.iteration();
}
while( len == 0 && !pt.checkTime() );
if( len < mhead.len )
{
......
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