Commit c5ef2617 authored by Pavel Vainerman's avatar Pavel Vainerman

(ModbusSession): добавил функцию setKeepAliveParams(), сделал настройки

по умолчанию.
parent cfe0364f
......@@ -13,7 +13,7 @@
Name: libuniset2
Version: 2.1
Release: alt19
Release: alt20
Summary: UniSet - library for building distributed industrial control systems
......@@ -456,6 +456,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# ..
%changelog
* Sat Aug 29 2015 Pavel Vainerman <pv@altlinux.ru> 2.1-alt20
- (ModbusSession): add setKeepAliveParams()
* Sat Aug 29 2015 Pavel Vainerman <pv@altlinux.ru> 2.1-alt19
- (ModbusSlave): rename ModbusMultiSlave --> ModbusPersistentSlave, minor fixes
......
......@@ -40,6 +40,8 @@ class ModbusTCPSession:
return caddr;
}
void setKeepAliveParams( timeout_t timeout_sec = 3, int conn_keepcnt = 2, int keepintvl = 2 );
protected:
virtual void run();
virtual void final();
......
......@@ -7,6 +7,8 @@
#include "modbus/ModbusTCPSession.h"
#include "modbus/ModbusTCPCore.h"
#include "UniSetTypes.h"
// glibc..
#include <netinet/tcp.h>
// -------------------------------------------------------------------------
using namespace std;
using namespace ModbusRTU;
......@@ -30,6 +32,14 @@ ModbusTCPSession::ModbusTCPSession( ost::TCPSocket& server, ModbusRTU::ModbusAdd
askCount(0)
{
setCRCNoCheckit(true);
timeout_t tout = timeout/1000;
if( tout <=0 )
tout = 3;
setKeepAlive(true);
setLinger(true);
setKeepAliveParams(tout);
}
// -------------------------------------------------------------------------
unsigned int ModbusTCPSession::getAskCount()
......@@ -38,6 +48,16 @@ unsigned int ModbusTCPSession::getAskCount()
return askCount;
}
// -------------------------------------------------------------------------
void ModbusTCPSession::setKeepAliveParams( timeout_t timeout_sec, int keepcnt, int keepintvl )
{
SOCKET fd = TCPSession::so;
int enable = 1;
setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&enable, sizeof(enable));
setsockopt(fd, SOL_TCP, TCP_KEEPCNT, (void*) &keepcnt, sizeof(keepcnt));
setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, (void*) &keepintvl, sizeof (keepintvl));
setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, (void*) &timeout_sec, sizeof (timeout_sec));
}
// -------------------------------------------------------------------------
void ModbusTCPSession::run()
{
if( cancelled )
......
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