Commit 6bb81d47 authored by Pavel Vainerman's avatar Pavel Vainerman

Попытка решить проблемму WaitUpTime --> Poco::TimeStamp.

Т.к. в Poco "вечное ожидание" - это 0, а в uniset = -1 (сейчас max::value).
parent 54f51f78
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <getopt.h> #include <getopt.h>
#include "Debug.h" #include "Debug.h"
#include "UniSetTypes.h" #include "UniSetTypes.h"
#include "PassiveTimer.h"
#include "Exceptions.h" #include "Exceptions.h"
#include "LogReader.h" #include "LogReader.h"
#include "LogServerTypes.h" #include "LogServerTypes.h"
...@@ -44,7 +45,7 @@ static void print_help() ...@@ -44,7 +45,7 @@ static void print_help()
printf("[-i|--iaddr] addr - LogServer ip or hostname.\n"); printf("[-i|--iaddr] addr - LogServer ip or hostname.\n");
printf("[-p|--port] port - LogServer port.\n"); printf("[-p|--port] port - LogServer port.\n");
printf("[-c|--command-only] - Send command and break. (No read logs).\n"); printf("[-c|--command-only] - Send command and break. (No read logs).\n");
printf("[-t|--timeout] msec - Timeout for wait data. Default: 0 - endless waiting\n"); printf("[-t|--timeout] msec - Timeout for wait data. Default: WaitUpTime - endless waiting\n");
printf("[-x|--reconnect-delay] msec - Pause for repeat connect to LogServer. Default: 5000 msec.\n"); printf("[-x|--reconnect-delay] msec - Pause for repeat connect to LogServer. Default: 5000 msec.\n");
printf("[-w|--logfile] logfile - Save log to 'logfile'.\n"); printf("[-w|--logfile] logfile - Save log to 'logfile'.\n");
printf("[-z|--logfile-truncate] - Truncate log file before write. Use with -w|--logfile \n"); printf("[-z|--logfile-truncate] - Truncate log file before write. Use with -w|--logfile \n");
...@@ -85,7 +86,7 @@ int main( int argc, char** argv ) ...@@ -85,7 +86,7 @@ int main( int argc, char** argv )
string logfilter(""); string logfilter("");
LogServerTypes::Command cmd = LogServerTypes::cmdNOP; LogServerTypes::Command cmd = LogServerTypes::cmdNOP;
int cmdonly = 0; int cmdonly = 0;
timeout_t tout = 5000; timeout_t tout = UniSetTimer::WaitUpTime;
timeout_t rdelay = 5000; timeout_t rdelay = 5000;
string logfile(""); string logfile("");
bool logtruncate = false; bool logtruncate = false;
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
Name: libuniset2 Name: libuniset2
Version: 2.5 Version: 2.5
Release: alt1.2 Release: alt2
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
License: LGPL License: LGPL
...@@ -484,6 +484,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname ...@@ -484,6 +484,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# .. # ..
%changelog %changelog
* Fri Aug 26 2016 Pavel Vainerman <pv@altlinux.ru> 2.5-alt2
- Fixed converting timeout_t to Poco::TimeSpan
* Thu Aug 25 2016 Pavel Vainerman <pv@altlinux.ru> 2.5-alt1.2 * Thu Aug 25 2016 Pavel Vainerman <pv@altlinux.ru> 2.5-alt1.2
- (UNetUDP): add debug information (getInfo) - (UNetUDP): add debug information (getInfo)
- minor fixes - minor fixes
......
...@@ -115,7 +115,7 @@ bool UNetSender::createConnection( bool throwEx ) ...@@ -115,7 +115,7 @@ bool UNetSender::createConnection( bool throwEx )
//udp = make_shared<UDPSocketU>(addr, port); //udp = make_shared<UDPSocketU>(addr, port);
udp = make_shared<UDPSocketU>(); udp = make_shared<UDPSocketU>();
udp->setBroadcast(true); udp->setBroadcast(true);
udp->setSendTimeout(writeTimeout * 1000); udp->setSendTimeout(UniSetTimer::timeoutToPoco(writeTimeout * 1000));
// udp->setNoDelay(true); // udp->setNoDelay(true);
} }
catch( const std::exception& e ) catch( const std::exception& e )
......
...@@ -68,6 +68,10 @@ class UniSetTimer ...@@ -68,6 +68,10 @@ class UniSetTimer
*/ */
static const timeout_t WaitUpTime = std::numeric_limits<timeout_t>::max(); static const timeout_t WaitUpTime = std::numeric_limits<timeout_t>::max();
// преобразование WaitUpTime в Poco waitpuTime у которого он = 0 :(
static const Poco::Timespan timeoutToPoco( const timeout_t );
/*! Минимальное время срабатывания. Задается в мсек. */ /*! Минимальное время срабатывания. Задается в мсек. */
static const timeout_t MinQuantityTime = 10; static const timeout_t MinQuantityTime = 10;
}; };
......
...@@ -58,15 +58,13 @@ void ModbusTCPMaster::setChannelTimeout( timeout_t msec ) ...@@ -58,15 +58,13 @@ void ModbusTCPMaster::setChannelTimeout( timeout_t msec )
if( !tcp ) if( !tcp )
return; return;
Poco::Timespan tm = UniSetTimer::timeoutToPoco(msec*1000);
Poco::Timespan old = tcp->getReceiveTimeout();; Poco::Timespan old = tcp->getReceiveTimeout();;
//timeout_t old = tcp->getReceiveTimeout();
Poco::Timespan tmsec(msec * 1000); if( old.microseconds() == tm.microseconds() )
if( old == msec )
return; return;
tcp->setReceiveTimeout(tmsec); tcp->setReceiveTimeout(tm);
int oldKeepAlive = keepAliveTimeout; int oldKeepAlive = keepAliveTimeout;
keepAliveTimeout = (msec > 1000 ? msec / 1000 : 1); keepAliveTimeout = (msec > 1000 ? msec / 1000 : 1);
...@@ -114,7 +112,10 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg, ...@@ -114,7 +112,10 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
assert(timeout); assert(timeout);
ptTimeout.setTiming(timeout); ptTimeout.setTiming(timeout);
tcp->setReceiveTimeout(timeout * 1000); if( timeout == UniSetTimer::WaitUpTime )
tcp->setReceiveTimeout(0);
else
tcp->setReceiveTimeout(timeout * 1000);
msg.makeHead(++nTransaction, crcNoCheckit); msg.makeHead(++nTransaction, crcNoCheckit);
...@@ -379,7 +380,7 @@ void ModbusTCPMaster::reconnect() ...@@ -379,7 +380,7 @@ void ModbusTCPMaster::reconnect()
{ {
tcp = make_shared<UTCPStream>(); tcp = make_shared<UTCPStream>();
tcp->create(iaddr, port, 500); tcp->create(iaddr, port, 500);
tcp->setReceiveTimeout(replyTimeOut_ms * 1000); tcp->setReceiveTimeout(UniSetTimer::timeoutToPoco(replyTimeOut_ms * 1000));
tcp->setKeepAliveParams((replyTimeOut_ms > 1000 ? replyTimeOut_ms / 1000 : 1)); tcp->setKeepAliveParams((replyTimeOut_ms > 1000 ? replyTimeOut_ms / 1000 : 1));
tcp->setNoDelay(true); tcp->setNoDelay(true);
} }
......
...@@ -78,8 +78,8 @@ void LogReader::connect( const std::string& _addr, int _port, timeout_t msec ) ...@@ -78,8 +78,8 @@ void LogReader::connect( const std::string& _addr, int _port, timeout_t msec )
{ {
tcp = make_shared<UTCPStream>(); tcp = make_shared<UTCPStream>();
tcp->create(iaddr, port, msec ); tcp->create(iaddr, port, msec );
tcp->setReceiveTimeout(inTimeout * 1000); tcp->setReceiveTimeout( UniSetTimer::timeoutToPoco(inTimeout * 1000) );
tcp->setSendTimeout(outTimeout * 1000); tcp->setSendTimeout( UniSetTimer::timeoutToPoco(outTimeout * 1000) );
tcp->setKeepAlive(true); tcp->setKeepAlive(true);
tcp->setBlocking(true); tcp->setBlocking(true);
} }
......
...@@ -101,3 +101,11 @@ bool UniSetTimer::wait( timeout_t timeMS ) ...@@ -101,3 +101,11 @@ bool UniSetTimer::wait( timeout_t timeMS )
return false; return false;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
const Poco::Timespan UniSetTimer::timeoutToPoco( const timeout_t msec )
{
if( msec == WaitUpTime )
return Poco::Timespan(0,0);
return Poco::Timespan(msec/100, msec%1000);
}
//------------------------------------------------------------------------------
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