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
60884957
Commit
60884957
authored
Aug 09, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(TCP): добавил функцию setKeepAliveParams() позволяющую задать
"тонкие" настройки по отслеживанию "живости соединения", а также мелкие правки.
parent
ffbaa93f
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
38 additions
and
15 deletions
+38
-15
log-stdin.cc
Utilities/ULog/log-stdin.cc
+1
-1
log-wrap.cc
Utilities/ULog/log-wrap.cc
+1
-1
libuniset2.spec
conf/libuniset2.spec
+4
-1
MBTCPMultiMaster.cc
extensions/ModbusMaster/MBTCPMultiMaster.cc
+0
-1
UTCPStream.h
include/UTCPStream.h
+4
-0
ModbusTCPMaster.cc
src/Communications/Modbus/ModbusTCPMaster.cc
+5
-2
ModbusTCPServer.cc
src/Communications/Modbus/ModbusTCPServer.cc
+4
-4
ModbusTCPSession.cc
src/Communications/Modbus/ModbusTCPSession.cc
+4
-4
TCPCheck.cc
src/Communications/TCP/TCPCheck.cc
+1
-0
UTCPStream.cc
src/Communications/TCP/UTCPStream.cc
+14
-1
No files found.
Utilities/ULog/log-stdin.cc
View file @
60884957
...
...
@@ -80,7 +80,7 @@ int main( int argc, char* argv[], char* envp[] )
if
(
r
>
0
)
{
buf
[
r
]
=
'\0'
;
(
*
(
log
.
get
())
)
<<
buf
;
log
->
any
(
)
<<
buf
;
}
}
}
...
...
Utilities/ULog/log-wrap.cc
View file @
60884957
...
...
@@ -91,7 +91,7 @@ int main( int argc, char* argv[], char* envp[] )
if
(
r
>
0
)
{
buf
[
r
]
=
'\0'
;
(
*
(
zlog
.
get
())
)
<<
buf
;
zlog
->
any
(
)
<<
buf
;
}
}
...
...
conf/libuniset2.spec
View file @
60884957
...
...
@@ -13,7 +13,7 @@
Name: libuniset2
Version: 2.1
Release: alt1
3
Release: alt1
4
Summary: UniSet - library for building distributed industrial control systems
...
...
@@ -456,6 +456,9 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
# ..
%changelog
* Sun Aug 09 2015 Pavel Vainerman <pv@altlinux.ru> 2.1-alt14
- (UTCPStream): add new function "setKeepAliveParams"
* Sat Aug 08 2015 Pavel Vainerman <pv@altlinux.ru> 2.1-alt13
- (ModbusMultiMaster): minor fixes (add "force" for <GateList>)
...
...
extensions/ModbusMaster/MBTCPMultiMaster.cc
View file @
60884957
...
...
@@ -368,7 +368,6 @@ void MBTCPMultiMaster::check_thread()
bool
r
=
it
->
check
();
mbinfo
<<
myname
<<
"(check): "
<<
it
->
myname
<<
" "
<<
(
r
?
"OK"
:
"FAIL"
)
<<
endl
;
cerr
<<
"respond_init="
<<
it
->
respond_init
<<
endl
;
try
{
...
...
include/UTCPStream.h
View file @
60884957
...
...
@@ -15,7 +15,11 @@ class UTCPStream:
void
create
(
const
std
::
string
&
hname
,
int
port
,
bool
throwflag
=
false
,
timeout_t
timer
=
0
);
// set keepalive params
void
setKeepAliveParams
(
timeout_t
timeout_sec
=
5
,
int
conn_keepcnt
=
1
,
int
keepintvl
=
2
);
protected
:
private
:
};
...
...
src/Communications/Modbus/ModbusTCPMaster.cc
View file @
60884957
...
...
@@ -105,7 +105,7 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
if
(
dlog
->
is_info
()
)
{
dlog
->
info
()
<<
iaddr
<<
"(ModbusTCPMaster::query): send tcp header("
<<
sizeof
(
mh
)
<<
"): "
;
mbPrintMessage
(
*
(
dlog
.
get
()
),
(
ModbusByte
*
)(
&
mh
),
sizeof
(
mh
));
mbPrintMessage
(
dlog
->
info
(
),
(
ModbusByte
*
)(
&
mh
),
sizeof
(
mh
));
dlog
->
info
()
<<
endl
;
}
...
...
@@ -177,7 +177,7 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
if
(
dlog
->
is_info
()
)
{
dlog
->
info
()
<<
"(ModbusTCPMaster::query): recv tcp header("
<<
ret
<<
"): "
;
mbPrintMessage
(
*
(
dlog
.
get
()
),
(
ModbusByte
*
)(
&
rmh
),
sizeof
(
rmh
));
mbPrintMessage
(
dlog
->
info
(
),
(
ModbusByte
*
)(
&
rmh
),
sizeof
(
rmh
));
dlog
->
info
(
false
)
<<
endl
;
}
...
...
@@ -306,6 +306,7 @@ bool ModbusTCPMaster::checkConnection( const std::string& ip, int port, int time
// Проверяем просто попыткой создать соединение..
UTCPStream
t
;
t
.
create
(
ip
,
port
,
true
,
timeout_msec
);
t
.
setKeepAliveParams
(
(
timeout_msec
>
1000
?
timeout_msec
/
1000
:
1
),
1
,
1
);
t
.
disconnect
();
return
true
;
}
...
...
@@ -332,6 +333,7 @@ void ModbusTCPMaster::reconnect()
tcp
=
make_shared
<
UTCPStream
>
();
tcp
->
create
(
iaddr
,
port
,
true
,
500
);
tcp
->
setTimeout
(
replyTimeOut_ms
);
tcp
->
setKeepAliveParams
((
replyTimeOut_ms
>
1000
?
replyTimeOut_ms
/
1000
:
1
));
}
catch
(
const
std
::
exception
&
e
)
{
...
...
@@ -385,6 +387,7 @@ void ModbusTCPMaster::connect( ost::InetAddress addr, int _port )
tcp
=
make_shared
<
UTCPStream
>
();
tcp
->
create
(
iaddr
,
port
,
true
,
500
);
tcp
->
setTimeout
(
replyTimeOut_ms
);
tcp
->
setKeepAliveParams
((
replyTimeOut_ms
>
1000
?
replyTimeOut_ms
/
1000
:
1
));
}
catch
(
const
std
::
exception
&
e
)
{
...
...
src/Communications/Modbus/ModbusTCPServer.cc
View file @
60884957
...
...
@@ -288,8 +288,8 @@ mbErrCode ModbusTCPServer::tcp_processing( ost::TCPStream& tcp, ModbusTCP::MBAPH
if
(
dlog
->
is_info
()
)
{
dlog
->
info
()
<<
"(ModbusTCPServer::tcp_processing): recv tcp header("
<<
len
<<
"): "
;
mbPrintMessage
(
*
(
dlog
.
get
()
),
(
ModbusByte
*
)(
&
mhead
),
sizeof
(
mhead
));
(
*
(
dlog
.
get
()))(
Debug
::
INFO
)
<<
endl
;
mbPrintMessage
(
dlog
->
info
(
),
(
ModbusByte
*
)(
&
mhead
),
sizeof
(
mhead
));
dlog
->
info
(
)
<<
endl
;
}
// check header
...
...
@@ -331,8 +331,8 @@ mbErrCode ModbusTCPServer::pre_send_request( ModbusMessage& request )
if
(
dlog
->
is_info
()
)
{
dlog
->
info
()
<<
"(ModbusTCPServer::pre_send_request): send tcp header: "
;
mbPrintMessage
(
*
(
dlog
.
get
()
),
(
ModbusByte
*
)(
&
curQueryHeader
),
sizeof
(
curQueryHeader
));
(
*
(
dlog
.
get
()))(
Debug
::
INFO
)
<<
endl
;
mbPrintMessage
(
dlog
->
info
(
),
(
ModbusByte
*
)(
&
curQueryHeader
),
sizeof
(
curQueryHeader
));
dlog
->
info
(
)
<<
endl
;
}
tcp
<<
curQueryHeader
;
...
...
src/Communications/Modbus/ModbusTCPSession.cc
View file @
60884957
...
...
@@ -212,8 +212,8 @@ mbErrCode ModbusTCPSession::tcp_processing( ost::TCPStream& tcp, ModbusTCP::MBAP
if
(
dlog
->
is_info
()
)
{
dlog
->
info
()
<<
peername
<<
"(tcp_processing): recv tcp header("
<<
len
<<
"): "
;
mbPrintMessage
(
*
(
dlog
.
get
()
),
(
ModbusByte
*
)(
&
mhead
),
sizeof
(
mhead
));
(
*
(
dlog
.
get
()))(
Debug
::
INFO
)
<<
endl
;
mbPrintMessage
(
dlog
->
info
(
),
(
ModbusByte
*
)(
&
mhead
),
sizeof
(
mhead
));
dlog
->
info
(
)
<<
endl
;
}
// check header
...
...
@@ -255,8 +255,8 @@ mbErrCode ModbusTCPSession::pre_send_request( ModbusMessage& request )
if
(
dlog
->
is_info
()
)
{
dlog
->
info
()
<<
peername
<<
"(pre_send_request): send tcp header: "
;
mbPrintMessage
(
*
(
dlog
.
get
()
),
(
ModbusByte
*
)(
&
curQueryHeader
),
sizeof
(
curQueryHeader
));
(
*
(
dlog
.
get
()))(
Debug
::
INFO
)
<<
endl
;
mbPrintMessage
(
dlog
->
info
(
),
(
ModbusByte
*
)(
&
curQueryHeader
),
sizeof
(
curQueryHeader
));
dlog
->
info
(
)
<<
endl
;
}
*
tcp
()
<<
curQueryHeader
;
...
...
src/Communications/TCP/TCPCheck.cc
View file @
60884957
...
...
@@ -60,6 +60,7 @@ void TCPCheck::check_thread()
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
UTCPStream
t
;
t
.
create
(
ip
,
port
,
true
,
tout_msec
);
t
.
setKeepAliveParams
(
(
tout_msec
>
1000
?
tout_msec
/
1000
:
1
)
);
setResult
(
true
);
t
.
disconnect
();
}
...
...
src/Communications/TCP/UTCPStream.cc
View file @
60884957
...
...
@@ -7,6 +7,9 @@
#include "UTCPStream.h"
#include "PassiveTimer.h"
#include "UniSetTypes.h"
// glibc..
#include <netinet/tcp.h>
// -------------------------------------------------------------------------
using
namespace
std
;
// -------------------------------------------------------------------------
...
...
@@ -20,6 +23,16 @@ UTCPStream::UTCPStream():
{
}
// -------------------------------------------------------------------------
void
UTCPStream
::
setKeepAliveParams
(
timeout_t
timeout_sec
,
int
keepcnt
,
int
keepintvl
)
{
SOCKET
fd
=
TCPStream
::
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
UTCPStream
::
create
(
const
std
::
string
&
hname
,
int
port
,
bool
throwflag
,
timeout_t
t
)
{
family
=
ost
::
Socket
::
IPV4
;
...
...
@@ -30,6 +43,6 @@ void UTCPStream::create( const std::string& hname, int port, bool throwflag, tim
connect
(
h
,
port
,
mss
);
setKeepAlive
(
true
);
setLinger
(
true
);
//setCompletion(false
);
setKeepAliveParams
(
);
}
// -------------------------------------------------------------------------
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