Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
c5ef2617
Commit
c5ef2617
authored
Aug 29, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(ModbusSession): добавил функцию setKeepAliveParams(), сделал настройки
по умолчанию.
parent
cfe0364f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
1 deletion
+26
-1
libuniset2.spec
conf/libuniset2.spec
+4
-1
ModbusTCPSession.h
include/modbus/ModbusTCPSession.h
+2
-0
ModbusTCPSession.cc
src/Communications/Modbus/ModbusTCPSession.cc
+20
-0
No files found.
conf/libuniset2.spec
View file @
c5ef2617
...
...
@@ -13,7 +13,7 @@
Name: libuniset2
Version: 2.1
Release: alt
19
Release: alt
20
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
...
...
include/modbus/ModbusTCPSession.h
View file @
c5ef2617
...
...
@@ -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
();
...
...
src/Communications/Modbus/ModbusTCPSession.cc
View file @
c5ef2617
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment