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
6d6bd388
Commit
6d6bd388
authored
Aug 23, 2016
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ПЕРЕХОД НА libPoco: шаг первый (удаление cc++, быстрый перевод на Poco::Net)
parent
419dd6a0
Show whitespace changes
Inline
Side-by-side
Showing
71 changed files
with
438 additions
and
473 deletions
+438
-473
MBTCPServer.cc
Utilities/MBTester/MBTCPServer.cc
+2
-5
mbtcpconnection.cc
Utilities/MBTester/mbtcpconnection.cc
+1
-3
mbtcpserver.cc
Utilities/MBTester/mbtcpserver.cc
+0
-3
mbtcptester.cc
Utilities/MBTester/mbtcptester.cc
+1
-3
configure.ac
configure.ac
+12
-3
Makefile.am
extensions/LogicProcessor/tests/Makefile.am
+1
-1
MBTCPMaster.cc
extensions/ModbusMaster/MBTCPMaster.cc
+4
-5
MBTCPMultiMaster.cc
extensions/ModbusMaster/MBTCPMultiMaster.cc
+3
-4
MBTCPTestServer.cc
extensions/ModbusMaster/tests/MBTCPTestServer.cc
+7
-9
test_mbtcpmaster.cc
extensions/ModbusMaster/tests/test_mbtcpmaster.cc
+3
-2
test_mbtcpmultimaster.cc
extensions/ModbusMaster/tests/test_mbtcpmultimaster.cc
+7
-8
MBSlave.cc
extensions/ModbusSlave/MBSlave.cc
+8
-12
mbslave.cc
extensions/ModbusSlave/mbslave.cc
+0
-1
test_mbslave.cc
extensions/ModbusSlave/tests/test_mbslave.cc
+1
-2
UNetExchange.cc
extensions/UNetUDP/UNetExchange.cc
+2
-4
UNetExchange.h
extensions/UNetUDP/UNetExchange.h
+1
-2
UNetReceiver.cc
extensions/UNetUDP/UNetReceiver.cc
+2
-4
UNetReceiver.h
extensions/UNetUDP/UNetReceiver.h
+5
-6
UNetSender.cc
extensions/UNetUDP/UNetSender.cc
+8
-8
UNetSender.h
extensions/UNetUDP/UNetSender.h
+8
-7
test_unetudp.cc
extensions/UNetUDP/tests/test_unetudp.cc
+10
-8
urecv_perf_test.cc
extensions/UNetUDP/tests/urecv_perf_test.cc
+12
-13
unet-udp-tester.cc
extensions/UNetUDP/unet-udp-tester.cc
+18
-25
MTR.cc
extensions/lib/MTR.cc
+1
-0
TestProc.cc
extensions/tests/MBSlaveTest/TestProc.cc
+4
-4
Makefile.am
extensions/tests/Makefile.am
+1
-1
CallbackTimer.tcc
include/CallbackTimer.tcc
+2
-2
ComPort.h
include/ComPort.h
+1
-1
LogReader.h
include/LogReader.h
+4
-6
LogServer.h
include/LogServer.h
+3
-4
LogSession.h
include/LogSession.h
+1
-2
MessageType.h
include/MessageType.h
+1
-0
Mutex.h
include/Mutex.h
+3
-2
PassiveTimer.h
include/PassiveTimer.h
+5
-37
TCPCheck.h
include/TCPCheck.h
+1
-1
ThreadCreator.h
include/ThreadCreator.h
+31
-12
UDPCore.h
include/UDPCore.h
+18
-18
USocket.h
include/USocket.h
+3
-2
UTCPCore.h
include/UTCPCore.h
+4
-3
UTCPSocket.h
include/UTCPSocket.h
+4
-10
UTCPStream.h
include/UTCPStream.h
+4
-3
UniSetActivator.h
include/UniSetActivator.h
+0
-1
UniSetObject.h
include/UniSetObject.h
+1
-1
VMonitor.h
include/VMonitor.h
+3
-0
ModbusTCPCore.h
include/modbus/ModbusTCPCore.h
+0
-1
ModbusTCPMaster.h
include/modbus/ModbusTCPMaster.h
+3
-3
ModbusTCPServer.h
include/modbus/ModbusTCPServer.h
+6
-7
ModbusTCPServerSlot.h
include/modbus/ModbusTCPServerSlot.h
+1
-2
UModbus.cc
python/lib/pyUniSet/UModbus.cc
+1
-3
ModbusTCPCore.cc
src/Communications/Modbus/ModbusTCPCore.cc
+7
-9
ModbusTCPMaster.cc
src/Communications/Modbus/ModbusTCPMaster.cc
+33
-33
ModbusTCPServer.cc
src/Communications/Modbus/ModbusTCPServer.cc
+9
-10
ModbusTCPServerSlot.cc
src/Communications/Modbus/ModbusTCPServerSlot.cc
+1
-1
ModbusTCPSession.cc
src/Communications/Modbus/ModbusTCPSession.cc
+10
-13
TCPCheck.cc
src/Communications/TCP/TCPCheck.cc
+4
-6
USocket.cc
src/Communications/TCP/USocket.cc
+8
-7
UTCPSocket.cc
src/Communications/TCP/UTCPSocket.cc
+17
-19
UTCPStream.cc
src/Communications/TCP/UTCPStream.cc
+23
-22
LogReader.cc
src/Log/LogReader.cc
+28
-42
LogServer.cc
src/Log/LogServer.cc
+10
-18
LogSession.cc
src/Log/LogSession.cc
+19
-8
UniSetObject.cc
src/ObjectRepository/UniSetObject.cc
+3
-3
UniSetTypes.cc
src/ObjectRepository/UniSetTypes.cc
+1
-0
Makefile.am
src/Timers/Makefile.am
+3
-1
Configuration.cc
src/Various/Configuration.cc
+1
-1
Mutex.cc
src/Various/Mutex.cc
+10
-8
VMonitor.cc
src/Various/VMonitor.cc
+17
-0
Makefile.am
tests/MQPerfTest/Makefile.am
+2
-2
Makefile.am
tests/Makefile.am
+3
-3
test_tcpcheck.cc
tests/test_tcpcheck.cc
+6
-3
uniset2.files
uniset2.files
+1
-0
No files found.
Utilities/MBTester/MBTCPServer.cc
View file @
6d6bd388
...
@@ -27,14 +27,11 @@ MBTCPServer::MBTCPServer(const std::unordered_set<ModbusAddr>& myaddr, const str
...
@@ -27,14 +27,11 @@ MBTCPServer::MBTCPServer(const std::unordered_set<ModbusAddr>& myaddr, const str
// if( replyTimeout <= 0 )
// if( replyTimeout <= 0 )
// replyTimeout = 2000;
// replyTimeout = 2000;
ost
::
InetAddress
ia
(
inetaddr
.
c_str
());
if
(
verbose
)
if
(
verbose
)
cout
<<
"(init): "
cout
<<
"(init): "
<<
" addr: "
<<
i
a
<<
":"
<<
port
<<
endl
;
<<
" addr: "
<<
i
netaddr
<<
":"
<<
port
<<
endl
;
sslot
=
new
ModbusTCPServerSlot
(
i
a
,
port
);
sslot
=
new
ModbusTCPServerSlot
(
i
netaddr
,
port
);
// sslot->initLog(conf,name,logfile);
// sslot->initLog(conf,name,logfile);
...
...
Utilities/MBTester/mbtcpconnection.cc
View file @
6d6bd388
...
@@ -142,10 +142,8 @@ int main( int argc, char** argv )
...
@@ -142,10 +142,8 @@ int main( int argc, char** argv )
ModbusTCPMaster
mb
;
ModbusTCPMaster
mb
;
mb
.
setLog
(
dlog
);
mb
.
setLog
(
dlog
);
// ost::Thread::setException(ost::Thread::throwException);
ost
::
InetAddress
ia
(
iaddr
.
c_str
());
mb
.
setTimeout
(
tout
);
mb
.
setTimeout
(
tout
);
mb
.
connect
(
ia
,
port
);
mb
.
connect
(
ia
ddr
,
port
);
mb
.
setForceDisconnect
(
!
persist
);
mb
.
setForceDisconnect
(
!
persist
);
...
...
Utilities/MBTester/mbtcpserver.cc
View file @
6d6bd388
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
#include <string>
#include <string>
#include <cc++/socket.h>
#include <getopt.h>
#include <getopt.h>
#include "Debug.h"
#include "Debug.h"
#include "MBTCPServer.h"
#include "MBTCPServer.h"
...
@@ -46,8 +45,6 @@ int main( int argc, char** argv )
...
@@ -46,8 +45,6 @@ int main( int argc, char** argv )
int
replyVal
=
-
1
;
int
replyVal
=
-
1
;
timeout_t
afterpause
=
0
;
timeout_t
afterpause
=
0
;
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
try
try
{
{
while
(
1
)
while
(
1
)
...
...
Utilities/MBTester/mbtcptester.cc
View file @
6d6bd388
...
@@ -330,10 +330,8 @@ int main( int argc, char** argv )
...
@@ -330,10 +330,8 @@ int main( int argc, char** argv )
ModbusTCPMaster
mb
;
ModbusTCPMaster
mb
;
mb
.
setLog
(
dlog
);
mb
.
setLog
(
dlog
);
// ost::Thread::setException(ost::Thread::throwException);
ost
::
InetAddress
ia
(
iaddr
.
c_str
());
mb
.
setTimeout
(
tout
);
mb
.
setTimeout
(
tout
);
mb
.
connect
(
ia
,
port
);
mb
.
connect
(
ia
ddr
,
port
);
mb
.
setForceDisconnect
(
!
persist
);
mb
.
setForceDisconnect
(
!
persist
);
...
...
configure.ac
View file @
6d6bd388
...
@@ -39,7 +39,6 @@ AC_SUBST(ASTYLE_OPT)
...
@@ -39,7 +39,6 @@ AC_SUBST(ASTYLE_OPT)
PKG_CHECK_MODULES(XML, libxml-2.0)
PKG_CHECK_MODULES(XML, libxml-2.0)
PKG_CHECK_MODULES(OMNI, omniORB4)
PKG_CHECK_MODULES(OMNI, omniORB4)
PKG_CHECK_MODULES(SIGC, sigc++-2.0)
PKG_CHECK_MODULES(SIGC, sigc++-2.0)
PKG_CHECK_MODULES(COMCPP, libccgnu2)
nopkgchecklibev=false
nopkgchecklibev=false
AC_ARG_ENABLE(pkgchecklibev, AC_HELP_STRING([--disable-pkgchecklibev], [disable pkg check modules for libev]),
AC_ARG_ENABLE(pkgchecklibev, AC_HELP_STRING([--disable-pkgchecklibev], [disable pkg check modules for libev]),
...
@@ -56,6 +55,15 @@ else
...
@@ -56,6 +55,15 @@ else
AC_SUBST(EV_CFLAGS)
AC_SUBST(EV_CFLAGS)
fi
fi
#check libpoco support
AC_MSG_CHECKING([libpoco support])
#AC_CHECK_LIB([PocoNet],ServerSocket,,exit)
AC_CHECK_HEADER(Poco/Net/Socket.h,,exit)
POCO_LIBS="-lPocoFoundation -lPocoNet"
POCO_CFLAGS="-IPoco"
AC_SUBST(POCO_LIBS)
AC_SUBST(POCO_CFLAGS)
#check sqlite support
#check sqlite support
AC_MSG_CHECKING([sqlite support])
AC_MSG_CHECKING([sqlite support])
buildsqlite=true
buildsqlite=true
...
@@ -315,9 +323,9 @@ AM_CONDITIONAL(HAVE_TESTS, test ${buildtests} = true)
...
@@ -315,9 +323,9 @@ AM_CONDITIONAL(HAVE_TESTS, test ${buildtests} = true)
CXX_EXTRA_FLAGS="-Wnon-virtual-dtor -Woverloaded-virtual -Woverflow -D_GLIBCXX_USE_NANOSLEEP"
CXX_EXTRA_FLAGS="-Wnon-virtual-dtor -Woverloaded-virtual -Woverflow -D_GLIBCXX_USE_NANOSLEEP"
# export
# export
LDFLAGS="$LDFLAGS ${OMNI_LIBS} ${XML_LIBS} ${SIGC_LIBS} ${COV_LIBS} ${
COMCPP
_LIBS}"
LDFLAGS="$LDFLAGS ${OMNI_LIBS} ${XML_LIBS} ${SIGC_LIBS} ${COV_LIBS} ${
POCO
_LIBS}"
# all developer liked options add to autogen.sh, please
# all developer liked options add to autogen.sh, please
CXXFLAGS="-I\$(top_builddir)/include $CXXFLAGS -funsigned-char -std=c++11 -g -D_GNU_SOURCE ${OMNI_CFLAGS} ${XML_CFLAGS} ${SIGC_CFLAGS} ${COV_CFLAGS} ${
COMCPP
_CFLAGS} $CXX_EXTRA_FLAGS"
CXXFLAGS="-I\$(top_builddir)/include $CXXFLAGS -funsigned-char -std=c++11 -g -D_GNU_SOURCE ${OMNI_CFLAGS} ${XML_CFLAGS} ${SIGC_CFLAGS} ${COV_CFLAGS} ${
POCO
_CFLAGS} $CXX_EXTRA_FLAGS"
AC_SUBST(LDFLAGS)
AC_SUBST(LDFLAGS)
AC_SUBST(CXXFLAGS)
AC_SUBST(CXXFLAGS)
...
@@ -378,6 +386,7 @@ AC_CONFIG_FILES([Makefile
...
@@ -378,6 +386,7 @@ AC_CONFIG_FILES([Makefile
tests/Makefile
tests/Makefile
tests/UniXmlTest/Makefile
tests/UniXmlTest/Makefile
tests/MQPerfTest/Makefile
tests/MQPerfTest/Makefile
tests/PocoTest/Makefile
docs/Makefile
docs/Makefile
docs/UniSetDox.cfg
docs/UniSetDox.cfg
docs/UniSetDoxDevel.cfg
docs/UniSetDoxDevel.cfg
...
...
extensions/LogicProcessor/tests/Makefile.am
View file @
6d6bd388
...
@@ -5,7 +5,7 @@ noinst_PROGRAMS = tests
...
@@ -5,7 +5,7 @@ noinst_PROGRAMS = tests
tests_SOURCES
=
tests.cc NullSM.cc lproc.cc
tests_SOURCES
=
tests.cc NullSM.cc lproc.cc
tests_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(top_builddir)
/extensions/lib/libUniSet2Extensions.la
\
tests_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(top_builddir)
/extensions/lib/libUniSet2Extensions.la
\
$(top_builddir)
/extensions/LogicProcessor/libUniSet2LProcessor.la
$(top_builddir)
/extensions/LogicProcessor/libUniSet2LProcessor.la
-lpthread
tests_CPPFLAGS
=
-I
$(top_builddir)
/include
-I
$(top_builddir)
/extensions/include
-I
$(top_builddir)
/extensions/LogicProcessor
tests_CPPFLAGS
=
-I
$(top_builddir)
/include
-I
$(top_builddir)
/extensions/include
-I
$(top_builddir)
/extensions/LogicProcessor
$(top_builddir)/extensions/lib/libUniSet2Extensions.la
:
$(top_builddir)/extensions/lib/libUniSet2Extensions.la
:
...
...
extensions/ModbusMaster/MBTCPMaster.cc
View file @
6d6bd388
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
#include <cmath>
#include <cmath>
#include <limits>
#include <limits>
#include <sstream>
#include <sstream>
#include <Poco/Net/NetException.h>
#include <Exceptions.h>
#include <Exceptions.h>
#include <extensions/Extensions.h>
#include <extensions/Extensions.h>
#include "MBTCPMaster.h"
#include "MBTCPMaster.h"
...
@@ -101,11 +102,9 @@ std::shared_ptr<ModbusClient> MBTCPMaster::initMB( bool reopen )
...
@@ -101,11 +102,9 @@ std::shared_ptr<ModbusClient> MBTCPMaster::initMB( bool reopen )
try
try
{
{
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
mbtcp
=
std
::
make_shared
<
ModbusTCPMaster
>
();
mbtcp
=
std
::
make_shared
<
ModbusTCPMaster
>
();
ost
::
InetAddress
ia
(
iaddr
.
c_str
());
mbtcp
->
connect
(
iaddr
,
port
);
mbtcp
->
connect
(
ia
,
port
);
mbtcp
->
setForceDisconnect
(
force_disconnect
);
mbtcp
->
setForceDisconnect
(
force_disconnect
);
if
(
recv_timeout
>
0
)
if
(
recv_timeout
>
0
)
...
@@ -128,9 +127,9 @@ std::shared_ptr<ModbusClient> MBTCPMaster::initMB( bool reopen )
...
@@ -128,9 +127,9 @@ std::shared_ptr<ModbusClient> MBTCPMaster::initMB( bool reopen )
mb
=
nullptr
;
mb
=
nullptr
;
mbtcp
=
nullptr
;
mbtcp
=
nullptr
;
}
}
catch
(
const
ost
::
Exception
&
e
)
catch
(
const
Poco
::
Net
::
Net
Exception
&
e
)
{
{
mbwarn
<<
myname
<<
"(init): Can`t create socket "
<<
iaddr
<<
":"
<<
port
<<
" err: "
<<
e
.
getString
()
<<
endl
;
mbwarn
<<
myname
<<
"(init): Can`t create socket "
<<
iaddr
<<
":"
<<
port
<<
" err: "
<<
e
.
displayText
()
<<
endl
;
mb
=
nullptr
;
mb
=
nullptr
;
mbtcp
=
nullptr
;
mbtcp
=
nullptr
;
}
}
...
...
extensions/ModbusMaster/MBTCPMultiMaster.cc
View file @
6d6bd388
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#include <limits>
#include <limits>
#include <iomanip>
#include <iomanip>
#include <sstream>
#include <sstream>
#include <Poco/Net/NetException.h>
#include <Exceptions.h>
#include <Exceptions.h>
#include <extensions/Extensions.h>
#include <extensions/Extensions.h>
#include "MBTCPMultiMaster.h"
#include "MBTCPMultiMaster.h"
...
@@ -316,8 +317,6 @@ bool MBTCPMultiMaster::MBSlaveInfo::init( std::shared_ptr<DebugStream>& mblog )
...
@@ -316,8 +317,6 @@ bool MBTCPMultiMaster::MBSlaveInfo::init( std::shared_ptr<DebugStream>& mblog )
{
{
try
try
{
{
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
mbinfo
<<
myname
<<
"(init): connect..."
<<
endl
;
mbinfo
<<
myname
<<
"(init): connect..."
<<
endl
;
mbtcp
->
connect
(
ip
,
port
);
mbtcp
->
connect
(
ip
,
port
);
...
@@ -342,9 +341,9 @@ bool MBTCPMultiMaster::MBSlaveInfo::init( std::shared_ptr<DebugStream>& mblog )
...
@@ -342,9 +341,9 @@ bool MBTCPMultiMaster::MBSlaveInfo::init( std::shared_ptr<DebugStream>& mblog )
{
{
mbwarn
<<
"(init): "
<<
ex
<<
endl
;
mbwarn
<<
"(init): "
<<
ex
<<
endl
;
}
}
catch
(
const
ost
::
Exception
&
e
)
catch
(
const
Poco
::
Net
::
Net
Exception
&
e
)
{
{
mbwarn
<<
myname
<<
"(init): Can`t create socket "
<<
ip
<<
":"
<<
port
<<
" err: "
<<
e
.
getString
()
<<
endl
;
mbwarn
<<
myname
<<
"(init): Can`t create socket "
<<
ip
<<
":"
<<
port
<<
" err: "
<<
e
.
displayText
()
<<
endl
;
}
}
catch
(...)
catch
(...)
{
{
...
...
extensions/ModbusMaster/tests/MBTCPTestServer.cc
View file @
6d6bd388
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
#include <sstream>
#include <sstream>
#include <UniSetTypes.h>
#include <Poco/Net/NetException.h>
#include "UniSetTypes.h"
#include "MBTCPTestServer.h"
#include "MBTCPTestServer.h"
#include "VTypes.h"
#include "VTypes.h"
#include "uniset-config.h"
#include "uniset-config.h"
...
@@ -29,27 +30,24 @@ MBTCPTestServer::MBTCPTestServer( const std::unordered_set<ModbusAddr>& _vaddr,
...
@@ -29,27 +30,24 @@ MBTCPTestServer::MBTCPTestServer( const std::unordered_set<ModbusAddr>& _vaddr,
lastWriteOutputQ
(
0
,
0
),
lastWriteOutputQ
(
0
,
0
),
disabled
(
false
)
disabled
(
false
)
{
{
ost
::
InetAddress
ia
(
inetaddr
.
c_str
());
if
(
verbose
)
if
(
verbose
)
cout
<<
"(MBTCPTestServer::init): "
cout
<<
"(MBTCPTestServer::init): "
<<
" addr: "
<<
i
a
<<
":"
<<
port
<<
endl
;
<<
" addr: "
<<
i
netaddr
<<
":"
<<
port
<<
endl
;
{
{
ostringstream
s
;
ostringstream
s
;
s
<<
i
a
<<
":"
<<
port
;
s
<<
i
netaddr
<<
":"
<<
port
;
myname
=
s
.
str
();
myname
=
s
.
str
();
}
}
try
try
{
{
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
sslot
=
new
ModbusTCPServerSlot
(
inetaddr
,
port
);
sslot
=
new
ModbusTCPServerSlot
(
ia
,
port
);
}
}
catch
(
const
ost
::
Sock
Exception
&
e
)
catch
(
const
Poco
::
Net
::
Net
Exception
&
e
)
{
{
ostringstream
err
;
ostringstream
err
;
err
<<
"(MBTCPTestServer::init): Can`t create socket "
<<
inetaddr
<<
":"
<<
port
<<
" err: "
<<
e
.
getString
()
<<
endl
;
err
<<
"(MBTCPTestServer::init): Can`t create socket "
<<
inetaddr
<<
":"
<<
port
<<
" err: "
<<
e
.
message
()
<<
endl
;
cerr
<<
err
.
str
()
<<
endl
;
cerr
<<
err
.
str
()
<<
endl
;
throw
SystemError
(
err
.
str
());
throw
SystemError
(
err
.
str
());
}
}
...
...
extensions/ModbusMaster/tests/test_mbtcpmaster.cc
View file @
6d6bd388
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#include <memory>
#include <memory>
#include <unordered_set>
#include <unordered_set>
#include <limits>
#include <limits>
#include <Poco/Net/NetException.h>
#include "UniSetTypes.h"
#include "UniSetTypes.h"
#include "MBTCPTestServer.h"
#include "MBTCPTestServer.h"
#include "MBTCPMultiMaster.h"
#include "MBTCPMultiMaster.h"
...
@@ -57,10 +58,10 @@ static void InitTest()
...
@@ -57,10 +58,10 @@ static void InitTest()
{
{
mbs
=
make_shared
<
MBTCPTestServer
>
(
vaddr
,
iaddr
,
port
,
false
);
mbs
=
make_shared
<
MBTCPTestServer
>
(
vaddr
,
iaddr
,
port
,
false
);
}
}
catch
(
const
ost
::
Sock
Exception
&
e
)
catch
(
const
Poco
::
Net
::
Net
Exception
&
e
)
{
{
ostringstream
err
;
ostringstream
err
;
err
<<
"(mbs): Can`t create socket "
<<
iaddr
<<
":"
<<
port
<<
" err: "
<<
e
.
getString
()
<<
endl
;
err
<<
"(mbs): Can`t create socket "
<<
iaddr
<<
":"
<<
port
<<
" err: "
<<
e
.
message
()
<<
endl
;
cerr
<<
err
.
str
()
<<
endl
;
cerr
<<
err
.
str
()
<<
endl
;
throw
SystemError
(
err
.
str
());
throw
SystemError
(
err
.
str
());
}
}
...
...
extensions/ModbusMaster/tests/test_mbtcpmultimaster.cc
View file @
6d6bd388
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include <time.h>
#include <time.h>
#include <limits>
#include <limits>
#include <unordered_set>
#include <unordered_set>
#include <Poco/Net/NetException.h>
#include "UniSetTypes.h"
#include "UniSetTypes.h"
#include "MBTCPMultiMaster.h"
#include "MBTCPMultiMaster.h"
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
...
@@ -23,9 +24,9 @@ using namespace UniSetTypes;
...
@@ -23,9 +24,9 @@ using namespace UniSetTypes;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
static
ModbusRTU
::
ModbusAddr
slaveaddr
=
0x01
;
// conf->getArgInt("--mbs-my-addr");
static
ModbusRTU
::
ModbusAddr
slaveaddr
=
0x01
;
// conf->getArgInt("--mbs-my-addr");
static
int
port
=
20053
;
// conf->getArgInt("--mbs-inet-port");
static
int
port
=
20053
;
// conf->getArgInt("--mbs-inet-port");
static
string
iaddr
(
"127.0.0.1"
);
// conf->getArgParam("--mbs-inet-addr");
static
const
string
iaddr
(
"127.0.0.1"
);
// conf->getArgParam("--mbs-inet-addr");
static
int
port2
=
20055
;
static
int
port2
=
20055
;
static
string
iaddr2
(
"127.0.0.1"
);
static
const
string
iaddr2
(
"127.0.0.1"
);
static
unordered_set
<
ModbusRTU
::
ModbusAddr
>
slaveADDR
=
{
0x01
};
static
unordered_set
<
ModbusRTU
::
ModbusAddr
>
slaveADDR
=
{
0x01
};
static
shared_ptr
<
MBTCPTestServer
>
mbs1
;
static
shared_ptr
<
MBTCPTestServer
>
mbs1
;
static
shared_ptr
<
MBTCPTestServer
>
mbs2
;
static
shared_ptr
<
MBTCPTestServer
>
mbs2
;
...
@@ -55,13 +56,12 @@ static void InitTest()
...
@@ -55,13 +56,12 @@ static void InitTest()
{
{
try
try
{
{
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
mbs1
=
make_shared
<
MBTCPTestServer
>
(
slaveADDR
,
iaddr
,
port
,
false
);
mbs1
=
make_shared
<
MBTCPTestServer
>
(
slaveADDR
,
iaddr
,
port
,
false
);
}
}
catch
(
const
ost
::
Sock
Exception
&
e
)
catch
(
const
Poco
::
Net
::
Net
Exception
&
e
)
{
{
ostringstream
err
;
ostringstream
err
;
err
<<
"(mb1): Can`t create socket "
<<
iaddr
<<
":"
<<
port
<<
" err: "
<<
e
.
getString
()
<<
endl
;
err
<<
"(mb1): Can`t create socket "
<<
iaddr
<<
":"
<<
port
<<
" err: "
<<
e
.
message
()
<<
endl
;
cerr
<<
err
.
str
()
<<
endl
;
cerr
<<
err
.
str
()
<<
endl
;
throw
SystemError
(
err
.
str
());
throw
SystemError
(
err
.
str
());
}
}
...
@@ -87,13 +87,12 @@ static void InitTest()
...
@@ -87,13 +87,12 @@ static void InitTest()
{
{
try
try
{
{
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
mbs2
=
make_shared
<
MBTCPTestServer
>
(
slaveADDR
,
iaddr2
,
port2
,
false
);
mbs2
=
make_shared
<
MBTCPTestServer
>
(
slaveADDR
,
iaddr2
,
port2
,
false
);
}
}
catch
(
const
ost
::
Sock
Exception
&
e
)
catch
(
const
Poco
::
Net
::
Net
Exception
&
e
)
{
{
ostringstream
err
;
ostringstream
err
;
err
<<
"(mb2): Can`t create socket "
<<
iaddr
<<
":"
<<
port
<<
" err: "
<<
e
.
getString
()
<<
endl
;
err
<<
"(mb2): Can`t create socket "
<<
iaddr
<<
":"
<<
port
<<
" err: "
<<
e
.
message
()
<<
endl
;
cerr
<<
err
.
str
()
<<
endl
;
cerr
<<
err
.
str
()
<<
endl
;
throw
SystemError
(
err
.
str
());
throw
SystemError
(
err
.
str
());
}
}
...
...
extensions/ModbusSlave/MBSlave.cc
View file @
6d6bd388
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
#include <cmath>
#include <cmath>
#include <sstream>
#include <sstream>
#include <Poco/Net/NetException.h>
#include "Exceptions.h"
#include "Exceptions.h"
#include "Extensions.h"
#include "Extensions.h"
#include "MBSlave.h"
#include "MBSlave.h"
...
@@ -201,8 +202,7 @@ MBSlave::MBSlave(UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId, const
...
@@ -201,8 +202,7 @@ MBSlave::MBSlave(UniSetTypes::ObjectId objId, UniSetTypes::ObjectId shmId, const
mbinfo
<<
myname
<<
"(init): type=TCP inet="
<<
iaddr
<<
" port="
<<
port
<<
endl
;
mbinfo
<<
myname
<<
"(init): type=TCP inet="
<<
iaddr
<<
" port="
<<
port
<<
endl
;
ost
::
InetAddress
ia
(
iaddr
.
c_str
());
tcpserver
=
make_shared
<
ModbusTCPServerSlot
>
(
iaddr
,
port
);
tcpserver
=
make_shared
<
ModbusTCPServerSlot
>
(
ia
,
port
);
tcpserver
->
setAfterSendPause
(
aftersend_pause
);
tcpserver
->
setAfterSendPause
(
aftersend_pause
);
tcpserver
->
setReplyTimeout
(
reply_tout
);
tcpserver
->
setReplyTimeout
(
reply_tout
);
...
@@ -632,8 +632,6 @@ void MBSlave::execute_tcp()
...
@@ -632,8 +632,6 @@ void MBSlave::execute_tcp()
tcpCancelled
=
false
;
tcpCancelled
=
false
;
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
try
try
{
{
tcpserver
->
run
(
vaddr
,
true
);
tcpserver
->
run
(
vaddr
,
true
);
...
@@ -645,12 +643,12 @@ void MBSlave::execute_tcp()
...
@@ -645,12 +643,12 @@ void MBSlave::execute_tcp()
<<
":"
<<
tcpserver
->
getInetPort
()
<<
" err: "
<<
ex
<<
endl
;
<<
":"
<<
tcpserver
->
getInetPort
()
<<
" err: "
<<
ex
<<
endl
;
throw
ex
;
throw
ex
;
}
}
catch
(
const
ost
::
Exception
&
e
)
catch
(
const
Poco
::
Net
::
Net
Exception
&
e
)
{
{
mbcrit
<<
myname
<<
"(execute_tcp): Can`t create socket "
mbcrit
<<
myname
<<
"(execute_tcp): Can`t create socket "
<<
tcpserver
->
getInetAddress
()
<<
tcpserver
->
getInetAddress
()
<<
":"
<<
tcpserver
->
getInetPort
()
<<
":"
<<
tcpserver
->
getInetPort
()
<<
" err: "
<<
e
.
getString
()
<<
endl
;
<<
" err: "
<<
e
.
displayText
()
<<
endl
;
throw
e
;
throw
e
;
}
}
catch
(
const
std
::
exception
&
e
)
catch
(
const
std
::
exception
&
e
)
...
@@ -2606,8 +2604,7 @@ UniSetTypes::SimpleInfo* MBSlave::getInfo( CORBA::Long userparam )
...
@@ -2606,8 +2604,7 @@ UniSetTypes::SimpleInfo* MBSlave::getInfo( CORBA::Long userparam )
if
(
sslot
)
// т.е. если у нас tcp
if
(
sslot
)
// т.е. если у нас tcp
{
{
ost
::
InetAddress
iaddr
=
sslot
->
getInetAddress
();
inf
<<
"TCPModbusSlave: "
<<
sslot
->
getInetAddress
()
<<
":"
<<
sslot
->
getInetPort
()
<<
endl
;
inf
<<
"TCPModbusSlave: "
<<
iaddr
<<
endl
;
}
}
inf
<<
vmon
.
pretty_str
()
<<
endl
;
inf
<<
vmon
.
pretty_str
()
<<
endl
;
...
@@ -2623,8 +2620,7 @@ UniSetTypes::SimpleInfo* MBSlave::getInfo( CORBA::Long userparam )
...
@@ -2623,8 +2620,7 @@ UniSetTypes::SimpleInfo* MBSlave::getInfo( CORBA::Long userparam )
if
(
sslot
)
// т.е. если у нас tcp
if
(
sslot
)
// т.е. если у нас tcp
{
{
ost
::
InetAddress
iaddr
=
sslot
->
getInetAddress
();
inf
<<
"TCP: "
<<
sslot
->
getInetAddress
()
<<
":"
<<
sslot
->
getInetPort
()
<<
endl
;
inf
<<
"TCP: "
<<
iaddr
<<
":"
<<
sslot
->
getInetPort
()
<<
endl
;
}
}
...
@@ -2676,8 +2672,8 @@ void MBSlave::initTCPClients( UniXML::iterator confnode )
...
@@ -2676,8 +2672,8 @@ void MBSlave::initTCPClients( UniXML::iterator confnode )
}
}
// resolve (если получиться)
// resolve (если получиться)
ost
::
InetAddress
ia
(
c
.
iaddr
.
c_str
()
);
Poco
::
Net
::
SocketAddress
sa
(
c
.
iaddr
);
c
.
iaddr
=
s
tring
(
ia
.
getHostname
()
);
c
.
iaddr
=
s
a
.
host
().
toString
(
);
if
(
!
cit
.
getProp
(
"respond"
).
empty
()
)
if
(
!
cit
.
getProp
(
"respond"
).
empty
()
)
{
{
...
...
extensions/ModbusSlave/mbslave.cc
View file @
6d6bd388
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
#include <sstream>
#include <sstream>
#include <string>
#include <string>
#include <cc++/socket.h>
#include "MBSlave.h"
#include "MBSlave.h"
#include "Configuration.h"
#include "Configuration.h"
#include "Debug.h"
#include "Debug.h"
...
...
extensions/ModbusSlave/tests/test_mbslave.cc
View file @
6d6bd388
...
@@ -35,9 +35,8 @@ static void InitTest()
...
@@ -35,9 +35,8 @@ static void InitTest()
if
(
!
mb
)
if
(
!
mb
)
{
{
mb
=
std
::
make_shared
<
ModbusTCPMaster
>
();
mb
=
std
::
make_shared
<
ModbusTCPMaster
>
();
ost
::
InetAddress
ia
(
addr
.
c_str
());
mb
->
setTimeout
(
2000
);
mb
->
setTimeout
(
2000
);
REQUIRE_NOTHROW
(
mb
->
connect
(
ia
,
port
)
);
REQUIRE_NOTHROW
(
mb
->
connect
(
addr
,
port
)
);
msleep
(
5000
);
msleep
(
5000
);
}
}
}
}
...
...
extensions/UNetUDP/UNetExchange.cc
View file @
6d6bd388
...
@@ -431,13 +431,11 @@ UNetExchange::~UNetExchange()
...
@@ -431,13 +431,11 @@ UNetExchange::~UNetExchange()
{
{
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
bool
UNetExchange
::
checkExistUNetHost
(
const
std
::
string
&
addr
,
ost
::
tpport_
t
port
)
bool
UNetExchange
::
checkExistUNetHost
(
const
std
::
string
&
addr
,
in
t
port
)
{
{
ost
::
IPV4Address
a1
(
addr
.
c_str
());
for
(
const
auto
&
it
:
recvlist
)
for
(
const
auto
&
it
:
recvlist
)
{
{
if
(
it
.
r1
->
getAddress
()
==
a
1
.
getAddress
()
&&
it
.
r1
->
getPort
()
==
port
)
if
(
it
.
r1
->
getAddress
()
==
a
ddr
&&
it
.
r1
->
getPort
()
==
port
)
return
true
;
return
true
;
}
}
...
...
extensions/UNetUDP/UNetExchange.h
View file @
6d6bd388
...
@@ -21,7 +21,6 @@
...
@@ -21,7 +21,6 @@
#include <string>
#include <string>
#include <queue>
#include <queue>
#include <deque>
#include <deque>
#include <cc++/socket.h>
#include "UniSetObject.h"
#include "UniSetObject.h"
#include "Trigger.h"
#include "Trigger.h"
#include "Mutex.h"
#include "Mutex.h"
...
@@ -129,7 +128,7 @@ class UNetExchange:
...
@@ -129,7 +128,7 @@ class UNetExchange:
/*! глобальная функция для вывода help-а */
/*! глобальная функция для вывода help-а */
static
void
help_print
(
int
argc
,
const
char
*
argv
[]
);
static
void
help_print
(
int
argc
,
const
char
*
argv
[]
);
bool
checkExistUNetHost
(
const
std
::
string
&
host
,
ost
::
tpport_
t
port
);
bool
checkExistUNetHost
(
const
std
::
string
&
host
,
in
t
port
);
inline
std
::
shared_ptr
<
LogAgregator
>
getLogAggregator
()
inline
std
::
shared_ptr
<
LogAgregator
>
getLogAggregator
()
{
{
...
...
extensions/UNetUDP/UNetReceiver.cc
View file @
6d6bd388
...
@@ -38,7 +38,7 @@ bool UNetReceiver::PacketCompare::operator()(const UniSetUDP::UDPMessage& lhs,
...
@@ -38,7 +38,7 @@ bool UNetReceiver::PacketCompare::operator()(const UniSetUDP::UDPMessage& lhs,
}
}
*/
*/
// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
UNetReceiver
::
UNetReceiver
(
const
std
::
string
&
s_host
,
const
ost
::
tpport_
t
_port
,
const
std
::
shared_ptr
<
SMInterface
>&
smi
,
bool
nocheckConnection
)
:
UNetReceiver
::
UNetReceiver
(
const
std
::
string
&
s_host
,
in
t
_port
,
const
std
::
shared_ptr
<
SMInterface
>&
smi
,
bool
nocheckConnection
)
:
shm
(
smi
),
shm
(
smi
),
recvpause
(
10
),
recvpause
(
10
),
updatepause
(
100
),
updatepause
(
100
),
...
@@ -167,8 +167,6 @@ bool UNetReceiver::createConnection( bool throwEx )
...
@@ -167,8 +167,6 @@ bool UNetReceiver::createConnection( bool throwEx )
if
(
!
activated
)
if
(
!
activated
)
return
false
;
return
false
;
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
try
try
{
{
udp
=
make_shared
<
UDPReceiveU
>
(
addr
,
port
);
udp
=
make_shared
<
UDPReceiveU
>
(
addr
,
port
);
...
@@ -626,7 +624,7 @@ void UNetReceiver::stop()
...
@@ -626,7 +624,7 @@ void UNetReceiver::stop()
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
bool
UNetReceiver
::
receive
()
bool
UNetReceiver
::
receive
()
{
{
ssize_t
ret
=
udp
->
receive
(
r_buf
.
data
,
sizeof
(
r_buf
.
data
));
ssize_t
ret
=
udp
->
receive
Bytes
(
r_buf
.
data
,
sizeof
(
r_buf
.
data
));
if
(
ret
<
0
)
if
(
ret
<
0
)
{
{
...
...
extensions/UNetUDP/UNetReceiver.h
View file @
6d6bd388
...
@@ -22,7 +22,6 @@
...
@@ -22,7 +22,6 @@
#include <string>
#include <string>
#include <queue>
#include <queue>
#include <unordered_map>
#include <unordered_map>
#include <cc++/socket.h>
#include <sigc++/sigc++.h>
#include <sigc++/sigc++.h>
#include <ev++.h>
#include <ev++.h>
#include "UniSetObject.h"
#include "UniSetObject.h"
...
@@ -92,7 +91,7 @@ class UNetReceiver:
...
@@ -92,7 +91,7 @@ class UNetReceiver:
public
std
::
enable_shared_from_this
<
UNetReceiver
>
public
std
::
enable_shared_from_this
<
UNetReceiver
>
{
{
public
:
public
:
UNetReceiver
(
const
std
::
string
&
host
,
const
ost
::
tpport_
t
port
,
const
std
::
shared_ptr
<
SMInterface
>&
smi
,
bool
nocheckConnection
=
false
);
UNetReceiver
(
const
std
::
string
&
host
,
in
t
port
,
const
std
::
shared_ptr
<
SMInterface
>&
smi
,
bool
nocheckConnection
=
false
);
virtual
~
UNetReceiver
();
virtual
~
UNetReceiver
();
void
start
();
void
start
();
...
@@ -136,11 +135,11 @@ class UNetReceiver:
...
@@ -136,11 +135,11 @@ class UNetReceiver:
void
forceUpdate
();
// пересохранить очередной пакет в SM даже если данные не менялись
void
forceUpdate
();
// пересохранить очередной пакет в SM даже если данные не менялись
inline
ost
::
IPV4Address
getAddress
()
const
inline
std
::
string
getAddress
()
const
{
{
return
addr
;
return
addr
;
}
}
inline
ost
::
tpport_
t
getPort
()
const
inline
in
t
getPort
()
const
{
{
return
port
;
return
port
;
}
}
...
@@ -207,8 +206,8 @@ class UNetReceiver:
...
@@ -207,8 +206,8 @@ class UNetReceiver:
timeout_t
updatepause
=
{
100
};
/*!< переодичность обновления данных в SM, [мсек] */
timeout_t
updatepause
=
{
100
};
/*!< переодичность обновления данных в SM, [мсек] */
std
::
shared_ptr
<
UDPReceiveU
>
udp
;
std
::
shared_ptr
<
UDPReceiveU
>
udp
;
ost
::
IPV4Address
addr
;
std
::
string
addr
;
ost
::
tpport_
t
port
=
{
0
};
in
t
port
=
{
0
};
std
::
string
myname
;
std
::
string
myname
;
ev
::
io
evReceive
;
ev
::
io
evReceive
;
ev
::
periodic
evCheckConnection
;
ev
::
periodic
evCheckConnection
;
...
...
extensions/UNetUDP/UNetSender.cc
View file @
6d6bd388
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
#include <sstream>
#include <sstream>
#include <iomanip>
#include <iomanip>
#include <Poco/Net/NetException.h>
#include "Exceptions.h"
#include "Exceptions.h"
#include "Extensions.h"
#include "Extensions.h"
#include "UNetSender.h"
#include "UNetSender.h"
...
@@ -25,7 +26,7 @@ using namespace std;
...
@@ -25,7 +26,7 @@ using namespace std;
using
namespace
UniSetTypes
;
using
namespace
UniSetTypes
;
using
namespace
UniSetExtensions
;
using
namespace
UniSetExtensions
;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
UNetSender
::
UNetSender
(
const
std
::
string
&
_host
,
const
ost
::
tpport_
t
_port
,
const
std
::
shared_ptr
<
SMInterface
>&
smi
,
UNetSender
::
UNetSender
(
const
std
::
string
&
_host
,
const
in
t
_port
,
const
std
::
shared_ptr
<
SMInterface
>&
smi
,
bool
nocheckConnection
,
const
std
::
string
&
s_f
,
const
std
::
string
&
s_val
,
bool
nocheckConnection
,
const
std
::
string
&
s_f
,
const
std
::
string
&
s_val
,
const
std
::
string
&
s_prefix
,
size_t
maxDCount
,
size_t
maxACount
)
:
const
std
::
string
&
s_prefix
,
size_t
maxDCount
,
size_t
maxACount
)
:
s_field
(
s_f
),
s_field
(
s_f
),
...
@@ -106,13 +107,12 @@ UNetSender::~UNetSender()
...
@@ -106,13 +107,12 @@ UNetSender::~UNetSender()
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
bool
UNetSender
::
createConnection
(
bool
throwEx
)
bool
UNetSender
::
createConnection
(
bool
throwEx
)
{
{
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
unetinfo
<<
myname
<<
"(createConnection): .."
<<
endl
;
unetinfo
<<
myname
<<
"(createConnection): .."
<<
endl
;
try
try
{
{
udp
=
make_shared
<
ost
::
UDPBroadcast
>
(
addr
,
port
);
udp
=
make_shared
<
UDPSocketU
>
(
addr
,
port
);
udp
->
setBroadcast
(
true
);
}
}
catch
(
const
std
::
exception
&
e
)
catch
(
const
std
::
exception
&
e
)
{
{
...
@@ -252,9 +252,9 @@ void UNetSender::send()
...
@@ -252,9 +252,9 @@ void UNetSender::send()
ncycle
++
;
ncycle
++
;
}
}
catch
(
ost
::
Sock
Exception
&
e
)
catch
(
Poco
::
Net
::
Net
Exception
&
e
)
{
{
unetwarn
<<
myname
<<
"(send): "
<<
e
.
getString
()
<<
endl
;
unetwarn
<<
myname
<<
"(send): "
<<
e
.
displayText
()
<<
endl
;
}
}
catch
(
UniSetTypes
::
Exception
&
ex
)
catch
(
UniSetTypes
::
Exception
&
ex
)
{
{
...
@@ -301,11 +301,11 @@ void UNetSender::real_send( UniSetUDP::UDPMessage& mypack )
...
@@ -301,11 +301,11 @@ void UNetSender::real_send( UniSetUDP::UDPMessage& mypack )
if
(
packetnum
==
0
)
if
(
packetnum
==
0
)
packetnum
=
1
;
packetnum
=
1
;
if
(
!
udp
||
!
udp
->
isPending
(
ost
::
Socket
::
pendingOutput
)
)
if
(
!
udp
||
!
udp
->
poll
(
writeTimeout
,
Poco
::
Net
::
Socket
::
SELECT_WRITE
)
)
return
;
return
;
mypack
.
transport_msg
(
s_msg
);
mypack
.
transport_msg
(
s_msg
);
size_t
ret
=
udp
->
send
(
(
char
*
)
s_msg
.
data
,
s_msg
.
len
);
size_t
ret
=
udp
->
send
Bytes
(
(
char
*
)
s_msg
.
data
,
s_msg
.
len
);
if
(
ret
<
s_msg
.
len
)
if
(
ret
<
s_msg
.
len
)
unetcrit
<<
myname
<<
"(real_send): FAILED ret="
<<
ret
<<
" < sizeof="
<<
s_msg
.
len
<<
endl
;
unetcrit
<<
myname
<<
"(real_send): FAILED ret="
<<
ret
<<
" < sizeof="
<<
s_msg
.
len
<<
endl
;
...
...
extensions/UNetUDP/UNetSender.h
View file @
6d6bd388
...
@@ -21,13 +21,13 @@
...
@@ -21,13 +21,13 @@
#include <string>
#include <string>
#include <vector>
#include <vector>
#include <unordered_map>
#include <unordered_map>
#include <cc++/socket.h>
#include "UniSetObject.h"
#include "UniSetObject.h"
#include "Trigger.h"
#include "Trigger.h"
#include "Mutex.h"
#include "Mutex.h"
#include "SMInterface.h"
#include "SMInterface.h"
#include "SharedMemory.h"
#include "SharedMemory.h"
#include "ThreadCreator.h"
#include "ThreadCreator.h"
#include "UDPCore.h"
#include "UDPPacket.h"
#include "UDPPacket.h"
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
/*
/*
...
@@ -64,7 +64,7 @@
...
@@ -64,7 +64,7 @@
class
UNetSender
class
UNetSender
{
{
public
:
public
:
UNetSender
(
const
std
::
string
&
host
,
const
ost
::
tpport_
t
port
,
const
std
::
shared_ptr
<
SMInterface
>&
smi
,
bool
nocheckConnection
=
false
,
UNetSender
(
const
std
::
string
&
host
,
const
in
t
port
,
const
std
::
shared_ptr
<
SMInterface
>&
smi
,
bool
nocheckConnection
=
false
,
const
std
::
string
&
s_field
=
""
,
const
std
::
string
&
s_fvalue
=
""
,
const
std
::
string
&
prefix
=
"unet"
,
const
std
::
string
&
s_field
=
""
,
const
std
::
string
&
s_fvalue
=
""
,
const
std
::
string
&
prefix
=
"unet"
,
size_t
maxDCount
=
UniSetUDP
::
MaxDCount
,
size_t
maxACount
=
UniSetUDP
::
MaxACount
);
size_t
maxDCount
=
UniSetUDP
::
MaxDCount
,
size_t
maxACount
=
UniSetUDP
::
MaxACount
);
...
@@ -134,11 +134,11 @@ class UNetSender
...
@@ -134,11 +134,11 @@ class UNetSender
virtual
const
std
::
string
getShortInfo
()
const
;
virtual
const
std
::
string
getShortInfo
()
const
;
inline
ost
::
IPV4Address
getAddress
()
const
inline
std
::
string
getAddress
()
const
{
{
return
addr
;
return
addr
;
}
}
inline
ost
::
tpport_
t
getPort
()
const
inline
in
t
getPort
()
const
{
{
return
port
;
return
port
;
}
}
...
@@ -171,14 +171,15 @@ class UNetSender
...
@@ -171,14 +171,15 @@ class UNetSender
private
:
private
:
UNetSender
();
UNetSender
();
std
::
shared_ptr
<
ost
::
UDPBroadcast
>
udp
=
{
nullptr
};
std
::
shared_ptr
<
UDPSocketU
>
udp
=
{
nullptr
};
ost
::
IPV4Address
addr
;
std
::
string
addr
;
ost
::
tpport_
t
port
=
{
0
};
in
t
port
=
{
0
};
std
::
string
s_host
=
{
""
};
std
::
string
s_host
=
{
""
};
std
::
string
myname
=
{
""
};
std
::
string
myname
=
{
""
};
timeout_t
sendpause
=
{
150
};
timeout_t
sendpause
=
{
150
};
timeout_t
packsendpause
=
{
5
};
timeout_t
packsendpause
=
{
5
};
timeout_t
writeTimeout
=
{
1000
};
// msec
std
::
atomic_bool
activated
=
{
false
};
std
::
atomic_bool
activated
=
{
false
};
PassiveTimer
ptCheckConnection
;
PassiveTimer
ptCheckConnection
;
...
...
extensions/UNetUDP/tests/test_unetudp.cc
View file @
6d6bd388
#include <catch.hpp>
#include <catch.hpp>
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
#include <memory>
#include <memory>
#include <cc++/socket.h>
#include "UniSetTypes.h"
#include "UniSetTypes.h"
#include "UInterface.h"
#include "UInterface.h"
#include "UDPPacket.h"
#include "UDPPacket.h"
...
@@ -15,11 +14,11 @@ using namespace std;
...
@@ -15,11 +14,11 @@ using namespace std;
using
namespace
UniSetTypes
;
using
namespace
UniSetTypes
;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
static
int
port
=
3000
;
static
int
port
=
3000
;
static
ost
::
IPV4Host
host
(
"127.255.255.255"
);
static
const
std
::
string
host
(
"127.255.255.255"
);
static
shared_ptr
<
UInterface
>
ui
=
nullptr
;
static
shared_ptr
<
UInterface
>
ui
=
nullptr
;
static
ObjectId
aid
=
2
;
static
ObjectId
aid
=
2
;
static
std
::
shared_ptr
<
UDPReceiveU
>
udp_r
=
nullptr
;
static
std
::
shared_ptr
<
UDPReceiveU
>
udp_r
=
nullptr
;
static
shared_ptr
<
ost
::
UDPBroadcast
>
udp_s
=
nullptr
;
static
shared_ptr
<
UDPSocketU
>
udp_s
=
nullptr
;
static
int
s_port
=
3003
;
// Node2
static
int
s_port
=
3003
;
// Node2
static
int
s_nodeID
=
3003
;
static
int
s_nodeID
=
3003
;
static
int
s_procID
=
123
;
static
int
s_procID
=
123
;
...
@@ -48,7 +47,10 @@ void InitTest()
...
@@ -48,7 +47,10 @@ void InitTest()
udp_r
=
make_shared
<
UDPReceiveU
>
(
host
,
port
);
udp_r
=
make_shared
<
UDPReceiveU
>
(
host
,
port
);
if
(
udp_s
==
nullptr
)
if
(
udp_s
==
nullptr
)
udp_s
=
make_shared
<
ost
::
UDPBroadcast
>
(
host
,
s_port
);
{
udp_s
=
make_shared
<
UDPSocketU
>
(
host
,
s_port
);
udp_s
->
setBroadcast
(
true
);
}
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// pnum - минималный номер ожидаемого пакета ( 0 - любой пришедщий )
// pnum - минималный номер ожидаемого пакета ( 0 - любой пришедщий )
...
@@ -60,10 +62,10 @@ static UniSetUDP::UDPMessage receive( unsigned int pnum = 0, timeout_t tout = 20
...
@@ -60,10 +62,10 @@ static UniSetUDP::UDPMessage receive( unsigned int pnum = 0, timeout_t tout = 20
while
(
ncycle
>
0
)
while
(
ncycle
>
0
)
{
{
if
(
!
udp_r
->
isInputReady
(
tout
)
)
if
(
!
udp_r
->
poll
(
tout
,
Poco
::
Net
::
Socket
::
SELECT_READ
)
)
break
;
break
;
size_t
ret
=
udp_r
->
UDPReceive
::
receive
(
&
(
buf
.
data
),
sizeof
(
buf
.
data
)
);
size_t
ret
=
udp_r
->
receiveBytes
(
&
(
buf
.
data
),
sizeof
(
buf
.
data
)
);
size_t
sz
=
UniSetUDP
::
UDPMessage
::
getMessage
(
pack
,
buf
);
size_t
sz
=
UniSetUDP
::
UDPMessage
::
getMessage
(
pack
,
buf
);
if
(
sz
==
0
||
pnum
==
0
||
(
pnum
>
0
&&
pack
.
num
>=
pnum
)
)
if
(
sz
==
0
||
pnum
==
0
||
(
pnum
>
0
&&
pack
.
num
>=
pnum
)
)
...
@@ -78,7 +80,7 @@ static UniSetUDP::UDPMessage receive( unsigned int pnum = 0, timeout_t tout = 20
...
@@ -78,7 +80,7 @@ static UniSetUDP::UDPMessage receive( unsigned int pnum = 0, timeout_t tout = 20
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
void
send
(
UniSetUDP
::
UDPMessage
&
pack
,
int
tout
=
2000
)
void
send
(
UniSetUDP
::
UDPMessage
&
pack
,
int
tout
=
2000
)
{
{
CHECK
(
udp_s
->
isPending
(
ost
::
Socket
::
pendingOutput
,
tout
)
);
CHECK
(
udp_s
->
poll
(
tout
,
Poco
::
Net
::
Socket
::
SELECT_WRITE
)
);
pack
.
nodeID
=
s_nodeID
;
pack
.
nodeID
=
s_nodeID
;
pack
.
procID
=
s_procID
;
pack
.
procID
=
s_procID
;
...
@@ -86,7 +88,7 @@ void send( UniSetUDP::UDPMessage& pack, int tout = 2000 )
...
@@ -86,7 +88,7 @@ void send( UniSetUDP::UDPMessage& pack, int tout = 2000 )
UniSetUDP
::
UDPPacket
s_buf
;
UniSetUDP
::
UDPPacket
s_buf
;
pack
.
transport_msg
(
s_buf
);
pack
.
transport_msg
(
s_buf
);
size_t
ret
=
udp_s
->
send
((
char
*
)
&
s_buf
.
data
,
s_buf
.
len
);
size_t
ret
=
udp_s
->
send
Bytes
((
char
*
)
&
s_buf
.
data
,
s_buf
.
len
);
REQUIRE
(
ret
==
s_buf
.
len
);
REQUIRE
(
ret
==
s_buf
.
len
);
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
...
...
extensions/UNetUDP/tests/urecv_perf_test.cc
View file @
6d6bd388
#include <memory>
#include <memory>
#include <chrono>
#include <chrono>
#include <string>
#include <string>
#include <Poco/Net/NetException.h>
#include "Debug.h"
#include "Debug.h"
#include "UNetReceiver.h"
#include "UNetReceiver.h"
#include "SMInterface.h"
#include "SMInterface.h"
...
@@ -31,9 +32,7 @@ shared_ptr<SMInterface> smiInstance()
...
@@ -31,9 +32,7 @@ shared_ptr<SMInterface> smiInstance()
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
static
void
run_senders
(
size_t
max
,
const
std
::
string
&
s_host
,
size_t
count
=
50
,
timeout_t
usecpause
=
50
)
static
void
run_senders
(
size_t
max
,
const
std
::
string
&
s_host
,
size_t
count
=
50
,
timeout_t
usecpause
=
50
)
{
{
ost
::
IPV4Host
host
(
s_host
.
c_str
());
std
::
vector
<
std
::
shared_ptr
<
UDPSocketU
>
>
vsend
;
std
::
vector
<
std
::
shared_ptr
<
ost
::
UDPSocket
>
>
vsend
;
vsend
.
reserve
(
max
);
vsend
.
reserve
(
max
);
cout
<<
"Run "
<<
max
<<
" senders ("
<<
s_host
<<
")"
<<
endl
;
cout
<<
"Run "
<<
max
<<
" senders ("
<<
s_host
<<
")"
<<
endl
;
...
@@ -43,12 +42,12 @@ static void run_senders( size_t max, const std::string& s_host, size_t count = 5
...
@@ -43,12 +42,12 @@ static void run_senders( size_t max, const std::string& s_host, size_t count = 5
{
{
try
try
{
{
auto
s
=
make_shared
<
ost
::
UDPSocket
>
(
host
,
begPort
+
i
);
auto
s
=
make_shared
<
UDPSocketU
>
(
s_
host
,
begPort
+
i
);
vsend
.
emplace_back
(
s
);
vsend
.
emplace_back
(
s
);
}
}
catch
(
ost
::
Sock
Exception
&
e
)
catch
(
Poco
::
Net
::
Net
Exception
&
e
)
{
{
cerr
<<
"(run_senders): "
<<
e
.
getString
()
<<
" ("
<<
host
<<
")"
<<
endl
;
cerr
<<
"(run_senders): "
<<
e
.
displayText
()
<<
" ("
<<
s_
host
<<
")"
<<
endl
;
throw
;
throw
;
}
}
catch
(
std
::
exception
&
ex
)
catch
(
std
::
exception
&
ex
)
...
@@ -76,11 +75,11 @@ static void run_senders( size_t max, const std::string& s_host, size_t count = 5
...
@@ -76,11 +75,11 @@ static void run_senders( size_t max, const std::string& s_host, size_t count = 5
try
try
{
{
if
(
vsend
[
i
]
)
if
(
vsend
[
i
]
)
vsend
[
i
]
->
setPeer
(
host
,
begPort
+
i
);
vsend
[
i
]
->
connect
(
Poco
::
Net
::
SocketAddress
(
s_host
,
begPort
+
i
)
);
}
}
catch
(
ost
::
Sock
Exception
&
e
)
catch
(
Poco
::
Net
::
Net
Exception
&
e
)
{
{
cerr
<<
"(run_senders): "
<<
e
.
getString
()
<<
" ("
<<
host
<<
")"
<<
endl
;
cerr
<<
"(run_senders): "
<<
e
.
message
()
<<
" ("
<<
s_
host
<<
")"
<<
endl
;
throw
;
throw
;
}
}
catch
(
std
::
exception
&
ex
)
catch
(
std
::
exception
&
ex
)
...
@@ -108,18 +107,18 @@ static void run_senders( size_t max, const std::string& s_host, size_t count = 5
...
@@ -108,18 +107,18 @@ static void run_senders( size_t max, const std::string& s_host, size_t count = 5
{
{
try
try
{
{
if
(
udp
->
isPending
(
ost
::
Socket
::
pendingOutput
,
100
)
)
if
(
udp
->
poll
(
100
,
Poco
::
Net
::
Socket
::
SELECT_WRITE
)
)
{
{
mypack
.
transport_msg
(
s_buf
);
mypack
.
transport_msg
(
s_buf
);
size_t
ret
=
udp
->
send
((
char
*
)
&
s_buf
.
data
,
s_buf
.
len
);
size_t
ret
=
udp
->
send
Bytes
((
char
*
)
&
s_buf
.
data
,
s_buf
.
len
);
if
(
ret
<
s_buf
.
len
)
if
(
ret
<
s_buf
.
len
)
cerr
<<
"(send): FAILED ret="
<<
ret
<<
" < sizeof="
<<
s_buf
.
len
<<
endl
;
cerr
<<
"(send): FAILED ret="
<<
ret
<<
" < sizeof="
<<
s_buf
.
len
<<
endl
;
}
}
}
}
catch
(
ost
::
Sock
Exception
&
e
)
catch
(
Poco
::
Net
::
Net
Exception
&
e
)
{
{
cerr
<<
"(send): "
<<
e
.
getString
()
<<
" ("
<<
host
<<
")"
<<
endl
;
cerr
<<
"(send): "
<<
e
.
message
()
<<
" ("
<<
s_
host
<<
")"
<<
endl
;
}
}
catch
(
...
)
catch
(
...
)
{
{
...
...
extensions/UNetUDP/unet-udp-tester.cc
View file @
6d6bd388
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
#include <iostream>
#include <iostream>
#include <chrono>
#include <chrono>
#include <iomanip>
#include <iomanip>
#include <
cc++/socket
.h>
#include <
Poco/Net/NetException
.h>
#include "UDPPacket.h"
#include "UDPPacket.h"
#include "PassiveTimer.h"
#include "PassiveTimer.h"
#include "UDPCore.h"
#include "UDPCore.h"
...
@@ -40,7 +40,7 @@ enum Command
...
@@ -40,7 +40,7 @@ enum Command
cmdReceive
cmdReceive
};
};
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
static
bool
split_addr
(
const
string
&
addr
,
string
&
host
,
ost
::
tpport_
t
&
port
)
static
bool
split_addr
(
const
string
&
addr
,
string
&
host
,
in
t
&
port
)
{
{
string
::
size_type
pos
=
addr
.
rfind
(
':'
);
string
::
size_type
pos
=
addr
.
rfind
(
':'
);
...
@@ -62,9 +62,9 @@ int main(int argc, char* argv[])
...
@@ -62,9 +62,9 @@ int main(int argc, char* argv[])
Command
cmd
=
cmdNOP
;
Command
cmd
=
cmdNOP
;
int
verb
=
0
;
int
verb
=
0
;
std
::
string
addr
=
""
;
std
::
string
addr
=
""
;
ost
::
tpport_
t
port
=
0
;
in
t
port
=
0
;
int
usecpause
=
2000000
;
int
usecpause
=
2000000
;
timeout_t
tout
=
TIMEOUT_INF
;
timeout_t
tout
=
UniSetTimer
::
WaitUpTime
;
bool
broadcast
=
true
;
bool
broadcast
=
true
;
int
procID
=
1
;
int
procID
=
1
;
int
nodeID
=
1
;
int
nodeID
=
1
;
...
@@ -168,8 +168,6 @@ int main(int argc, char* argv[])
...
@@ -168,8 +168,6 @@ int main(int argc, char* argv[])
return
-
1
;
return
-
1
;
}
}
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
try
try
{
{
string
s_host
;
string
s_host
;
...
@@ -186,7 +184,7 @@ int main(int argc, char* argv[])
...
@@ -186,7 +184,7 @@ int main(int argc, char* argv[])
<<
" port="
<<
port
<<
" port="
<<
port
<<
" timeout="
;
<<
" timeout="
;
if
(
tout
==
TIMEOUT_INF
)
if
(
tout
==
UniSetTimer
::
WaitUpTime
)
cout
<<
"Waitup"
;
cout
<<
"Waitup"
;
else
else
cout
<<
tout
;
cout
<<
tout
;
...
@@ -195,14 +193,12 @@ int main(int argc, char* argv[])
...
@@ -195,14 +193,12 @@ int main(int argc, char* argv[])
<<
endl
;
<<
endl
;
}
}
ost
::
IPV4Host
host
(
s_host
.
c_str
());
// udp.UDPTransmit::setBroadcast(broadcast);
switch
(
cmd
)
switch
(
cmd
)
{
{
case
cmdReceive
:
case
cmdReceive
:
{
{
UDPReceiveU
udp
(
host
,
port
);
UDPReceiveU
udp
(
s_
host
,
port
);
// char buf[UniSetUDP::MaxDataLen];
// char buf[UniSetUDP::MaxDataLen];
UniSetUDP
::
UDPMessage
pack
;
UniSetUDP
::
UDPMessage
pack
;
...
@@ -232,13 +228,13 @@ int main(int argc, char* argv[])
...
@@ -232,13 +228,13 @@ int main(int argc, char* argv[])
npack
=
0
;
npack
=
0
;
}
}
if
(
!
udp
.
isInputReady
(
tout
)
)
if
(
!
udp
.
poll
(
tout
,
Poco
::
Net
::
Socket
::
SELECT_READ
)
)
{
{
cout
<<
"(recv): Timeout.."
<<
endl
;
cout
<<
"(recv): Timeout.."
<<
endl
;
continue
;
continue
;
}
}
size_t
ret
=
udp
.
UDPReceive
::
receive
(
&
(
buf
.
data
),
sizeof
(
buf
.
data
)
);
size_t
ret
=
udp
.
receiveBytes
(
&
(
buf
.
data
),
sizeof
(
buf
.
data
)
);
size_t
sz
=
UniSetUDP
::
UDPMessage
::
getMessage
(
pack
,
buf
);
size_t
sz
=
UniSetUDP
::
UDPMessage
::
getMessage
(
pack
,
buf
);
if
(
sz
==
0
)
if
(
sz
==
0
)
...
@@ -270,9 +266,9 @@ int main(int argc, char* argv[])
...
@@ -270,9 +266,9 @@ int main(int argc, char* argv[])
if
(
show
)
if
(
show
)
cout
<<
"receive data: "
<<
pack
<<
endl
;
cout
<<
"receive data: "
<<
pack
<<
endl
;
}
}
catch
(
ost
::
Sock
Exception
&
e
)
catch
(
Poco
::
Net
::
Net
Exception
&
e
)
{
{
cerr
<<
"(recv): "
<<
e
.
getString
()
<<
" ("
<<
addr
<<
")"
<<
endl
;
cerr
<<
"(recv): "
<<
e
.
displayText
()
<<
" ("
<<
addr
<<
")"
<<
endl
;
}
}
catch
(
...
)
catch
(
...
)
{
{
...
@@ -292,12 +288,8 @@ int main(int argc, char* argv[])
...
@@ -292,12 +288,8 @@ int main(int argc, char* argv[])
case
cmdSend
:
case
cmdSend
:
{
{
ost
::
UDPSocket
*
udp
;
std
::
shared_ptr
<
UDPSocketU
>
udp
=
make_shared
<
UDPSocketU
>
(
s_host
,
port
);
udp
->
setBroadcast
(
broadcast
);
if
(
!
broadcast
)
udp
=
new
ost
::
UDPSocket
();
else
udp
=
new
ost
::
UDPBroadcast
(
host
,
port
);
UniSetUDP
::
UDPMessage
mypack
;
UniSetUDP
::
UDPMessage
mypack
;
mypack
.
nodeID
=
nodeID
;
mypack
.
nodeID
=
nodeID
;
...
@@ -312,7 +304,8 @@ int main(int argc, char* argv[])
...
@@ -312,7 +304,8 @@ int main(int argc, char* argv[])
for
(
unsigned
int
i
=
0
;
i
<
count
;
i
++
)
for
(
unsigned
int
i
=
0
;
i
<
count
;
i
++
)
mypack
.
addDData
(
i
,
i
);
mypack
.
addDData
(
i
,
i
);
udp
->
setPeer
(
host
,
port
);
Poco
::
Net
::
SocketAddress
sa
(
s_host
,
port
);
udp
->
connect
(
sa
);
size_t
packetnum
=
0
;
size_t
packetnum
=
0
;
UniSetUDP
::
UDPPacket
s_buf
;
UniSetUDP
::
UDPPacket
s_buf
;
...
@@ -333,7 +326,7 @@ int main(int argc, char* argv[])
...
@@ -333,7 +326,7 @@ int main(int argc, char* argv[])
try
try
{
{
if
(
udp
->
isPending
(
ost
::
Socket
::
pendingOutput
,
tout
)
)
if
(
udp
->
poll
(
tout
,
Poco
::
Net
::
Socket
::
SELECT_WRITE
)
)
{
{
mypack
.
transport_msg
(
s_buf
);
mypack
.
transport_msg
(
s_buf
);
...
@@ -341,15 +334,15 @@ int main(int argc, char* argv[])
...
@@ -341,15 +334,15 @@ int main(int argc, char* argv[])
cout
<<
"(send): to addr="
<<
addr
<<
" d_count="
<<
mypack
.
dcount
cout
<<
"(send): to addr="
<<
addr
<<
" d_count="
<<
mypack
.
dcount
<<
" a_count="
<<
mypack
.
acount
<<
" bytes="
<<
s_buf
.
len
<<
endl
;
<<
" a_count="
<<
mypack
.
acount
<<
" bytes="
<<
s_buf
.
len
<<
endl
;
size_t
ret
=
udp
->
send
((
char
*
)
&
s_buf
.
data
,
s_buf
.
len
);
size_t
ret
=
udp
->
send
Bytes
((
char
*
)
&
s_buf
.
data
,
s_buf
.
len
);
if
(
ret
<
s_buf
.
len
)
if
(
ret
<
s_buf
.
len
)
cerr
<<
"(send): FAILED ret="
<<
ret
<<
" < sizeof="
<<
s_buf
.
len
<<
endl
;
cerr
<<
"(send): FAILED ret="
<<
ret
<<
" < sizeof="
<<
s_buf
.
len
<<
endl
;
}
}
}
}
catch
(
ost
::
Sock
Exception
&
e
)
catch
(
Poco
::
Net
::
Net
Exception
&
e
)
{
{
cerr
<<
"(send): "
<<
e
.
getString
()
<<
" ("
<<
addr
<<
")"
<<
endl
;
cerr
<<
"(send): "
<<
e
.
message
()
<<
" ("
<<
addr
<<
")"
<<
endl
;
}
}
catch
(
...
)
catch
(
...
)
{
{
...
...
extensions/lib/MTR.cc
View file @
6d6bd388
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
#include <cmath>
#include <cmath>
#include <vector>
#include <vector>
#include <iomanip>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <algorithm>
#include "modbus/ModbusRTUMaster.h"
#include "modbus/ModbusRTUMaster.h"
#include "modbus/ModbusHelpers.h"
#include "modbus/ModbusHelpers.h"
...
...
extensions/tests/MBSlaveTest/TestProc.cc
View file @
6d6bd388
#include <iomanip>
#include <iomanip>
#include <Poco/Net/NetException.h>
#include "Exceptions.h"
#include "Exceptions.h"
#include "TestProc.h"
#include "TestProc.h"
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
...
@@ -22,11 +23,10 @@ TestProc::TestProc( UniSetTypes::ObjectId id, xmlNode* confnode ):
...
@@ -22,11 +23,10 @@ TestProc::TestProc( UniSetTypes::ObjectId id, xmlNode* confnode ):
vmonit
(
undef
);
vmonit
(
undef
);
mbPort
=
2048
;
// getId();
mbPort
=
2048
;
// getId();
ost
::
InetAddress
mbIAddr
(
"localhost"
);
const
std
::
string
mbIAddr
(
"localhost"
);
try
try
{
{
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
mbslave
=
make_shared
<
ModbusTCPServerSlot
>
(
mbIAddr
,
mbPort
);
mbslave
=
make_shared
<
ModbusTCPServerSlot
>
(
mbIAddr
,
mbPort
);
mbslave
->
connectWriteSingleOutput
(
sigc
::
mem_fun
(
this
,
&
TestProc
::
writeOutputSingleRegister
)
);
mbslave
->
connectWriteSingleOutput
(
sigc
::
mem_fun
(
this
,
&
TestProc
::
writeOutputSingleRegister
)
);
loga
->
add
(
mbslave
->
log
()
);
loga
->
add
(
mbslave
->
log
()
);
...
@@ -35,10 +35,10 @@ TestProc::TestProc( UniSetTypes::ObjectId id, xmlNode* confnode ):
...
@@ -35,10 +35,10 @@ TestProc::TestProc( UniSetTypes::ObjectId id, xmlNode* confnode ):
mbthr
=
make_shared
<
ThreadCreator
<
TestProc
>
>
(
this
,
&
TestProc
::
mbThread
);
mbthr
=
make_shared
<
ThreadCreator
<
TestProc
>
>
(
this
,
&
TestProc
::
mbThread
);
myinfo
<<
myname
<<
"(init) ModbusSlave "
<<
mbIP
<<
":"
<<
mbPort
<<
endl
;
myinfo
<<
myname
<<
"(init) ModbusSlave "
<<
mbIP
<<
":"
<<
mbPort
<<
endl
;
}
}
catch
(
const
ost
::
Sock
Exception
&
e
)
catch
(
const
Poco
::
Net
::
Net
Exception
&
e
)
{
{
ostringstream
err
;
ostringstream
err
;
err
<<
myname
<<
"(init) Can`t create socket "
<<
mbIP
<<
":"
<<
mbPort
<<
" err: "
<<
e
.
getString
()
<<
endl
;
err
<<
myname
<<
"(init) Can`t create socket "
<<
mbIP
<<
":"
<<
mbPort
<<
" err: "
<<
e
.
message
()
<<
endl
;
mycrit
<<
err
.
str
()
<<
endl
;
mycrit
<<
err
.
str
()
<<
endl
;
throw
SystemError
(
err
.
str
());
throw
SystemError
(
err
.
str
());
}
}
...
...
extensions/tests/Makefile.am
View file @
6d6bd388
...
@@ -20,7 +20,7 @@ tests_with_sm_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/extensions
...
@@ -20,7 +20,7 @@ tests_with_sm_CPPFLAGS = -I$(top_builddir)/include -I$(top_builddir)/extensions
sm_perf_test_SOURCES
=
sm_perf_test.cc
sm_perf_test_SOURCES
=
sm_perf_test.cc
sm_perf_test_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(top_builddir)
/extensions/lib/libUniSet2Extensions.la
\
sm_perf_test_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(top_builddir)
/extensions/lib/libUniSet2Extensions.la
\
$(top_builddir)
/extensions/SharedMemory/libUniSet2SharedMemory.la
$(SIGC_LIBS)
$(COMCPP_LIBS)
$(top_builddir)
/extensions/SharedMemory/libUniSet2SharedMemory.la
$(SIGC_LIBS)
-lpthread
sm_perf_test_CPPFLAGS
=
-I
$(top_builddir)
/include
-I
$(top_builddir)
/extensions/include
\
sm_perf_test_CPPFLAGS
=
-I
$(top_builddir)
/include
-I
$(top_builddir)
/extensions/include
\
-I
$(top_builddir)
/extensions/SharedMemory
$(SIGC_CFLAGS)
$(COMCPP_CFLAGS)
-I
$(top_builddir)
/extensions/SharedMemory
$(SIGC_CFLAGS)
$(COMCPP_CFLAGS)
...
...
include/CallbackTimer.tcc
View file @
6d6bd388
...
@@ -164,7 +164,7 @@ timeout_t CallbackTimer<Caller>::getInterval( size_t id )
...
@@ -164,7 +164,7 @@ timeout_t CallbackTimer<Caller>::getInterval( size_t id )
if( li!=lst.end() )
if( li!=lst.end() )
return li->pt.getInterval();
return li->pt.getInterval();
return
TIMEOUT_INF
;
return
UniSetTimer::WaitUpTime
;
}
}
// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
template <class Caller>
template <class Caller>
...
@@ -174,7 +174,7 @@ timeout_t CallbackTimer<Caller>::getCurrent( size_t id )
...
@@ -174,7 +174,7 @@ timeout_t CallbackTimer<Caller>::getCurrent( size_t id )
if( li!=lst.end() )
if( li!=lst.end() )
return li->pt.getCurrent();
return li->pt.getCurrent();
return
TIMEOUT_INF
;
return
UniSetTimer::WaitUpTime
;
}
}
// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
# endif //CallbackTimer_TCC_H_
# endif //CallbackTimer_TCC_H_
include/ComPort.h
View file @
6d6bd388
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
#include <fcntl.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/ioctl.h>
#include <string>
#include <string>
#include
<cc++/thread.h>
// for use timeout_t
#include
"PassiveTimer.h"
// for use timeout_t
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
class
ComPort
class
ComPort
{
{
...
...
include/LogReader.h
View file @
6d6bd388
...
@@ -21,7 +21,6 @@
...
@@ -21,7 +21,6 @@
#include <memory>
#include <memory>
#include <queue>
#include <queue>
#include <vector>
#include <vector>
#include <cc++/socket.h>
#include "UTCPStream.h"
#include "UTCPStream.h"
#include "DebugStream.h"
#include "DebugStream.h"
#include "LogServerTypes.h"
#include "LogServerTypes.h"
...
@@ -42,11 +41,11 @@ class LogReader
...
@@ -42,11 +41,11 @@ class LogReader
std
::
string
logfilter
=
{
""
};
std
::
string
logfilter
=
{
""
};
};
};
void
sendCommand
(
const
std
::
string
&
addr
,
ost
::
tpport_
t
port
,
void
sendCommand
(
const
std
::
string
&
addr
,
in
t
port
,
std
::
vector
<
Command
>&
vcmd
,
bool
cmd_only
=
true
,
std
::
vector
<
Command
>&
vcmd
,
bool
cmd_only
=
true
,
bool
verbose
=
false
);
bool
verbose
=
false
);
void
readlogs
(
const
std
::
string
&
addr
,
ost
::
tpport_
t
port
,
LogServerTypes
::
Command
c
=
LogServerTypes
::
cmdNOP
,
const
std
::
string
logfilter
=
""
,
bool
verbose
=
false
);
void
readlogs
(
const
std
::
string
&
addr
,
in
t
port
,
LogServerTypes
::
Command
c
=
LogServerTypes
::
cmdNOP
,
const
std
::
string
logfilter
=
""
,
bool
verbose
=
false
);
bool
isConnection
()
const
;
bool
isConnection
()
const
;
...
@@ -84,8 +83,7 @@ class LogReader
...
@@ -84,8 +83,7 @@ class LogReader
protected
:
protected
:
void
connect
(
const
std
::
string
&
addr
,
ost
::
tpport_t
port
,
timeout_t
tout
=
TIMEOUT_INF
);
void
connect
(
const
std
::
string
&
addr
,
int
port
,
timeout_t
tout
=
UniSetTimer
::
WaitUpTime
);
void
connect
(
ost
::
InetAddress
addr
,
ost
::
tpport_t
port
,
timeout_t
tout
=
TIMEOUT_INF
);
void
disconnect
();
void
disconnect
();
void
logOnEvent
(
const
std
::
string
&
s
);
void
logOnEvent
(
const
std
::
string
&
s
);
void
sendCommand
(
LogServerTypes
::
lsMessage
&
msg
,
bool
verbose
=
false
);
void
sendCommand
(
LogServerTypes
::
lsMessage
&
msg
,
bool
verbose
=
false
);
...
@@ -97,7 +95,7 @@ class LogReader
...
@@ -97,7 +95,7 @@ class LogReader
private
:
private
:
std
::
shared_ptr
<
UTCPStream
>
tcp
;
std
::
shared_ptr
<
UTCPStream
>
tcp
;
std
::
string
iaddr
=
{
""
};
std
::
string
iaddr
=
{
""
};
ost
::
tpport_
t
port
=
{
0
};
in
t
port
=
{
0
};
bool
cmdonly
{
false
};
bool
cmdonly
{
false
};
unsigned
int
readcount
=
{
0
};
// количество циклов чтения
unsigned
int
readcount
=
{
0
};
// количество циклов чтения
...
...
include/LogServer.h
View file @
6d6bd388
...
@@ -21,7 +21,6 @@
...
@@ -21,7 +21,6 @@
#include <string>
#include <string>
#include <memory>
#include <memory>
#include <unordered_map>
#include <unordered_map>
#include <cc++/socket.h>
#include <ev++.h>
#include <ev++.h>
#include "Mutex.h"
#include "Mutex.h"
#include "UniXML.h"
#include "UniXML.h"
...
@@ -106,7 +105,7 @@ class LogServer:
...
@@ -106,7 +105,7 @@ class LogServer:
sessMaxCount
=
num
;
sessMaxCount
=
num
;
}
}
void
run
(
const
std
::
string
&
addr
,
ost
::
tpport_t
port
,
bool
thread
=
true
);
void
run
(
const
std
::
string
&
addr
,
Poco
::
UInt16
port
,
bool
thread
=
true
);
void
terminate
();
void
terminate
();
inline
bool
isRunning
()
inline
bool
isRunning
()
...
@@ -142,7 +141,7 @@ class LogServer:
...
@@ -142,7 +141,7 @@ class LogServer:
size_t
scount
=
{
0
};
size_t
scount
=
{
0
};
UniSetTypes
::
uniset_rwmutex
mutSList
;
UniSetTypes
::
uniset_rwmutex
mutSList
;
timeout_t
timeout
=
{
TIMEOUT_INF
};
timeout_t
timeout
=
{
UniSetTimer
::
WaitUpTime
};
timeout_t
cmdTimeout
=
{
2000
};
timeout_t
cmdTimeout
=
{
2000
};
Debug
::
type
sessLogLevel
=
{
Debug
::
NONE
};
Debug
::
type
sessLogLevel
=
{
Debug
::
NONE
};
size_t
sessMaxCount
=
{
10
};
size_t
sessMaxCount
=
{
10
};
...
@@ -164,7 +163,7 @@ class LogServer:
...
@@ -164,7 +163,7 @@ class LogServer:
std
::
string
myname
=
{
"LogServer"
};
std
::
string
myname
=
{
"LogServer"
};
std
::
string
addr
=
{
""
};
std
::
string
addr
=
{
""
};
ost
::
tpport_t
port
=
{
0
};
Poco
::
UInt16
port
=
{
0
};
std
::
atomic_bool
isrunning
=
{
false
};
std
::
atomic_bool
isrunning
=
{
false
};
};
};
...
...
include/LogSession.h
View file @
6d6bd388
...
@@ -20,7 +20,6 @@
...
@@ -20,7 +20,6 @@
#include <string>
#include <string>
#include <memory>
#include <memory>
#include <queue>
#include <queue>
#include <cc++/socket.h>
#include <ev++.h>
#include <ev++.h>
#include "Mutex.h"
#include "Mutex.h"
#include "DebugStream.h"
#include "DebugStream.h"
...
@@ -78,7 +77,7 @@ class LogSession
...
@@ -78,7 +77,7 @@ class LogSession
std
::
string
getShortInfo
();
std
::
string
getShortInfo
();
protected
:
protected
:
LogSession
(
ost
::
TCPSocket
&
server
);
//
LogSession( ost::TCPSocket& server );
void
event
(
ev
::
async
&
watcher
,
int
revents
);
void
event
(
ev
::
async
&
watcher
,
int
revents
);
void
callback
(
ev
::
io
&
watcher
,
int
revents
);
void
callback
(
ev
::
io
&
watcher
,
int
revents
);
...
...
include/MessageType.h
View file @
6d6bd388
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
#define MessageType_H_
#define MessageType_H_
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
#include <sys/time.h>
#include <sys/time.h>
#include <cstring>
#include <ostream>
#include <ostream>
#include "Configuration.h"
#include "Configuration.h"
#include "UniSetTypes.h"
#include "UniSetTypes.h"
...
...
include/Mutex.h
View file @
6d6bd388
...
@@ -25,7 +25,8 @@
...
@@ -25,7 +25,8 @@
#include <atomic>
#include <atomic>
#include <chrono>
#include <chrono>
#include <mutex>
#include <mutex>
#include <cc++/thread.h>
#include <Poco/RWLock.h>
#include "PassiveTimer.h"
// -----------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------
namespace
UniSetTypes
namespace
UniSetTypes
{
{
...
@@ -65,7 +66,7 @@ namespace UniSetTypes
...
@@ -65,7 +66,7 @@ namespace UniSetTypes
private
:
private
:
std
::
string
nm
;
std
::
string
nm
;
friend
class
uniset_rwmutex_lock
;
friend
class
uniset_rwmutex_lock
;
ost
::
ThreadLock
m
;
// это рекурсивный mutex (!)
std
::
unique_ptr
<
Poco
::
RWLock
>
m
;
};
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
uniset_rwmutex
&
m
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
uniset_rwmutex
&
m
);
...
...
include/PassiveTimer.h
View file @
6d6bd388
...
@@ -22,14 +22,17 @@
...
@@ -22,14 +22,17 @@
# define PASSIVETIMER_H_
# define PASSIVETIMER_H_
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
#include <signal.h>
#include <signal.h>
#include <cc++/socket.h>
#include <condition_variable>
#include <condition_variable>
#include <thread>
#include <thread>
#include <mutex>
#include <mutex>
#include <atomic>
#include <atomic>
#include <chrono>
#include <chrono>
#include <limits>
#include <Poco/Timespan.h>
#include "Mutex.h"
#include "Mutex.h"
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
typedef
Poco
::
Timespan
::
TimeDiff
timeout_t
;
//----------------------------------------------------------------------------------------
/*! \class UniSetTimer
/*! \class UniSetTimer
* \brief Базовый интерфейс пасивных таймеров
* \brief Базовый интерфейс пасивных таймеров
* \author Pavel Vainerman
* \author Pavel Vainerman
...
@@ -63,7 +66,7 @@ class UniSetTimer
...
@@ -63,7 +66,7 @@ class UniSetTimer
/*! Время засыпания, до момента пока не будет вызвана функция прерывания
/*! Время засыпания, до момента пока не будет вызвана функция прерывания
* terminate() или stop()
* terminate() или stop()
*/
*/
static
const
timeout_t
WaitUpTime
=
TIMEOUT_INF
;
static
const
timeout_t
WaitUpTime
=
std
::
numeric_limits
<
timeout_t
>::
max
()
;
/*! Минимальное время срабатывания. Задается в мсек. */
/*! Минимальное время срабатывания. Задается в мсек. */
static
const
timeout_t
MinQuantityTime
=
10
;
static
const
timeout_t
MinQuantityTime
=
10
;
...
@@ -141,39 +144,4 @@ class PassiveCondTimer:
...
@@ -141,39 +144,4 @@ class PassiveCondTimer:
std
::
condition_variable
cv_working
;
std
::
condition_variable
cv_working
;
};
};
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
/*! \class PassiveSigTimer
* \brief Пассивный таймер с режимом засыпания (ожидания)
* \author Pavel Vainerman
* \par
* Создан на основе сигнала (SIGALRM).
*/
class
PassiveSigTimer
:
public
PassiveTimer
{
public
:
PassiveSigTimer
();
virtual
~
PassiveSigTimer
();
virtual
bool
wait
(
timeout_t
t_msec
);
//throw(UniSetTypes::NotSetSignal);
virtual
void
terminate
();
protected
:
private
:
struct
itimerval
mtimer
=
{
{
0
,
0
},
{
0
,
0
}
};
pid_t
pid
=
{
0
};
// bool terminated;
volatile
sig_atomic_t
terminated
=
{
0
};
void
init
();
static
void
callalrm
(
int
signo
);
static
void
call
(
int
signo
,
siginfo_t
*
evp
,
void
*
ucontext
);
};
//----------------------------------------------------------------------------------------
# endif //PASSIVETIMER_H_
# endif //PASSIVETIMER_H_
include/TCPCheck.h
View file @
6d6bd388
...
@@ -18,8 +18,8 @@
...
@@ -18,8 +18,8 @@
#define _TCPCheck_H_
#define _TCPCheck_H_
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
#include <atomic>
#include <atomic>
#include <cc++/socket.h>
#include "ThreadCreator.h"
#include "ThreadCreator.h"
#include "PassiveTimer.h" // for timeout_t
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
/*! Вспомогательный класс для проверки связи, реализованный через создание потока,
/*! Вспомогательный класс для проверки связи, реализованный через создание потока,
чтобы при проверке не было "зависания" при недоступности адреса.
чтобы при проверке не было "зависания" при недоступности адреса.
...
...
include/ThreadCreator.h
View file @
6d6bd388
...
@@ -22,8 +22,10 @@
...
@@ -22,8 +22,10 @@
#ifndef ThreadCreator_h_
#ifndef ThreadCreator_h_
#define ThreadCreator_h_
#define ThreadCreator_h_
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
#include <
cc++/t
hread.h>
#include <
Poco/T
hread.h>
#include <sys/resource.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <unistd.h>
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
/*! \class ThreadCreator
/*! \class ThreadCreator
* Шаблон для создания потоков с указанием функции вызова.
* Шаблон для создания потоков с указанием функции вызова.
...
@@ -81,7 +83,7 @@
...
@@ -81,7 +83,7 @@
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
template
<
class
ThreadMaster
>
template
<
class
ThreadMaster
>
class
ThreadCreator
:
class
ThreadCreator
:
public
ost
::
PosixThread
public
Poco
::
Runnable
{
{
public
:
public
:
...
@@ -95,27 +97,34 @@ class ThreadCreator:
...
@@ -95,27 +97,34 @@ class ThreadCreator:
inline
pid_t
getTID
()
const
inline
pid_t
getTID
()
const
{
{
return
pid
;
return
thr
.
tid
()
;
}
}
/*! \return 0 - sucess */
/*! \return 0 - sucess */
int
setPriority
(
int
prior
);
void
setPriority
(
Poco
::
Thread
::
Priority
prior
);
/*! \return < 0 - fail */
/*! \return < 0 - fail */
int
getPriority
()
const
;
Poco
::
Thread
::
Priority
getPriority
()
const
;
void
stop
();
void
stop
();
void
start
();
inline
void
setName
(
const
std
::
string
&
name
)
inline
bool
isRunning
(
)
{
{
ost
::
PosixThread
::
setName
(
name
.
c_str
()
);
return
thr
.
isRunning
(
);
}
}
inline
void
join
()
{
thr
.
join
();
}
/*
inline void setCancel( ost::Thread::Cancel mode )
inline void setCancel( ost::Thread::Cancel mode )
{
{
ost::PosixThread::setCancel(mode);
ost::PosixThread::setCancel(mode);
}
}
*/
inline
void
setFinalAction
(
ThreadMaster
*
m
,
Action
a
)
inline
void
setFinalAction
(
ThreadMaster
*
m
,
Action
a
)
{
{
finm
=
m
;
finm
=
m
;
...
@@ -144,6 +153,8 @@ class ThreadCreator:
...
@@ -144,6 +153,8 @@ class ThreadCreator:
(
initm
->*
initact
)();
(
initm
->*
initact
)();
}
}
virtual
void
terminate
(){}
private
:
private
:
ThreadCreator
();
ThreadCreator
();
...
@@ -157,6 +168,8 @@ class ThreadCreator:
...
@@ -157,6 +168,8 @@ class ThreadCreator:
ThreadMaster
*
initm
;
ThreadMaster
*
initm
;
Action
initact
;
Action
initact
;
Poco
::
Thread
thr
;
};
};
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
...
@@ -188,6 +201,12 @@ void ThreadCreator<ThreadMaster>::stop()
...
@@ -188,6 +201,12 @@ void ThreadCreator<ThreadMaster>::stop()
}
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
template
<
class
ThreadMaster
>
template
<
class
ThreadMaster
>
void
ThreadCreator
<
ThreadMaster
>::
start
()
{
thr
.
start
(
*
this
);
}
//----------------------------------------------------------------------------------------
template
<
class
ThreadMaster
>
ThreadCreator
<
ThreadMaster
>::
ThreadCreator
()
:
ThreadCreator
<
ThreadMaster
>::
ThreadCreator
()
:
pid
(
0
),
pid
(
0
),
m
(
0
),
m
(
0
),
...
@@ -205,15 +224,15 @@ ThreadCreator<ThreadMaster>::~ThreadCreator()
...
@@ -205,15 +224,15 @@ ThreadCreator<ThreadMaster>::~ThreadCreator()
}
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
template
<
class
ThreadMaster
>
template
<
class
ThreadMaster
>
int
ThreadCreator
<
ThreadMaster
>::
setPriority
(
int
prior
)
void
ThreadCreator
<
ThreadMaster
>::
setPriority
(
Poco
::
Thread
::
Priority
prior
)
{
{
return
setpriority
(
PRIO_PROCESS
,
pid
,
prior
);
return
thr
.
setPriority
(
prior
);
}
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
template
<
class
ThreadMaster
>
template
<
class
ThreadMaster
>
int
ThreadCreator
<
ThreadMaster
>::
getPriority
()
const
Poco
::
Thread
::
Priority
ThreadCreator
<
ThreadMaster
>::
getPriority
()
const
{
{
return
getpriority
(
PRIO_PROCESS
,
pid
);
return
thr
.
getPriority
(
);
}
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
#endif // ThreadCreator_h_
#endif // ThreadCreator_h_
include/UDPCore.h
View file @
6d6bd388
...
@@ -2,67 +2,67 @@
...
@@ -2,67 +2,67 @@
#ifndef UDPReceiveU_H_
#ifndef UDPReceiveU_H_
#define UDPReceiveU_H_
#define UDPReceiveU_H_
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
#include <
cc++/s
ocket.h>
#include <
Poco/Net/DatagramS
ocket.h>
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
// различные классы-обёртки, чтобы достучаться до "сырого сокета" и других функций
// различные классы-обёртки, чтобы достучаться до "сырого сокета" и других функций
// необходимых при использовании с libev..
// необходимых при использовании с libev..
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
class
UDPSocketU
:
class
UDPSocketU
:
public
ost
::
UDP
Socket
public
Poco
::
Net
::
Datagram
Socket
{
{
public
:
public
:
UDPSocketU
(
const
ost
::
IPV4Address
&
bind
,
ost
::
tpport_t
port
)
:
UDPSocketU
(
const
std
::
string
&
bind
,
int
port
)
:
ost
::
UDPSocket
(
bind
,
port
)
Poco
::
Net
::
DatagramSocket
(
Poco
::
Net
::
SocketAddress
(
bind
,
port
),
true
)
{}
{}
virtual
~
UDPSocketU
()
{}
virtual
~
UDPSocketU
()
{}
inline
SOCKET
getSocket
()
const
inline
int
getSocket
()
const
{
{
return
ost
::
UDPSocket
::
so
;
return
Poco
::
Net
::
DatagramSocket
::
sockfd
()
;
}
}
};
};
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
class
UDPReceiveU
:
class
UDPReceiveU
:
public
ost
::
UDPReceive
public
Poco
::
Net
::
DatagramSocket
{
{
public
:
public
:
UDPReceiveU
(
const
ost
::
IPV4Address
&
bind
,
ost
::
tpport_
t
port
)
:
UDPReceiveU
(
const
std
::
string
&
bind
,
in
t
port
)
:
ost
::
UDPReceive
(
bind
,
port
)
Poco
::
Net
::
DatagramSocket
(
Poco
::
Net
::
SocketAddress
(
bind
,
port
),
true
)
{}
{}
virtual
~
UDPReceiveU
()
{}
virtual
~
UDPReceiveU
()
{}
inline
SOCKET
getSocket
()
inline
int
getSocket
()
{
{
return
ost
::
UDPReceive
::
so
;
return
Poco
::
Net
::
DatagramSocket
::
sockfd
()
;
}
}
inline
void
setCompletion
(
bool
set
)
inline
void
setCompletion
(
bool
set
)
{
{
ost
::
UDPReceive
::
setCompletion
(
set
);
Poco
::
Net
::
DatagramSocket
::
setBlocking
(
set
);
}
}
};
};
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
class
UDPDuplexU
:
class
UDPDuplexU
:
public
ost
::
UDPDuplex
public
Poco
::
Net
::
DatagramSocket
{
{
public
:
public
:
UDPDuplexU
(
const
ost
::
IPV4Address
&
bind
,
ost
::
tpport_
t
port
)
:
UDPDuplexU
(
const
std
::
string
&
bind
,
in
t
port
)
:
ost
::
UDPDuplex
(
bind
,
port
)
Poco
::
Net
::
DatagramSocket
(
Poco
::
Net
::
SocketAddress
(
bind
,
port
),
true
)
{}
{}
virtual
~
UDPDuplexU
()
{}
virtual
~
UDPDuplexU
()
{}
SOCKET
getReceiveSocket
()
int
getReceiveSocket
()
{
{
return
ost
::
UDPReceive
::
so
;
return
Poco
::
Net
::
DatagramSocket
::
sockfd
();
;
}
}
void
setReceiveCompletion
(
bool
set
)
void
setReceiveCompletion
(
bool
set
)
{
{
ost
::
UDPReceive
::
setCompletion
(
set
);
Poco
::
Net
::
DatagramSocket
::
setBlocking
(
set
);
}
}
};
};
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
...
...
include/USocket.h
View file @
6d6bd388
...
@@ -2,10 +2,11 @@
...
@@ -2,10 +2,11 @@
#ifndef USocket_H_
#ifndef USocket_H_
#define USocket_H_
#define USocket_H_
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
#include <cc++/socket.h>
#include <Poco/Net/Socket.h>
#include "PassiveTimer.h" // fot timeout_t
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
class
USocket
:
class
USocket
:
public
os
t
::
Socket
public
Poco
::
Ne
t
::
Socket
{
{
public
:
public
:
...
...
include/UTCPCore.h
View file @
6d6bd388
...
@@ -2,8 +2,9 @@
...
@@ -2,8 +2,9 @@
#ifndef UTCPCore_H_
#ifndef UTCPCore_H_
#define UTCPCore_H_
#define UTCPCore_H_
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
#include <cc++/thread.h> // ..for timeout_t
#include <string>
#include <string>
#include <cstring> // for std::memcpy
#include "PassiveTimer.h" // ..for timeout_t
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
namespace
UTCPCore
namespace
UTCPCore
{
{
...
@@ -29,7 +30,7 @@ namespace UTCPCore
...
@@ -29,7 +30,7 @@ namespace UTCPCore
return
;
return
;
data
=
new
unsigned
char
[
nbytes
];
data
=
new
unsigned
char
[
nbytes
];
memcpy
(
data
,
bytes
,
nbytes
);
std
::
memcpy
(
data
,
bytes
,
nbytes
);
}
}
Buffer
(
const
std
::
string
&
s
)
Buffer
(
const
std
::
string
&
s
)
...
@@ -41,7 +42,7 @@ namespace UTCPCore
...
@@ -41,7 +42,7 @@ namespace UTCPCore
return
;
return
;
data
=
new
unsigned
char
[
len
];
data
=
new
unsigned
char
[
len
];
memcpy
(
data
,
s
.
data
(),
len
);
std
::
memcpy
(
data
,
s
.
data
(),
len
);
}
}
virtual
~
Buffer
()
virtual
~
Buffer
()
...
...
include/UTCPSocket.h
View file @
6d6bd388
...
@@ -3,19 +3,18 @@
...
@@ -3,19 +3,18 @@
#define UTCPSocket_H_
#define UTCPSocket_H_
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
#include <string>
#include <string>
#include <cc++/socket.h>
#include <Poco/Net/RawSocket.h>
#include "PassiveTimer.h" // for timeout_t
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
class
UTCPSocket
:
class
UTCPSocket
:
public
ost
::
TCP
Socket
public
Poco
::
Net
::
Raw
Socket
{
{
public
:
public
:
// dup and accept...raw socket
// dup and accept...raw socket
UTCPSocket
(
int
sock
);
UTCPSocket
(
int
sock
);
// hname = "host:port"
UTCPSocket
(
const
std
::
string
&
host
,
int
port
);
UTCPSocket
(
const
std
::
string
&
hname
,
unsigned
backlog
=
5
,
unsigned
mss
=
536
);
UTCPSocket
(
const
ost
::
IPV4Address
&
bind
,
ost
::
tpport_t
port
,
unsigned
backlog
=
5
,
unsigned
mss
=
536
);
virtual
~
UTCPSocket
();
virtual
~
UTCPSocket
();
...
@@ -31,11 +30,6 @@ class UTCPSocket:
...
@@ -31,11 +30,6 @@ class UTCPSocket:
*/
*/
bool
setNoDelay
(
bool
enable
);
bool
setNoDelay
(
bool
enable
);
void
setCompletion
(
bool
set
)
{
ost
::
TCPSocket
::
setCompletion
(
set
);
}
int
getSocket
();
int
getSocket
();
// --------------------------------------------------------------------
// --------------------------------------------------------------------
...
...
include/UTCPStream.h
View file @
6d6bd388
...
@@ -18,21 +18,22 @@
...
@@ -18,21 +18,22 @@
#define UTCPStream_H_
#define UTCPStream_H_
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
#include <string>
#include <string>
#include <cc++/socket.h>
#include <Poco/Net/SocketStream.h>
#include "PassiveTimer.h" // for timeout_t
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
/*! Специальная "обёртка" над ost::TCPStream, устанавливающая ещё и параметры KeepAlive,
/*! Специальная "обёртка" над ost::TCPStream, устанавливающая ещё и параметры KeepAlive,
* для открытого сокета.
* для открытого сокета.
* \note Правда это linux-only
* \note Правда это linux-only
*/
*/
class
UTCPStream
:
class
UTCPStream
:
public
ost
::
TCPStream
public
Poco
::
Net
::
StreamSocket
{
{
public
:
public
:
UTCPStream
();
UTCPStream
();
virtual
~
UTCPStream
();
virtual
~
UTCPStream
();
void
create
(
const
std
::
string
&
hname
,
int
port
,
bool
throwflag
=
false
,
timeout_t
timer
=
0
);
void
create
(
const
std
::
string
&
hname
,
int
port
,
timeout_t
tout
=
100
0
);
// set keepalive params
// set keepalive params
// return true if OK
// return true if OK
...
...
include/UniSetActivator.h
View file @
6d6bd388
...
@@ -25,7 +25,6 @@
...
@@ -25,7 +25,6 @@
#include <deque>
#include <deque>
#include <memory>
#include <memory>
#include <omniORB4/CORBA.h>
#include <omniORB4/CORBA.h>
#include <cc++/socket.h>
#include "UniSetTypes.h"
#include "UniSetTypes.h"
#include "UniSetObject.h"
#include "UniSetObject.h"
#include "UniSetManager.h"
#include "UniSetManager.h"
...
...
include/UniSetObject.h
View file @
6d6bd388
...
@@ -175,7 +175,7 @@ class UniSetObject:
...
@@ -175,7 +175,7 @@ class UniSetObject:
void
setID
(
UniSetTypes
::
ObjectId
id
);
void
setID
(
UniSetTypes
::
ObjectId
id
);
/*! установить приоритет для потока обработки сообщений (если позволяют права и система) */
/*! установить приоритет для потока обработки сообщений (если позволяют права и система) */
void
setThreadPriority
(
int
p
);
void
setThreadPriority
(
Poco
::
Thread
::
Priority
p
);
/*! установка размера очереди сообщений */
/*! установка размера очереди сообщений */
void
setMaxSizeOfMessageQueue
(
size_t
s
);
void
setMaxSizeOfMessageQueue
(
size_t
s
);
...
...
include/VMonitor.h
View file @
6d6bd388
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
#include <list>
#include <list>
#include <ostream>
#include <ostream>
#include <unordered_map>
#include <unordered_map>
#include <Poco/Types.h>
#include "UniSetTypes.h"
#include "UniSetTypes.h"
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
#ifndef VMON_DEF_FUNC
#ifndef VMON_DEF_FUNC
...
@@ -136,6 +137,7 @@ class VMonitor
...
@@ -136,6 +137,7 @@ class VMonitor
VMON_DEF_FUNC
(
bool
);
VMON_DEF_FUNC
(
bool
);
VMON_DEF_FUNC
(
float
);
VMON_DEF_FUNC
(
float
);
VMON_DEF_FUNC
(
double
);
VMON_DEF_FUNC
(
double
);
VMON_DEF_FUNC
(
Poco
::
Int64
);
// <--- for timeout_t
// VMON_DEF_FUNC(UniSetTypes::ObjectId); // <--- long
// VMON_DEF_FUNC(UniSetTypes::ObjectId); // <--- long
void
add
(
const
std
::
string
&
name
,
const
std
::
string
&
v
);
void
add
(
const
std
::
string
&
name
,
const
std
::
string
&
v
);
...
@@ -156,6 +158,7 @@ class VMonitor
...
@@ -156,6 +158,7 @@ class VMonitor
VMON_DEF_MAP
(
bool
);
VMON_DEF_MAP
(
bool
);
VMON_DEF_MAP
(
float
);
VMON_DEF_MAP
(
float
);
VMON_DEF_MAP
(
double
);
VMON_DEF_MAP
(
double
);
std
::
unordered_map
<
const
Poco
::
Int64
*
,
const
std
::
string
>
m_Int64
;
VMON_DEF_MAP3
(
std
::
string
,
string
);
VMON_DEF_MAP3
(
std
::
string
,
string
);
};
};
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
...
...
include/modbus/ModbusTCPCore.h
View file @
6d6bd388
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
#define ModbusTCPCore_H_
#define ModbusTCPCore_H_
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
#include <queue>
#include <queue>
#include <cc++/socket.h>
#include "ModbusRTUErrors.h"
#include "ModbusRTUErrors.h"
#include "UTCPStream.h"
#include "UTCPStream.h"
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
...
...
include/modbus/ModbusTCPMaster.h
View file @
6d6bd388
...
@@ -4,10 +4,10 @@
...
@@ -4,10 +4,10 @@
#include <memory>
#include <memory>
#include <string>
#include <string>
#include <queue>
#include <queue>
#include <cc++/socket.h>
#include <Poco/Net/SocketStream.h>
#include "UTCPStream.h"
#include "ModbusTypes.h"
#include "ModbusTypes.h"
#include "ModbusClient.h"
#include "ModbusClient.h"
#include "UTCPStream.h"
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
/*! Modbus TCP master interface */
/*! Modbus TCP master interface */
class
ModbusTCPMaster
:
class
ModbusTCPMaster
:
...
@@ -19,7 +19,7 @@ class ModbusTCPMaster:
...
@@ -19,7 +19,7 @@ class ModbusTCPMaster:
virtual
~
ModbusTCPMaster
();
virtual
~
ModbusTCPMaster
();
void
connect
(
const
std
::
string
&
addr
,
int
port
);
void
connect
(
const
std
::
string
&
addr
,
int
port
);
void
connect
(
ost
::
InetAddress
addr
,
int
port
);
void
connect
(
const
Poco
::
Net
::
SocketAddress
&
addr
,
int
_
port
);
void
disconnect
();
void
disconnect
();
void
forceDisconnect
();
void
forceDisconnect
();
bool
isConnection
()
const
;
bool
isConnection
()
const
;
...
...
include/modbus/ModbusTCPServer.h
View file @
6d6bd388
...
@@ -4,7 +4,6 @@
...
@@ -4,7 +4,6 @@
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
#include <string>
#include <string>
#include <queue>
#include <queue>
#include <cc++/socket.h>
#include <ev++.h>
#include <ev++.h>
#include <sigc++/sigc++.h>
#include <sigc++/sigc++.h>
#include "Mutex.h"
#include "Mutex.h"
...
@@ -29,7 +28,7 @@ class ModbusTCPServer:
...
@@ -29,7 +28,7 @@ class ModbusTCPServer:
public
ModbusServer
public
ModbusServer
{
{
public
:
public
:
ModbusTCPServer
(
ost
::
InetAddress
&
ia
,
int
port
=
502
);
ModbusTCPServer
(
const
std
::
string
&
addr
,
int
port
=
502
);
virtual
~
ModbusTCPServer
();
virtual
~
ModbusTCPServer
();
/*! Запуск сервера
/*! Запуск сервера
...
@@ -79,11 +78,11 @@ class ModbusTCPServer:
...
@@ -79,11 +78,11 @@ class ModbusTCPServer:
void
getSessions
(
Sessions
&
lst
);
void
getSessions
(
Sessions
&
lst
);
inline
ost
::
InetAddress
getInetAddress
()
inline
std
::
string
getInetAddress
()
{
{
return
iaddr
;
return
iaddr
;
}
}
inline
ost
::
tpport_
t
getInetPort
()
inline
in
t
getInetPort
()
{
{
return
port
;
return
port
;
}
}
...
@@ -133,8 +132,8 @@ class ModbusTCPServer:
...
@@ -133,8 +132,8 @@ class ModbusTCPServer:
/*! set timeout for receive data */
/*! set timeout for receive data */
virtual
void
setChannelTimeout
(
timeout_t
msec
)
override
{};
virtual
void
setChannelTimeout
(
timeout_t
msec
)
override
{};
ost
::
tpport_
t
port
=
{
0
};
in
t
port
=
{
0
};
ost
::
InetAddress
iaddr
;
std
::
string
iaddr
;
std
::
string
myname
;
std
::
string
myname
;
std
::
queue
<
unsigned
char
>
qrecv
;
std
::
queue
<
unsigned
char
>
qrecv
;
ModbusRTU
::
ADUHeader
curQueryHeader
;
ModbusRTU
::
ADUHeader
curQueryHeader
;
...
@@ -157,7 +156,7 @@ class ModbusTCPServer:
...
@@ -157,7 +156,7 @@ class ModbusTCPServer:
const
std
::
unordered_set
<
ModbusRTU
::
ModbusAddr
>*
vmbaddr
=
{
nullptr
};
const
std
::
unordered_set
<
ModbusRTU
::
ModbusAddr
>*
vmbaddr
=
{
nullptr
};
TimerSignal
m_timer_signal
;
TimerSignal
m_timer_signal
;
timeout_t
tmTime_msec
=
{
TIMEOUT_INF
};
// время по умолчанию для таймера (TimerSignal)
timeout_t
tmTime_msec
=
{
UniSetTimer
::
WaitUpTime
};
// время по умолчанию для таймера (TimerSignal)
double
tmTime
=
{
0
.
0
};
double
tmTime
=
{
0
.
0
};
PassiveTimer
ptWait
;
PassiveTimer
ptWait
;
...
...
include/modbus/ModbusTCPServerSlot.h
View file @
6d6bd388
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
#define ModbusTCPServerSlot_H_
#define ModbusTCPServerSlot_H_
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
#include <string>
#include <string>
#include <cc++/socket.h>
#include "ModbusTCPServer.h"
#include "ModbusTCPServer.h"
#include "ModbusServerSlot.h"
#include "ModbusServerSlot.h"
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
...
@@ -13,7 +12,7 @@ class ModbusTCPServerSlot:
...
@@ -13,7 +12,7 @@ class ModbusTCPServerSlot:
public
ModbusTCPServer
public
ModbusTCPServer
{
{
public
:
public
:
ModbusTCPServerSlot
(
ost
::
InetAddress
&
ia
,
int
port
=
502
);
ModbusTCPServerSlot
(
const
std
::
string
&
ia
,
int
port
=
502
);
virtual
~
ModbusTCPServerSlot
();
virtual
~
ModbusTCPServerSlot
();
virtual
void
sigterm
(
int
signo
);
virtual
void
sigterm
(
int
signo
);
...
...
python/lib/pyUniSet/UModbus.cc
View file @
6d6bd388
...
@@ -102,12 +102,10 @@ void UModbus::connect( const string& _ip, int _port )throw(UException)
...
@@ -102,12 +102,10 @@ void UModbus::connect( const string& _ip, int _port )throw(UException)
ip
=
_ip
;
ip
=
_ip
;
port
=
_port
;
port
=
_port
;
ost
::
InetAddress
ia
(
_ip
.
c_str
());
try
try
{
{
// cerr << "************** Connect: " << ia << ":" << port << " ip:" << ip << endl;
mb
->
connect
(
ip
,
port
);
mb
->
connect
(
ia
,
port
);
}
}
catch
(
ModbusRTU
::
mbException
&
ex
)
catch
(
ModbusRTU
::
mbException
&
ex
)
{
{
...
...
src/Communications/Modbus/ModbusTCPCore.cc
View file @
6d6bd388
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
#include <Poco/Net/NetException.h>
#include "modbus/ModbusTCPCore.h"
#include "modbus/ModbusTCPCore.h"
#include "Exceptions.h"
#include "Exceptions.h"
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
...
@@ -26,7 +27,7 @@ using namespace ModbusRTU;
...
@@ -26,7 +27,7 @@ using namespace ModbusRTU;
size_t
ModbusTCPCore
::
readNextData
(
UTCPStream
*
tcp
,
size_t
ModbusTCPCore
::
readNextData
(
UTCPStream
*
tcp
,
std
::
queue
<
unsigned
char
>&
qrecv
,
size_t
max
,
timeout_t
t
)
std
::
queue
<
unsigned
char
>&
qrecv
,
size_t
max
,
timeout_t
t
)
{
{
if
(
!
tcp
||
!
tcp
->
isConnected
()
)
if
(
!
tcp
)
// || !tcp->available
() )
return
0
;
return
0
;
size_t
i
=
0
;
size_t
i
=
0
;
...
@@ -57,14 +58,11 @@ size_t ModbusTCPCore::readNextData(UTCPStream* tcp,
...
@@ -57,14 +58,11 @@ size_t ModbusTCPCore::readNextData(UTCPStream* tcp,
if
(
l
==
0
)
if
(
l
==
0
)
commfail
=
true
;
commfail
=
true
;
}
}
catch
(
ost
::
SockException
&
e
)
catch
(
Poco
::
Net
::
NetException
&
e
)
{
if
(
e
.
getSocketError
()
==
ost
::
Socket
::
errConnectFailed
||
e
.
getSocketError
()
==
ost
::
Socket
::
errConnectInvalid
)
{
{
#warning Разобраться с Poco::Net::NetException
commfail
=
true
;
commfail
=
true
;
}
}
}
delete
[]
buf
;
delete
[]
buf
;
#else
#else
...
@@ -107,7 +105,7 @@ size_t ModbusTCPCore::getNextData(UTCPStream* tcp,
...
@@ -107,7 +105,7 @@ size_t ModbusTCPCore::getNextData(UTCPStream* tcp,
{
{
if
(
qrecv
.
empty
()
||
qrecv
.
size
()
<
len
)
if
(
qrecv
.
empty
()
||
qrecv
.
size
()
<
len
)
{
{
if
(
!
tcp
||
!
tcp
->
isConnected
()
)
if
(
!
tcp
)
// || !tcp->available
() )
return
0
;
return
0
;
if
(
len
<=
0
)
if
(
len
<=
0
)
...
@@ -227,7 +225,7 @@ size_t ModbusTCPCore::getDataFD( int fd, std::queue<unsigned char>& qrecv,
...
@@ -227,7 +225,7 @@ size_t ModbusTCPCore::getDataFD( int fd, std::queue<unsigned char>& qrecv,
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
mbErrCode
ModbusTCPCore
::
sendData
(
UTCPStream
*
tcp
,
unsigned
char
*
buf
,
size_t
len
,
timeout_t
t
)
mbErrCode
ModbusTCPCore
::
sendData
(
UTCPStream
*
tcp
,
unsigned
char
*
buf
,
size_t
len
,
timeout_t
t
)
{
{
if
(
!
tcp
||
!
tcp
->
isConnected
()
)
if
(
!
tcp
)
// || !tcp->available
() )
return
erTimeOut
;
return
erTimeOut
;
try
try
...
@@ -237,7 +235,7 @@ mbErrCode ModbusTCPCore::sendData( UTCPStream* tcp, unsigned char* buf, size_t l
...
@@ -237,7 +235,7 @@ mbErrCode ModbusTCPCore::sendData( UTCPStream* tcp, unsigned char* buf, size_t l
if
(
l
==
len
)
if
(
l
==
len
)
return
erNoError
;
return
erNoError
;
}
}
catch
(
ost
::
Sock
Exception
&
e
)
catch
(
Poco
::
Net
::
Net
Exception
&
e
)
{
{
// cerr << "(send): " << e.getString() << ": " << e.getSystemErrorString() << endl;
// cerr << "(send): " << e.getString() << ": " << e.getSystemErrorString() << endl;
}
}
...
...
src/Communications/Modbus/ModbusTCPMaster.cc
View file @
6d6bd388
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#include <errno.h>
#include <errno.h>
#include <iostream>
#include <iostream>
#include <sstream>
#include <sstream>
#include <Poco/Net/NetException.h>
#include "Exceptions.h"
#include "Exceptions.h"
#include "modbus/ModbusTCPMaster.h"
#include "modbus/ModbusTCPMaster.h"
#include "modbus/ModbusTCPCore.h"
#include "modbus/ModbusTCPCore.h"
...
@@ -25,6 +26,7 @@
...
@@ -25,6 +26,7 @@
using
namespace
std
;
using
namespace
std
;
using
namespace
ModbusRTU
;
using
namespace
ModbusRTU
;
using
namespace
UniSetTypes
;
using
namespace
UniSetTypes
;
using
namespace
Poco
;
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
ModbusTCPMaster
::
ModbusTCPMaster
()
:
ModbusTCPMaster
::
ModbusTCPMaster
()
:
tcp
(
nullptr
),
tcp
(
nullptr
),
...
@@ -59,12 +61,13 @@ void ModbusTCPMaster::setChannelTimeout( timeout_t msec )
...
@@ -59,12 +61,13 @@ void ModbusTCPMaster::setChannelTimeout( timeout_t msec )
if
(
!
tcp
)
if
(
!
tcp
)
return
;
return
;
timeout_t
old
=
tcp
->
getTimeout
();
Poco
::
Timespan
old
=
tcp
->
getReceiveTimeout
();;
//timeout_t old = tcp->getReceiveTimeout();
if
(
old
==
msec
)
if
(
old
==
msec
)
return
;
return
;
tcp
->
setTimeout
(
msec
);
tcp
->
set
Receive
Timeout
(
msec
);
int
oldKeepAlive
=
keepAliveTimeout
;
int
oldKeepAlive
=
keepAliveTimeout
;
keepAliveTimeout
=
(
msec
>
1000
?
msec
/
1000
:
1
);
keepAliveTimeout
=
(
msec
>
1000
?
msec
/
1000
:
1
);
...
@@ -112,13 +115,14 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
...
@@ -112,13 +115,14 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
assert
(
timeout
);
assert
(
timeout
);
ptTimeout
.
setTiming
(
timeout
);
ptTimeout
.
setTiming
(
timeout
);
tcp
->
setTimeout
(
timeout
);
tcp
->
set
Receive
Timeout
(
timeout
);
msg
.
makeHead
(
++
nTransaction
,
crcNoCheckit
);
msg
.
makeHead
(
++
nTransaction
,
crcNoCheckit
);
for
(
size_t
i
=
0
;
i
<
2
;
i
++
)
for
(
size_t
i
=
0
;
i
<
2
;
i
++
)
{
{
if
(
tcp
->
isPending
(
ost
::
Socket
::
pendingOutput
,
timeout
)
)
//if( tcp->isPending(ost::Socket::pendingOutput, timeout) )
if
(
tcp
->
poll
(
timeout
,
Poco
::
Net
::
Socket
::
SELECT_READ
)
)
{
{
mbErrCode
res
=
send
(
msg
);
mbErrCode
res
=
send
(
msg
);
...
@@ -162,9 +166,9 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
...
@@ -162,9 +166,9 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
while
(
!
qrecv
.
empty
()
)
while
(
!
qrecv
.
empty
()
)
qrecv
.
pop
();
qrecv
.
pop
();
tcp
->
sync
();
//
tcp->sync();
if
(
tcp
->
isPending
(
ost
::
Socket
::
pendingInput
,
timeout
)
)
if
(
tcp
->
poll
(
timeout
,
Poco
::
Net
::
Socket
::
SELECT_READ
)
)
{
{
size_t
ret
=
0
;
size_t
ret
=
0
;
...
@@ -185,7 +189,9 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
...
@@ -185,7 +189,9 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
if
(
ret
<
sizeof
(
reply
.
aduhead
)
)
if
(
ret
<
sizeof
(
reply
.
aduhead
)
)
{
{
ost
::
tpport_t
port
;
#warning Разобраться с обработкой ошибки связи
#if 0
int port;
if( dlog->is_warn() )
if( dlog->is_warn() )
{
{
...
@@ -206,7 +212,7 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
...
@@ -206,7 +212,7 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
dlog->warn() << "(query): tcp error: " << e.getString() << endl;
dlog->warn() << "(query): tcp error: " << e.getString() << endl;
}
}
}
}
#endif
cleanInputStream
();
cleanInputStream
();
tcp
->
forceDisconnect
();
tcp
->
forceDisconnect
();
return
erTimeOut
;
// return erHardwareError;
return
erTimeOut
;
// return erHardwareError;
...
@@ -260,7 +266,7 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
...
@@ -260,7 +266,7 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
// при штатном обмене..лучше дождаться конца "посылки"..
// при штатном обмене..лучше дождаться конца "посылки"..
// поэтому применяем disconnect(), а не forceDisconnect()
// поэтому применяем disconnect(), а не forceDisconnect()
// (с учётом выставленной опции setLinger(true))
// (с учётом выставленной опции setLinger(true))
tcp
->
disconnect
();
// tcp->forceDisconnect
();
tcp
->
shutdown
();
}
}
return
res
;
return
res
;
...
@@ -297,15 +303,15 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
...
@@ -297,15 +303,15 @@ mbErrCode ModbusTCPMaster::query( ModbusAddr addr, ModbusMessage& msg,
tcp
->
forceDisconnect
();
tcp
->
forceDisconnect
();
}
}
catch
(
const
Exception
&
ex
)
catch
(
const
UniSetTypes
::
Exception
&
ex
)
{
{
if
(
dlog
->
is_warn
()
)
if
(
dlog
->
is_warn
()
)
dlog
->
warn
()
<<
"(query): "
<<
ex
<<
endl
;
dlog
->
warn
()
<<
"(query): "
<<
ex
<<
endl
;
}
}
catch
(
const
ost
::
Sock
Exception
&
e
)
catch
(
const
Poco
::
Net
::
Net
Exception
&
e
)
{
{
if
(
dlog
->
is_warn
()
)
if
(
dlog
->
is_warn
()
)
dlog
->
warn
()
<<
"(query): tcp error: "
<<
e
.
getString
()
<<
endl
;
dlog
->
warn
()
<<
"(query): tcp error: "
<<
e
.
displayText
()
<<
endl
;
}
}
catch
(
const
std
::
exception
&
e
)
catch
(
const
std
::
exception
&
e
)
{
{
...
@@ -351,10 +357,10 @@ bool ModbusTCPMaster::checkConnection( const std::string& ip, int port, int time
...
@@ -351,10 +357,10 @@ bool ModbusTCPMaster::checkConnection( const std::string& ip, int port, int time
// Проверяем просто попыткой создать соединение..
// Проверяем просто попыткой создать соединение..
UTCPStream
t
;
UTCPStream
t
;
t
.
create
(
ip
,
port
,
t
rue
,
t
imeout_msec
);
t
.
create
(
ip
,
port
,
timeout_msec
);
t
.
setKeepAliveParams
(
(
timeout_msec
>
1000
?
timeout_msec
/
1000
:
1
),
1
,
1
);
t
.
setKeepAliveParams
(
(
timeout_msec
>
1000
?
timeout_msec
/
1000
:
1
),
1
,
1
);
t
.
setNoDelay
(
true
);
t
.
setNoDelay
(
true
);
t
.
disconnect
();
t
.
shutdown
();
return
true
;
return
true
;
}
}
catch
(...)
catch
(...)
...
@@ -378,8 +384,8 @@ void ModbusTCPMaster::reconnect()
...
@@ -378,8 +384,8 @@ void ModbusTCPMaster::reconnect()
try
try
{
{
tcp
=
make_shared
<
UTCPStream
>
();
tcp
=
make_shared
<
UTCPStream
>
();
tcp
->
create
(
iaddr
,
port
,
true
,
500
);
tcp
->
create
(
iaddr
,
port
,
500
);
tcp
->
setTimeout
(
replyTimeOut_ms
);
tcp
->
set
Receive
Timeout
(
replyTimeOut_ms
);
tcp
->
setKeepAliveParams
((
replyTimeOut_ms
>
1000
?
replyTimeOut_ms
/
1000
:
1
));
tcp
->
setKeepAliveParams
((
replyTimeOut_ms
>
1000
?
replyTimeOut_ms
/
1000
:
1
));
tcp
->
setNoDelay
(
true
);
tcp
->
setNoDelay
(
true
);
}
}
...
@@ -405,11 +411,11 @@ void ModbusTCPMaster::reconnect()
...
@@ -405,11 +411,11 @@ void ModbusTCPMaster::reconnect()
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
ModbusTCPMaster
::
connect
(
const
std
::
string
&
addr
,
int
_port
)
void
ModbusTCPMaster
::
connect
(
const
std
::
string
&
addr
,
int
_port
)
{
{
ost
::
InetAddress
ia
(
addr
.
c_str
()
);
Net
::
SocketAddress
sa
(
addr
,
_port
);
connect
(
i
a
,
_port
);
connect
(
s
a
,
_port
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
ModbusTCPMaster
::
connect
(
ost
::
InetAddress
addr
,
int
_port
)
void
ModbusTCPMaster
::
connect
(
const
Poco
::
Net
::
SocketAddress
&
addr
,
int
_port
)
{
{
if
(
tcp
)
if
(
tcp
)
{
{
...
@@ -417,25 +423,18 @@ void ModbusTCPMaster::connect( ost::InetAddress addr, int _port )
...
@@ -417,25 +423,18 @@ void ModbusTCPMaster::connect( ost::InetAddress addr, int _port )
tcp
.
reset
();
tcp
.
reset
();
}
}
// if( !tcp )
iaddr
=
addr
.
host
().
toString
();
// {
ostringstream
s
;
s
<<
addr
;
iaddr
=
s
.
str
();
port
=
_port
;
port
=
_port
;
if
(
dlog
->
is_info
()
)
if
(
dlog
->
is_info
()
)
dlog
->
info
()
<<
"(ModbusTCPMaster): connect to "
<<
iaddr
<<
":"
<<
port
<<
endl
;
dlog
->
info
()
<<
"(ModbusTCPMaster): connect to "
<<
iaddr
<<
":"
<<
port
<<
endl
;
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
try
try
{
{
tcp
=
make_shared
<
UTCPStream
>
();
tcp
=
make_shared
<
UTCPStream
>
();
tcp
->
create
(
iaddr
,
port
,
true
,
500
);
tcp
->
c
onnect
(
addr
,
500
);
// tcp->c
reate(iaddr, port, true, 500);
tcp
->
setTimeout
(
replyTimeOut_ms
);
tcp
->
set
ReceiveTimeout
(
replyTimeOut_ms
);
// tcp->set
Timeout(replyTimeOut_ms);
tcp
->
setKeepAliveParams
((
replyTimeOut_ms
>
1000
?
replyTimeOut_ms
/
1000
:
1
));
tcp
->
setKeepAlive
(
true
);
// tcp->setKeepAlive
Params((replyTimeOut_ms > 1000 ? replyTimeOut_ms / 1000 : 1));
tcp
->
setNoDelay
(
true
);
tcp
->
setNoDelay
(
true
);
}
}
catch
(
const
std
::
exception
&
e
)
catch
(
const
std
::
exception
&
e
)
...
@@ -444,7 +443,7 @@ void ModbusTCPMaster::connect( ost::InetAddress addr, int _port )
...
@@ -444,7 +443,7 @@ void ModbusTCPMaster::connect( ost::InetAddress addr, int _port )
{
{
ostringstream
s
;
ostringstream
s
;
s
<<
"(ModbusTCPMaster): connection "
<<
s
.
str
()
<<
" error: "
<<
e
.
what
();
s
<<
"(ModbusTCPMaster): connection "
<<
s
.
str
()
<<
" error: "
<<
e
.
what
();
dlog
->
crit
()
<<
s
.
str
()
<<
std
::
endl
;
dlog
->
crit
()
<<
iaddr
<<
std
::
endl
;
}
}
}
}
catch
(
...
)
catch
(
...
)
...
@@ -468,7 +467,7 @@ void ModbusTCPMaster::disconnect()
...
@@ -468,7 +467,7 @@ void ModbusTCPMaster::disconnect()
if
(
!
tcp
)
if
(
!
tcp
)
return
;
return
;
tcp
->
disconnect
();
tcp
->
shutdown
();
tcp
.
reset
();
tcp
.
reset
();
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
...
@@ -486,6 +485,7 @@ void ModbusTCPMaster::forceDisconnect()
...
@@ -486,6 +485,7 @@ void ModbusTCPMaster::forceDisconnect()
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
bool
ModbusTCPMaster
::
isConnection
()
const
bool
ModbusTCPMaster
::
isConnection
()
const
{
{
return
tcp
&&
tcp
->
isConnected
();
#warning Разобраться с isConnected
return
(
tcp
!=
nullptr
);
/* && tcp->isConnected(); */
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
src/Communications/Modbus/ModbusTCPServer.cc
View file @
6d6bd388
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
#include <iostream>
#include <iostream>
#include <sstream>
#include <sstream>
#include <Poco/Net/NetException.h>
#include "Exceptions.h"
#include "Exceptions.h"
#include "modbus/ModbusTCPServer.h"
#include "modbus/ModbusTCPServer.h"
#include "modbus/ModbusTCPCore.h"
#include "modbus/ModbusTCPCore.h"
...
@@ -24,7 +25,7 @@ using namespace std;
...
@@ -24,7 +25,7 @@ using namespace std;
using
namespace
ModbusRTU
;
using
namespace
ModbusRTU
;
using
namespace
UniSetTypes
;
using
namespace
UniSetTypes
;
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
ModbusTCPServer
::
ModbusTCPServer
(
ost
::
InetAddress
&
ia
,
int
_port
)
:
ModbusTCPServer
::
ModbusTCPServer
(
const
std
::
string
&
ia
,
int
_port
)
:
port
(
_port
),
port
(
_port
),
iaddr
(
ia
),
iaddr
(
ia
),
myname
(
""
),
myname
(
""
),
...
@@ -48,7 +49,7 @@ ModbusTCPServer::ModbusTCPServer( ost::InetAddress& ia, int _port ):
...
@@ -48,7 +49,7 @@ ModbusTCPServer::ModbusTCPServer( ost::InetAddress& ia, int _port ):
ModbusTCPServer
::~
ModbusTCPServer
()
ModbusTCPServer
::~
ModbusTCPServer
()
{
{
}
}
// -------------------------------------------------------------------------
// --------------------
w
-----------------------------------------------------
void
ModbusTCPServer
::
setMaxSessions
(
size_t
num
)
void
ModbusTCPServer
::
setMaxSessions
(
size_t
num
)
{
{
if
(
num
<
sessCount
)
if
(
num
<
sessCount
)
...
@@ -90,13 +91,11 @@ bool ModbusTCPServer::isActive() const
...
@@ -90,13 +91,11 @@ bool ModbusTCPServer::isActive() const
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
ModbusTCPServer
::
evprepare
()
void
ModbusTCPServer
::
evprepare
()
{
{
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
try
try
{
{
sock
=
make_shared
<
UTCPSocket
>
(
iaddr
,
port
);
sock
=
make_shared
<
UTCPSocket
>
(
iaddr
,
port
);
}
}
catch
(
const
ost
::
Sock
Exception
&
ex
)
catch
(
const
Poco
::
Net
::
Net
Exception
&
ex
)
{
{
ostringstream
err
;
ostringstream
err
;
err
<<
"(ModbusTCPServer::evprepare): connect "
<<
iaddr
<<
":"
<<
port
<<
" err: "
<<
ex
.
what
();
err
<<
"(ModbusTCPServer::evprepare): connect "
<<
iaddr
<<
":"
<<
port
<<
" err: "
<<
ex
.
what
();
...
@@ -111,14 +110,14 @@ void ModbusTCPServer::evprepare()
...
@@ -111,14 +110,14 @@ void ModbusTCPServer::evprepare()
throw
SystemError
(
err
.
str
());
throw
SystemError
(
err
.
str
());
}
}
sock
->
set
Completion
(
false
);
sock
->
set
Blocking
(
false
);
io
.
set
(
loop
);
io
.
set
(
loop
);
io
.
start
(
sock
->
getSocket
(),
ev
::
READ
);
io
.
start
(
sock
->
getSocket
(),
ev
::
READ
);
ioTimer
.
set
(
loop
);
ioTimer
.
set
(
loop
);
if
(
tmTime_msec
!=
TIMEOUT_INF
)
if
(
tmTime_msec
!=
UniSetTimer
::
WaitUpTime
)
ioTimer
.
start
(
tmTime
);
ioTimer
.
start
(
tmTime
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
...
@@ -189,7 +188,7 @@ void ModbusTCPServer::setTimer( timeout_t msec )
...
@@ -189,7 +188,7 @@ void ModbusTCPServer::setTimer( timeout_t msec )
{
{
tmTime_msec
=
msec
;
tmTime_msec
=
msec
;
if
(
msec
==
TIMEOUT_INF
)
if
(
msec
==
UniSetTimer
::
WaitUpTime
)
{
{
tmTime
=
0
;
tmTime
=
0
;
...
@@ -228,7 +227,7 @@ void ModbusTCPServer::ioAccept(ev::io& watcher, int revents)
...
@@ -228,7 +227,7 @@ void ModbusTCPServer::ioAccept(ev::io& watcher, int revents)
if
(
dlog
->
is_crit
()
)
if
(
dlog
->
is_crit
()
)
dlog
->
crit
()
<<
myname
<<
"(ModbusTCPServer::ioAccept): terminate work.."
<<
endl
;
dlog
->
crit
()
<<
myname
<<
"(ModbusTCPServer::ioAccept): terminate work.."
<<
endl
;
sock
->
reject
();
sock
->
close
();
return
;
return
;
}
}
...
@@ -237,7 +236,7 @@ void ModbusTCPServer::ioAccept(ev::io& watcher, int revents)
...
@@ -237,7 +236,7 @@ void ModbusTCPServer::ioAccept(ev::io& watcher, int revents)
if
(
dlog
->
is_crit
()
)
if
(
dlog
->
is_crit
()
)
dlog
->
crit
()
<<
myname
<<
"(ModbusTCPServer::ioAccept): session limit("
<<
maxSessions
<<
")"
<<
endl
;
dlog
->
crit
()
<<
myname
<<
"(ModbusTCPServer::ioAccept): session limit("
<<
maxSessions
<<
")"
<<
endl
;
sock
->
reject
();
sock
->
close
();
return
;
return
;
}
}
...
...
src/Communications/Modbus/ModbusTCPServerSlot.cc
View file @
6d6bd388
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
using
namespace
ModbusRTU
;
using
namespace
ModbusRTU
;
using
namespace
std
;
using
namespace
std
;
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
ModbusTCPServerSlot
::
ModbusTCPServerSlot
(
ost
::
InetAddress
&
ia
,
int
port
)
:
ModbusTCPServerSlot
::
ModbusTCPServerSlot
(
const
string
&
ia
,
int
port
)
:
ModbusTCPServer
(
ia
,
port
)
ModbusTCPServer
(
ia
,
port
)
{
{
}
}
...
...
src/Communications/Modbus/ModbusTCPSession.cc
View file @
6d6bd388
...
@@ -15,11 +15,12 @@
...
@@ -15,11 +15,12 @@
*/
*/
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
#include <iostream>
#include <iostream>
#include <sstream>
#include <string>
#include <string>
#include <fcntl.h>
#include <fcntl.h>
#include <errno.h>
#include <errno.h>
#include <cstring>
#include <cstring>
#include <
cc++/socket
.h>
#include <
Poco/Net/NetException
.h>
#include "modbus/ModbusTCPSession.h"
#include "modbus/ModbusTCPSession.h"
#include "modbus/ModbusTCPCore.h"
#include "modbus/ModbusTCPCore.h"
#include "UniSetTypes.h"
#include "UniSetTypes.h"
...
@@ -51,13 +52,12 @@ ModbusTCPSession::ModbusTCPSession( int sfd, const std::unordered_set<ModbusAddr
...
@@ -51,13 +52,12 @@ ModbusTCPSession::ModbusTCPSession( int sfd, const std::unordered_set<ModbusAddr
try
try
{
{
sock
=
make_shared
<
USocket
>
(
sfd
);
sock
=
make_shared
<
USocket
>
(
sfd
);
ost
::
tpport_t
p
;
// если стремиться к "оптимизации по скорости"
// если стремиться к "оптимизации по скорости"
// то getpeername "медленная" операция и может стоит от неё отказаться.
// то getpeername "медленная" операция и может стоит от неё отказаться.
ost
::
InetAddress
iaddr
=
sock
->
getIPV4Peer
(
&
p
);
Poco
::
Net
::
SocketAddress
iaddr
=
sock
->
peerAddress
(
);
if
(
!
iaddr
.
isInetAddress
()
)
if
(
iaddr
.
host
().
toString
().
empty
()
)
{
{
ostringstream
err
;
ostringstream
err
;
err
<<
"(ModbusTCPSession): unknonwn ip(0.0.0.0) client disconnected?!"
;
err
<<
"(ModbusTCPSession): unknonwn ip(0.0.0.0) client disconnected?!"
;
...
@@ -69,24 +69,21 @@ ModbusTCPSession::ModbusTCPSession( int sfd, const std::unordered_set<ModbusAddr
...
@@ -69,24 +69,21 @@ ModbusTCPSession::ModbusTCPSession( int sfd, const std::unordered_set<ModbusAddr
throw
SystemError
(
err
.
str
());
throw
SystemError
(
err
.
str
());
}
}
caddr
=
string
(
iaddr
.
getHostname
()
);
caddr
=
iaddr
.
host
().
toString
(
);
ostringstream
s
;
ostringstream
s
;
s
<<
iaddr
<<
":"
<<
p
;
s
<<
caddr
<<
":"
<<
iaddr
.
port
()
;
peername
=
s
.
str
();
peername
=
s
.
str
();
}
}
catch
(
const
ost
::
Sock
Exception
&
ex
)
catch
(
const
Poco
::
Net
::
Net
Exception
&
ex
)
{
{
ostringstream
err
;
err
<<
ex
.
what
();
if
(
dlog
->
is_crit
()
)
if
(
dlog
->
is_crit
()
)
dlog
->
crit
()
<<
"(ModbusTCPSession): err: "
<<
e
rr
.
str
()
<<
endl
;
dlog
->
crit
()
<<
"(ModbusTCPSession): err: "
<<
e
x
.
displayText
()
<<
endl
;
sock
.
reset
();
sock
.
reset
();
throw
SystemError
(
e
rr
.
str
());
throw
SystemError
(
e
x
.
message
());
}
}
sock
->
set
Completion
(
false
);
// fcntl(sfd, F_SETFL, fcntl(sfd, F_GETFL, 0) | O_NONBLOCK);
sock
->
set
Blocking
(
false
);
// fcntl(sfd, F_SETFL, fcntl(sfd, F_GETFL, 0) | O_NONBLOCK);
setCRCNoCheckit
(
true
);
setCRCNoCheckit
(
true
);
timeout_t
tout
=
timeout
/
1000
;
timeout_t
tout
=
timeout
/
1000
;
...
...
src/Communications/TCP/TCPCheck.cc
View file @
6d6bd388
...
@@ -52,7 +52,7 @@ bool TCPCheck::check( const std::string& _ip, int _port, timeout_t tout, timeout
...
@@ -52,7 +52,7 @@ bool TCPCheck::check( const std::string& _ip, int _port, timeout_t tout, timeout
setResult
(
false
);
setResult
(
false
);
ThreadCreator
<
TCPCheck
>
t
(
this
,
&
TCPCheck
::
check_thread
);
ThreadCreator
<
TCPCheck
>
t
(
this
,
&
TCPCheck
::
check_thread
);
t
.
setCancel
(
ost
::
Thread
::
cancelDeferred
);
//
t.setCancel(ost::Thread::cancelDeferred);
t
.
start
();
t
.
start
();
PassiveTimer
pt
(
tout
);
PassiveTimer
pt
(
tout
);
...
@@ -72,14 +72,13 @@ void TCPCheck::check_thread()
...
@@ -72,14 +72,13 @@ void TCPCheck::check_thread()
try
try
{
{
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
UTCPStream
t
;
UTCPStream
t
;
t
.
create
(
ip
,
port
,
t
rue
,
t
out_msec
);
t
.
create
(
ip
,
port
,
tout_msec
);
t
.
setKeepAliveParams
(
(
tout_msec
>
1000
?
tout_msec
/
1000
:
1
)
);
t
.
setKeepAliveParams
(
(
tout_msec
>
1000
?
tout_msec
/
1000
:
1
)
);
setResult
(
true
);
setResult
(
true
);
t
.
disconnect
();
t
.
shutdown
();
}
}
catch
(
ost
::
Exception
&
e
)
{}
catch
(
...
)
{}
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
bool
TCPCheck
::
ping
(
const
std
::
string
&
_ip
,
timeout_t
tout
,
timeout_t
sleep_msec
,
const
std
::
string
&
_ping_args
)
bool
TCPCheck
::
ping
(
const
std
::
string
&
_ip
,
timeout_t
tout
,
timeout_t
sleep_msec
,
const
std
::
string
&
_ping_args
)
...
@@ -91,7 +90,6 @@ bool TCPCheck::ping( const std::string& _ip, timeout_t tout, timeout_t sleep_mse
...
@@ -91,7 +90,6 @@ bool TCPCheck::ping( const std::string& _ip, timeout_t tout, timeout_t sleep_mse
setResult
(
false
);
setResult
(
false
);
ThreadCreator
<
TCPCheck
>
t
(
this
,
&
TCPCheck
::
ping_thread
);
ThreadCreator
<
TCPCheck
>
t
(
this
,
&
TCPCheck
::
ping_thread
);
t
.
setCancel
(
ost
::
Thread
::
cancelDeferred
);
t
.
start
();
t
.
start
();
PassiveTimer
pt
(
tout
);
PassiveTimer
pt
(
tout
);
...
...
src/Communications/TCP/USocket.cc
View file @
6d6bd388
...
@@ -5,30 +5,31 @@ using namespace std;
...
@@ -5,30 +5,31 @@ using namespace std;
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
USocket
::~
USocket
()
USocket
::~
USocket
()
{
{
endSocket
();
close
();
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
USocket
::
USocket
(
int
sock
)
:
USocket
::
USocket
(
int
sock
)
Socket
(
accept
(
sock
,
NULL
,
NULL
)
)
// Socket(sock
)
{
{
init
();
init
();
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
bool
USocket
::
setKeepAliveParams
(
timeout_t
timeout_sec
,
int
keepcnt
,
int
keepintvl
)
bool
USocket
::
setKeepAliveParams
(
timeout_t
timeout_sec
,
int
keepcnt
,
int
keepintvl
)
{
{
return
UTCPCore
::
setKeepAliveParams
(
so
,
timeout_sec
,
keepcnt
,
keepintvl
);
return
UTCPCore
::
setKeepAliveParams
(
getSocket
()
,
timeout_sec
,
keepcnt
,
keepintvl
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
int
USocket
::
getSocket
()
int
USocket
::
getSocket
()
{
{
return
so
;
return
Socket
::
sockfd
()
;
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
USocket
::
init
(
bool
throwflag
)
void
USocket
::
init
(
bool
throwflag
)
{
{
setError
(
throwflag
);
//
setError(throwflag);
setKeepAlive
(
true
);
setKeepAlive
(
true
);
setLinger
(
true
);
Socket
::
setLinger
(
true
,
1
);
//setLinger(true);
setKeepAliveParams
();
setKeepAliveParams
();
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
src/Communications/TCP/UTCPSocket.cc
View file @
6d6bd388
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
#include <fcntl.h>
#include <fcntl.h>
#include <errno.h>
#include <errno.h>
#include <cstring>
#include <cstring>
#include <cc++/socket.h>
#include "UTCPSocket.h"
#include "UTCPSocket.h"
#include "PassiveTimer.h"
#include "PassiveTimer.h"
#include "UniSetTypes.h"
#include "UniSetTypes.h"
...
@@ -13,13 +12,16 @@ using namespace std;
...
@@ -13,13 +12,16 @@ using namespace std;
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
UTCPSocket
::~
UTCPSocket
()
UTCPSocket
::~
UTCPSocket
()
{
{
endSocket
();
close
();
//endSocket();
// shutdown(so, SHUT_RDWR);
// shutdown(so, SHUT_RDWR);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
UTCPSocket
::
UTCPSocket
(
int
sock
)
:
UTCPSocket
::
UTCPSocket
(
int
sock
)
:
TCPSocket
(
NULL
)
Poco
::
Net
::
RawSocket
(
sock
)
{
{
/*
struct sockaddr_in client_addr;
struct sockaddr_in client_addr;
socklen_t client_len = sizeof(client_addr);
socklen_t client_len = sizeof(client_addr);
...
@@ -33,51 +35,47 @@ UTCPSocket::UTCPSocket( int sock ):
...
@@ -33,51 +35,47 @@ UTCPSocket::UTCPSocket( int sock ):
}
}
Socket::state = CONNECTED;
Socket::state = CONNECTED;
*/
init
();
init
();
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
UTCPSocket
::
UTCPSocket
(
const
std
::
string
&
hname
,
unsigned
backlog
,
unsigned
mss
)
:
UTCPSocket
::
UTCPSocket
(
const
string
&
host
,
int
port
)
:
TCPSocket
(
hname
.
c_str
(),
backlog
,
mss
)
Poco
::
Net
::
RawSocket
(
Poco
::
Net
::
SocketAddress
(
host
,
port
),
true
)
{
init
();
}
// -------------------------------------------------------------------------
UTCPSocket
::
UTCPSocket
(
const
ost
::
IPV4Address
&
bind
,
ost
::
tpport_t
port
,
unsigned
backlog
,
unsigned
mss
)
:
TCPSocket
(
bind
,
port
,
backlog
,
mss
)
{
{
init
();
init
();
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
bool
UTCPSocket
::
setKeepAliveParams
(
timeout_t
timeout_sec
,
int
keepcnt
,
int
keepintvl
)
bool
UTCPSocket
::
setKeepAliveParams
(
timeout_t
timeout_sec
,
int
keepcnt
,
int
keepintvl
)
{
{
return
UTCPCore
::
setKeepAliveParams
(
so
,
timeout_sec
,
keepcnt
,
keepintvl
);
return
UTCPCore
::
setKeepAliveParams
(
Poco
::
Net
::
RawSocket
::
sockfd
()
,
timeout_sec
,
keepcnt
,
keepintvl
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
bool
UTCPSocket
::
setNoDelay
(
bool
enable
)
bool
UTCPSocket
::
setNoDelay
(
bool
enable
)
{
{
return
(
TCPSocket
::
setNoDelay
(
enable
)
==
0
);
Poco
::
Net
::
RawSocket
::
setNoDelay
(
enable
);
return
(
Poco
::
Net
::
RawSocket
::
getNoDelay
()
==
enable
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
int
UTCPSocket
::
getSocket
()
int
UTCPSocket
::
getSocket
()
{
{
return
so
;
return
Poco
::
Net
::
RawSocket
::
sockfd
()
;
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
UTCPSocket
::
init
(
bool
throwflag
)
void
UTCPSocket
::
init
(
bool
throwflag
)
{
{
setError
(
throwflag
);
//
setError(throwflag);
setKeepAlive
(
true
);
Poco
::
Net
::
RawSocket
::
setKeepAlive
(
true
);
setLinger
(
true
);
Poco
::
Net
::
RawSocket
::
setLinger
(
true
,
1
);
setKeepAliveParams
();
setKeepAliveParams
();
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
ssize_t
UTCPSocket
::
writeData
(
const
void
*
buf
,
size_t
len
,
timeout_t
t
)
ssize_t
UTCPSocket
::
writeData
(
const
void
*
buf
,
size_t
len
,
timeout_t
t
)
{
{
return
TCPSocket
::
writeData
(
buf
,
len
,
t
);
return
Poco
::
Net
::
RawSocket
::
sendBytes
(
buf
,
len
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
ssize_t
UTCPSocket
::
readData
(
void
*
buf
,
size_t
len
,
char
separator
,
timeout_t
t
)
ssize_t
UTCPSocket
::
readData
(
void
*
buf
,
size_t
len
,
char
separator
,
timeout_t
t
)
{
{
return
TCPSocket
::
readData
(
buf
,
len
,
separator
,
t
);
return
Poco
::
Net
::
RawSocket
::
receiveBytes
(
buf
,
len
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
src/Communications/TCP/UTCPStream.cc
View file @
6d6bd388
...
@@ -19,7 +19,6 @@
...
@@ -19,7 +19,6 @@
#include <fcntl.h>
#include <fcntl.h>
#include <errno.h>
#include <errno.h>
#include <cstring>
#include <cstring>
#include <cc++/socket.h>
#include "UTCPStream.h"
#include "UTCPStream.h"
#include "PassiveTimer.h"
#include "PassiveTimer.h"
#include "UniSetTypes.h"
#include "UniSetTypes.h"
...
@@ -32,64 +31,66 @@ UTCPStream::~UTCPStream()
...
@@ -32,64 +31,66 @@ UTCPStream::~UTCPStream()
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
UTCPStream
::
UTCPStream
()
:
UTCPStream
::
UTCPStream
()
TCPStream
(
ost
::
Socket
::
IPV4
,
true
)
{
{
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
bool
UTCPStream
::
setKeepAliveParams
(
timeout_t
timeout_sec
,
int
keepcnt
,
int
keepintvl
)
bool
UTCPStream
::
setKeepAliveParams
(
timeout_t
timeout_sec
,
int
keepcnt
,
int
keepintvl
)
{
{
return
UTCPCore
::
setKeepAliveParams
(
so
,
timeout_sec
,
keepcnt
,
keepintvl
);
return
UTCPCore
::
setKeepAliveParams
(
Poco
::
Net
::
StreamSocket
::
sockfd
()
,
timeout_sec
,
keepcnt
,
keepintvl
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
bool
UTCPStream
::
isSetLinger
()
const
bool
UTCPStream
::
isSetLinger
()
const
{
{
return
Socket
::
flags
.
linger
;
bool
on
;
int
sec
;
Poco
::
Net
::
StreamSocket
::
getLinger
(
on
,
sec
);
return
on
;
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
UTCPStream
::
forceDisconnect
()
void
UTCPStream
::
forceDisconnect
()
{
{
bool
f
=
Socket
::
flags
.
linger
;
bool
on
;
Socket
::
flags
.
linger
=
false
;
int
sec
;
disconnect
();
Poco
::
Net
::
StreamSocket
::
getLinger
(
on
,
sec
);
Socket
::
flags
.
linger
=
f
;
setLinger
(
false
,
0
);
shutdown
();
Poco
::
Net
::
StreamSocket
::
setLinger
(
on
,
sec
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
bool
UTCPStream
::
setNoDelay
(
bool
enable
)
bool
UTCPStream
::
setNoDelay
(
bool
enable
)
{
{
return
(
TCPStream
::
setNoDelay
(
enable
)
==
0
);
Poco
::
Net
::
StreamSocket
::
setNoDelay
(
enable
);
return
(
Poco
::
Net
::
StreamSocket
::
getNoDelay
()
==
enable
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
ssize_t
UTCPStream
::
writeData
(
const
void
*
buf
,
size_t
len
,
timeout_t
t
)
ssize_t
UTCPStream
::
writeData
(
const
void
*
buf
,
size_t
len
,
timeout_t
t
)
{
{
return
TCPStream
::
writeData
(
buf
,
len
,
t
);
return
Poco
::
Net
::
StreamSocket
::
sendBytes
(
buf
,
len
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
ssize_t
UTCPStream
::
readData
(
void
*
buf
,
size_t
len
,
char
separator
,
timeout_t
t
)
ssize_t
UTCPStream
::
readData
(
void
*
buf
,
size_t
len
,
char
separator
,
timeout_t
t
)
{
{
return
TCPStream
::
readData
(
buf
,
len
,
separator
,
t
);
return
Poco
::
Net
::
StreamSocket
::
receiveBytes
(
buf
,
len
);
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
int
UTCPStream
::
getSocket
()
const
int
UTCPStream
::
getSocket
()
const
{
{
return
TCPStream
::
so
;
return
Poco
::
Net
::
StreamSocket
::
sockfd
()
;
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
timeout_t
UTCPStream
::
getTimeout
()
const
timeout_t
UTCPStream
::
getTimeout
()
const
{
{
return
TCPStream
::
timeout
;
auto
tm
=
Poco
::
Net
::
StreamSocket
::
getReceiveTimeout
();
return
tm
.
microseconds
();
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
UTCPStream
::
create
(
const
std
::
string
&
hname
,
int
port
,
bool
throwflag
,
timeout_t
t
)
void
UTCPStream
::
create
(
const
std
::
string
&
hname
,
int
port
,
timeout_t
tou
t
)
{
{
family
=
ost
::
Socket
::
IPV4
;
Poco
::
Net
::
SocketAddress
sa
(
hname
,
port
);
timeout
=
t
;
connect
(
sa
,
tout
);
unsigned
mss
=
536
;
setError
(
throwflag
);
ost
::
IPV4Host
h
(
hname
.
c_str
());
connect
(
h
,
port
,
mss
);
setKeepAlive
(
true
);
setKeepAlive
(
true
);
setLinger
(
true
);
Poco
::
Net
::
StreamSocket
::
setLinger
(
true
,
1
);
setKeepAliveParams
();
setKeepAliveParams
();
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
src/Log/LogReader.cc
View file @
6d6bd388
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
#include <string.h>
#include <string.h>
#include <errno.h>
#include <errno.h>
#include <Poco/Net/NetException.h>
#include <iostream>
#include <iostream>
#include <sstream>
#include <sstream>
#include "Exceptions.h"
#include "Exceptions.h"
...
@@ -56,17 +57,10 @@ DebugStream::StreamEvent_Signal LogReader::signal_stream_event()
...
@@ -56,17 +57,10 @@ DebugStream::StreamEvent_Signal LogReader::signal_stream_event()
return
m_logsig
;
return
m_logsig
;
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
LogReader
::
connect
(
const
std
::
string
&
addr
,
ost
::
tpport_t
_port
,
timeout_t
msec
)
void
LogReader
::
connect
(
const
std
::
string
&
_addr
,
int
_port
,
timeout_t
msec
)
{
ost
::
InetAddress
ia
(
addr
.
c_str
());
connect
(
ia
,
_port
,
msec
);
}
// -------------------------------------------------------------------------
void
LogReader
::
connect
(
ost
::
InetAddress
addr
,
ost
::
tpport_t
_port
,
timeout_t
msec
)
{
{
if
(
tcp
)
if
(
tcp
)
{
{
(
*
tcp
.
get
())
<<
endl
;
disconnect
();
disconnect
();
tcp
=
0
;
tcp
=
0
;
}
}
...
@@ -74,21 +68,17 @@ void LogReader::connect( ost::InetAddress addr, ost::tpport_t _port, timeout_t m
...
@@ -74,21 +68,17 @@ void LogReader::connect( ost::InetAddress addr, ost::tpport_t _port, timeout_t m
// if( !tcp )
// if( !tcp )
// {
// {
ostringstream
s
;
iaddr
=
_addr
;
s
<<
addr
;
iaddr
=
s
.
str
();
port
=
_port
;
port
=
_port
;
if
(
rlog
.
is_info
()
)
if
(
rlog
.
is_info
()
)
rlog
.
info
()
<<
"(LogReader): connect to "
<<
iaddr
<<
":"
<<
port
<<
endl
;
rlog
.
info
()
<<
"(LogReader): connect to "
<<
iaddr
<<
":"
<<
port
<<
endl
;
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
try
try
{
{
tcp
=
make_shared
<
UTCPStream
>
();
tcp
=
make_shared
<
UTCPStream
>
();
tcp
->
create
(
iaddr
,
port
,
true
,
500
);
tcp
->
create
(
iaddr
,
port
,
500
);
tcp
->
setTimeout
(
msec
);
tcp
->
set
Receive
Timeout
(
msec
);
tcp
->
setKeepAlive
(
true
);
tcp
->
setKeepAlive
(
true
);
}
}
catch
(
const
std
::
exception
&
e
)
catch
(
const
std
::
exception
&
e
)
...
@@ -123,16 +113,16 @@ void LogReader::disconnect()
...
@@ -123,16 +113,16 @@ void LogReader::disconnect()
if
(
rlog
.
is_info
()
)
if
(
rlog
.
is_info
()
)
rlog
.
info
()
<<
iaddr
<<
"(LogReader): disconnect."
<<
endl
;
rlog
.
info
()
<<
iaddr
<<
"(LogReader): disconnect."
<<
endl
;
tcp
->
disconnect
();
tcp
->
shutdown
();
tcp
=
0
;
tcp
=
0
;
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
bool
LogReader
::
isConnection
()
const
bool
LogReader
::
isConnection
()
const
{
{
return
tcp
&&
tcp
->
isConnected
();
return
(
tcp
!=
nullptr
);
/* && tcp->isConnected(); */
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
LogReader
::
sendCommand
(
const
std
::
string
&
_addr
,
ost
::
tpport_
t
_port
,
std
::
vector
<
Command
>&
vcmd
,
bool
cmd_only
,
bool
verbose
)
void
LogReader
::
sendCommand
(
const
std
::
string
&
_addr
,
in
t
_port
,
std
::
vector
<
Command
>&
vcmd
,
bool
cmd_only
,
bool
verbose
)
{
{
if
(
vcmd
.
empty
()
)
if
(
vcmd
.
empty
()
)
return
;
return
;
...
@@ -143,7 +133,7 @@ void LogReader::sendCommand( const std::string& _addr, ost::tpport_t _port, std:
...
@@ -143,7 +133,7 @@ void LogReader::sendCommand( const std::string& _addr, ost::tpport_t _port, std:
rlog
.
addLevel
(
Debug
::
ANY
);
rlog
.
addLevel
(
Debug
::
ANY
);
if
(
outTimeout
==
0
)
if
(
outTimeout
==
0
)
outTimeout
=
TIMEOUT_INF
;
outTimeout
=
UniSetTimer
::
WaitUpTime
;
std
::
string
listfilter
(
""
);
std
::
string
listfilter
(
""
);
...
@@ -200,9 +190,9 @@ void LogReader::sendCommand( const std::string& _addr, ost::tpport_t _port, std:
...
@@ -200,9 +190,9 @@ void LogReader::sendCommand( const std::string& _addr, ost::tpport_t _port, std:
sendCommand
(
msg
,
verbose
);
sendCommand
(
msg
,
verbose
);
break
;
break
;
}
}
catch
(
const
ost
::
Sock
Exception
&
e
)
catch
(
const
Poco
::
Net
::
Net
Exception
&
e
)
{
{
cerr
<<
"(LogReader): "
<<
e
.
getString
()
<<
" ("
<<
_addr
<<
")"
<<
endl
;
cerr
<<
"(LogReader): "
<<
e
.
displayText
()
<<
" ("
<<
_addr
<<
")"
<<
endl
;
}
}
catch
(
const
std
::
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
...
@@ -231,13 +221,13 @@ void LogReader::sendCommand( const std::string& _addr, ost::tpport_t _port, std:
...
@@ -231,13 +221,13 @@ void LogReader::sendCommand( const std::string& _addr, ost::tpport_t _port, std:
{
{
int
a
=
2
;
int
a
=
2
;
while
(
a
>
0
&&
tcp
->
isPending
(
ost
::
Socket
::
pendingInput
,
reply_timeout
)
)
while
(
a
>
0
&&
tcp
->
poll
(
reply_timeout
,
Poco
::
Net
::
Socket
::
SELECT_READ
)
)
{
{
int
n
=
tcp
->
peek
(
buf
,
sizeof
(
buf
)
-
1
);
int
n
=
tcp
->
available
(
);
if
(
n
>
0
)
if
(
n
>
0
)
{
{
tcp
->
re
ad
(
buf
,
n
);
tcp
->
re
ceiveBytes
(
buf
,
n
);
buf
[
n
]
=
'\0'
;
buf
[
n
]
=
'\0'
;
outlog
->
any
(
false
)
<<
buf
;
outlog
->
any
(
false
)
<<
buf
;
...
@@ -248,9 +238,9 @@ void LogReader::sendCommand( const std::string& _addr, ost::tpport_t _port, std:
...
@@ -248,9 +238,9 @@ void LogReader::sendCommand( const std::string& _addr, ost::tpport_t _port, std:
// rlog.warn() << "(LogReader): ...wait reply timeout..." << endl;
// rlog.warn() << "(LogReader): ...wait reply timeout..." << endl;
}
}
catch
(
const
ost
::
Sock
Exception
&
e
)
catch
(
const
Poco
::
Net
::
Net
Exception
&
e
)
{
{
cerr
<<
"(LogReader): "
<<
e
.
getString
()
<<
" ("
<<
_addr
<<
")"
<<
endl
;
cerr
<<
"(LogReader): "
<<
e
.
displayText
()
<<
" ("
<<
_addr
<<
")"
<<
endl
;
}
}
catch
(
const
std
::
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
...
@@ -261,7 +251,7 @@ void LogReader::sendCommand( const std::string& _addr, ost::tpport_t _port, std:
...
@@ -261,7 +251,7 @@ void LogReader::sendCommand( const std::string& _addr, ost::tpport_t _port, std:
disconnect
();
disconnect
();
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
LogReader
::
readlogs
(
const
std
::
string
&
_addr
,
ost
::
tpport_
t
_port
,
LogServerTypes
::
Command
cmd
,
const
std
::
string
logfilter
,
bool
verbose
)
void
LogReader
::
readlogs
(
const
std
::
string
&
_addr
,
in
t
_port
,
LogServerTypes
::
Command
cmd
,
const
std
::
string
logfilter
,
bool
verbose
)
{
{
char
buf
[
100001
];
char
buf
[
100001
];
...
@@ -269,10 +259,10 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
...
@@ -269,10 +259,10 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
rlog
.
addLevel
(
Debug
::
ANY
);
rlog
.
addLevel
(
Debug
::
ANY
);
if
(
inTimeout
==
0
)
if
(
inTimeout
==
0
)
inTimeout
=
TIMEOUT_INF
;
inTimeout
=
UniSetTimer
::
WaitUpTime
;
if
(
outTimeout
==
0
)
if
(
outTimeout
==
0
)
outTimeout
=
TIMEOUT_INF
;
outTimeout
=
UniSetTimer
::
WaitUpTime
;
unsigned
int
rcount
=
1
;
unsigned
int
rcount
=
1
;
...
@@ -313,13 +303,13 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
...
@@ -313,13 +303,13 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
send_ok
=
true
;
send_ok
=
true
;
}
}
while
(
tcp
->
isPending
(
ost
::
Socket
::
pendingInput
,
inTimeout
)
)
while
(
tcp
->
poll
(
inTimeout
,
Poco
::
Net
::
Socket
::
SELECT_READ
)
)
{
{
ssize_t
n
=
tcp
->
peek
(
buf
,
sizeof
(
buf
)
-
1
);
ssize_t
n
=
tcp
->
available
(
);
if
(
n
>
0
)
if
(
n
>
0
)
{
{
tcp
->
re
ad
(
buf
,
n
);
tcp
->
re
ceiveBytes
(
buf
,
n
);
buf
[
n
]
=
'\0'
;
buf
[
n
]
=
'\0'
;
outlog
->
any
(
false
)
<<
buf
;
outlog
->
any
(
false
)
<<
buf
;
...
@@ -342,9 +332,9 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
...
@@ -342,9 +332,9 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
disconnect
();
disconnect
();
}
}
catch
(
const
ost
::
Sock
Exception
&
e
)
catch
(
const
Poco
::
Net
::
Net
Exception
&
e
)
{
{
cerr
<<
"(LogReader): "
<<
e
.
getString
()
<<
" ("
<<
_addr
<<
")"
<<
endl
;
cerr
<<
"(LogReader): "
<<
e
.
displayText
()
<<
" ("
<<
_addr
<<
")"
<<
endl
;
}
}
catch
(
const
std
::
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
...
@@ -374,21 +364,17 @@ void LogReader::sendCommand(LogServerTypes::lsMessage& msg, bool verbose )
...
@@ -374,21 +364,17 @@ void LogReader::sendCommand(LogServerTypes::lsMessage& msg, bool verbose )
try
try
{
{
if
(
tcp
->
isPending
(
ost
::
Socket
::
pendingOutput
,
outTimeout
)
)
if
(
tcp
->
poll
(
outTimeout
,
Poco
::
Net
::
Socket
::
SELECT_WRITE
)
)
{
{
rlog
.
info
()
<<
"(LogReader): ** send command: cmd='"
<<
msg
.
cmd
<<
"' logname='"
<<
msg
.
logname
<<
"' data='"
<<
msg
.
data
<<
"'"
<<
endl
;
rlog
.
info
()
<<
"(LogReader): ** send command: cmd='"
<<
msg
.
cmd
<<
"' logname='"
<<
msg
.
logname
<<
"' data='"
<<
msg
.
data
<<
"'"
<<
endl
;
tcp
->
sendBytes
((
unsigned
char
*
)(
&
msg
),
sizeof
(
msg
));
for
(
size_t
i
=
0
;
i
<
sizeof
(
msg
);
i
++
)
(
*
tcp
)
<<
((
unsigned
char
*
)(
&
msg
))[
i
];
tcp
->
sync
();
}
}
else
else
rlog
.
warn
()
<<
"(LogReader): **** SEND COMMAND ('"
<<
msg
.
cmd
<<
"' FAILED!"
<<
endl
;
rlog
.
warn
()
<<
"(LogReader): **** SEND COMMAND ('"
<<
msg
.
cmd
<<
"' FAILED!"
<<
endl
;
}
}
catch
(
const
ost
::
Sock
Exception
&
e
)
catch
(
const
Poco
::
Net
::
Net
Exception
&
e
)
{
{
cerr
<<
"(LogReader): "
<<
e
.
getString
()
<<
endl
;
// " (" << _addr << ")" << endl;
cerr
<<
"(LogReader): "
<<
e
.
displayText
()
<<
endl
;
// " (" << _addr << ")" << endl;
}
}
catch
(
const
std
::
exception
&
ex
)
catch
(
const
std
::
exception
&
ex
)
{
{
...
...
src/Log/LogServer.cc
View file @
6d6bd388
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
#include <sstream>
#include <sstream>
#include <iomanip>
#include <iomanip>
#include <Poco/Net/NetException.h>
#include "LogServer.h"
#include "LogServer.h"
#include "UniSetTypes.h"
#include "UniSetTypes.h"
#include "Exceptions.h"
#include "Exceptions.h"
...
@@ -41,7 +42,7 @@ LogServer::LogServer( std::shared_ptr<LogAgregator> log ):
...
@@ -41,7 +42,7 @@ LogServer::LogServer( std::shared_ptr<LogAgregator> log ):
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
LogServer
::
LogServer
(
std
::
shared_ptr
<
DebugStream
>
log
)
:
LogServer
::
LogServer
(
std
::
shared_ptr
<
DebugStream
>
log
)
:
timeout
(
TIMEOUT_INF
),
timeout
(
UniSetTimer
::
WaitUpTime
),
cmdTimeout
(
2000
),
cmdTimeout
(
2000
),
sessLogLevel
(
Debug
::
NONE
),
sessLogLevel
(
Debug
::
NONE
),
sock
(
0
),
sock
(
0
),
...
@@ -50,7 +51,7 @@ LogServer::LogServer( std::shared_ptr<DebugStream> log ):
...
@@ -50,7 +51,7 @@ LogServer::LogServer( std::shared_ptr<DebugStream> log ):
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
LogServer
::
LogServer
()
:
LogServer
::
LogServer
()
:
timeout
(
TIMEOUT_INF
),
timeout
(
UniSetTimer
::
WaitUpTime
),
cmdTimeout
(
2000
),
cmdTimeout
(
2000
),
sessLogLevel
(
Debug
::
NONE
),
sessLogLevel
(
Debug
::
NONE
),
sock
(
0
),
sock
(
0
),
...
@@ -90,7 +91,7 @@ void LogServer::evfinish( const ev::loop_ref& loop )
...
@@ -90,7 +91,7 @@ void LogServer::evfinish( const ev::loop_ref& loop )
mylog
.
info
()
<<
myname
<<
"(LogServer): finished."
<<
endl
;
mylog
.
info
()
<<
myname
<<
"(LogServer): finished."
<<
endl
;
}
}
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
void
LogServer
::
run
(
const
std
::
string
&
_addr
,
ost
::
tpport_t
_port
,
bool
thread
)
void
LogServer
::
run
(
const
std
::
string
&
_addr
,
Poco
::
UInt16
_port
,
bool
thread
)
{
{
addr
=
_addr
;
addr
=
_addr
;
port
=
_port
;
port
=
_port
;
...
@@ -124,22 +125,13 @@ void LogServer::evprepare( const ev::loop_ref& eloop )
...
@@ -124,22 +125,13 @@ void LogServer::evprepare( const ev::loop_ref& eloop )
try
try
{
{
ost
::
InetAddress
iaddr
(
addr
.
c_str
());
sock
=
make_shared
<
UTCPSocket
>
(
addr
,
port
);
sock
=
make_shared
<
UTCPSocket
>
(
iaddr
,
port
);
}
}
catch
(
ost
::
Socket
*
socket
)
catch
(
Poco
::
Net
::
NetException
&
ex
)
{
{
ost
::
tpport_t
port
;
int
errnum
=
socket
->
getErrorNumber
();
ost
::
InetAddress
saddr
=
(
ost
::
InetAddress
)
socket
->
getPeer
(
&
port
);
ostringstream
err
;
ostringstream
err
;
err
<<
myname
<<
"(evprepare): socket error("
<<
errnum
<<
"): "
;
err
<<
myname
<<
"(evprepare): socket error:"
<<
ex
.
message
();
if
(
errnum
==
ost
::
Socket
::
errBindingFailed
)
err
<<
"bind failed; port busy"
<<
endl
;
else
err
<<
"client socket failed"
<<
endl
;
if
(
mylog
.
is_crit
()
)
if
(
mylog
.
is_crit
()
)
mylog
.
crit
()
<<
err
.
str
()
<<
endl
;
mylog
.
crit
()
<<
err
.
str
()
<<
endl
;
...
@@ -147,7 +139,7 @@ void LogServer::evprepare( const ev::loop_ref& eloop )
...
@@ -147,7 +139,7 @@ void LogServer::evprepare( const ev::loop_ref& eloop )
throw
SystemError
(
err
.
str
()
);
throw
SystemError
(
err
.
str
()
);
}
}
sock
->
set
Completion
(
false
);
sock
->
set
Blocking
(
false
);
io
.
set
<
LogServer
,
&
LogServer
::
ioAccept
>
(
this
);
io
.
set
<
LogServer
,
&
LogServer
::
ioAccept
>
(
this
);
io
.
set
(
eloop
);
io
.
set
(
eloop
);
...
@@ -170,7 +162,7 @@ void LogServer::ioAccept( ev::io& watcher, int revents )
...
@@ -170,7 +162,7 @@ void LogServer::ioAccept( ev::io& watcher, int revents )
if
(
mylog
.
is_crit
()
)
if
(
mylog
.
is_crit
()
)
mylog
.
crit
()
<<
myname
<<
"(LogServer::ioAccept): terminate work.."
<<
endl
;
mylog
.
crit
()
<<
myname
<<
"(LogServer::ioAccept): terminate work.."
<<
endl
;
sock
->
reject
();
sock
->
close
();
return
;
return
;
}
}
...
@@ -182,7 +174,7 @@ void LogServer::ioAccept( ev::io& watcher, int revents )
...
@@ -182,7 +174,7 @@ void LogServer::ioAccept( ev::io& watcher, int revents )
if
(
mylog
.
is_crit
()
)
if
(
mylog
.
is_crit
()
)
mylog
.
crit
()
<<
myname
<<
"(LogServer::ioAccept): session limit("
<<
sessMaxCount
<<
")"
<<
endl
;
mylog
.
crit
()
<<
myname
<<
"(LogServer::ioAccept): session limit("
<<
sessMaxCount
<<
")"
<<
endl
;
sock
->
reject
();
sock
->
close
();
return
;
return
;
}
}
}
}
...
...
src/Log/LogSession.cc
View file @
6d6bd388
...
@@ -23,7 +23,7 @@
...
@@ -23,7 +23,7 @@
#include <fcntl.h>
#include <fcntl.h>
#include <errno.h>
#include <errno.h>
#include <cstring>
#include <cstring>
#include <
cc++/socket
.h>
#include <
Poco/Net/NetException
.h>
#include "Exceptions.h"
#include "Exceptions.h"
#include "LogSession.h"
#include "LogSession.h"
#include "UniSetTypes.h"
#include "UniSetTypes.h"
...
@@ -67,17 +67,28 @@ LogSession::LogSession( int sfd, std::shared_ptr<DebugStream>& _log, timeout_t _
...
@@ -67,17 +67,28 @@ LogSession::LogSession( int sfd, std::shared_ptr<DebugStream>& _log, timeout_t _
try
try
{
{
sock
=
make_shared
<
USocket
>
(
sfd
);
sock
=
make_shared
<
USocket
>
(
sfd
);
ost
::
tpport_t
p
;
ost
::
InetAddress
iaddr
=
sock
->
getIPV4Peer
(
&
p
);
// resolve..
Poco
::
Net
::
SocketAddress
iaddr
=
sock
->
peerAddress
();
caddr
=
string
(
iaddr
.
getHostname
()
);
if
(
iaddr
.
host
().
toString
().
empty
()
)
{
ostringstream
err
;
err
<<
"(ModbusTCPSession): unknonwn ip(0.0.0.0) client disconnected?!"
;
if
(
mylog
.
is_crit
()
)
mylog
.
crit
()
<<
err
.
str
()
<<
endl
;
sock
.
reset
();
throw
SystemError
(
err
.
str
());
}
caddr
=
iaddr
.
host
().
toString
();
ostringstream
s
;
ostringstream
s
;
s
<<
iaddr
<<
":"
<<
p
;
s
<<
caddr
<<
":"
<<
iaddr
.
port
()
;
peername
=
s
.
str
();
peername
=
s
.
str
();
}
}
catch
(
const
ost
::
Sock
Exception
&
ex
)
catch
(
const
Poco
::
Net
::
Net
Exception
&
ex
)
{
{
ostringstream
err
;
ostringstream
err
;
err
<<
ex
.
what
();
err
<<
ex
.
what
();
...
@@ -85,7 +96,7 @@ LogSession::LogSession( int sfd, std::shared_ptr<DebugStream>& _log, timeout_t _
...
@@ -85,7 +96,7 @@ LogSession::LogSession( int sfd, std::shared_ptr<DebugStream>& _log, timeout_t _
throw
SystemError
(
err
.
str
());
throw
SystemError
(
err
.
str
());
}
}
sock
->
set
Completion
(
false
);
sock
->
set
Blocking
(
false
);
io
.
set
<
LogSession
,
&
LogSession
::
callback
>
(
this
);
io
.
set
<
LogSession
,
&
LogSession
::
callback
>
(
this
);
cmdTimer
.
set
<
LogSession
,
&
LogSession
::
onCmdTimeout
>
(
this
);
cmdTimer
.
set
<
LogSession
,
&
LogSession
::
onCmdTimeout
>
(
this
);
...
...
src/ObjectRepository/UniSetObject.cc
View file @
6d6bd388
...
@@ -351,7 +351,7 @@ void UniSetObject::termWaiting()
...
@@ -351,7 +351,7 @@ void UniSetObject::termWaiting()
tmr
->
terminate
();
tmr
->
terminate
();
}
}
// ------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------
void
UniSetObject
::
setThreadPriority
(
int
p
)
void
UniSetObject
::
setThreadPriority
(
Poco
::
Thread
::
Priority
p
)
{
{
if
(
thr
)
if
(
thr
)
thr
->
setPriority
(
p
);
thr
->
setPriority
(
p
);
...
@@ -578,7 +578,7 @@ bool UniSetObject::activate()
...
@@ -578,7 +578,7 @@ bool UniSetObject::activate()
if
(
myid
!=
UniSetTypes
::
DefaultObjectId
&&
threadcreate
)
if
(
myid
!=
UniSetTypes
::
DefaultObjectId
&&
threadcreate
)
{
{
thr
=
make_shared
<
ThreadCreator
<
UniSetObject
>
>
(
this
,
&
UniSetObject
::
work
);
thr
=
make_shared
<
ThreadCreator
<
UniSetObject
>
>
(
this
,
&
UniSetObject
::
work
);
thr
->
setCancel
(
ost
::
Thread
::
cancelDeferred
);
//
thr->setCancel(ost::Thread::cancelDeferred);
std
::
unique_lock
<
std
::
mutex
>
locker
(
m_working
);
std
::
unique_lock
<
std
::
mutex
>
locker
(
m_working
);
a_working
=
true
;
a_working
=
true
;
...
@@ -722,7 +722,7 @@ UniSetTypes::SimpleInfo* UniSetObject::getInfo( ::CORBA::Long userparam )
...
@@ -722,7 +722,7 @@ UniSetTypes::SimpleInfo* UniSetObject::getInfo( ::CORBA::Long userparam )
{
{
if
(
thr
)
if
(
thr
)
{
{
msgpid
=
thr
->
get
Id
();
// заодно(на всякий) обновим и внутреннюю информацию
msgpid
=
thr
->
get
TID
();
// заодно(на всякий) обновим и внутреннюю информацию
info
<<
msgpid
;
info
<<
msgpid
;
}
}
else
else
...
...
src/ObjectRepository/UniSetTypes.cc
View file @
6d6bd388
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
#include <cmath>
#include <cmath>
#include <iomanip>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <fstream>
#include "UniSetTypes.h"
#include "UniSetTypes.h"
#include "Configuration.h"
#include "Configuration.h"
...
...
src/Timers/Makefile.am
View file @
6d6bd388
...
@@ -2,6 +2,8 @@
...
@@ -2,6 +2,8 @@
# This file is part of the UniSet library #
# This file is part of the UniSet library #
############################################################################
############################################################################
noinst_LTLIBRARIES
=
libTimers.la
noinst_LTLIBRARIES
=
libTimers.la
libTimers_la_SOURCES
=
PassiveTimer.cc PassiveSigTimer.cc PassiveCondTimer.cc
libTimers_la_SOURCES
=
PassiveTimer.cc PassiveCondTimer.cc
#PassiveSigTimer.cc
include
$(top_builddir)/include.mk
include
$(top_builddir)/include.mk
src/Various/Configuration.cc
View file @
6d6bd388
...
@@ -1293,7 +1293,7 @@ namespace UniSetTypes
...
@@ -1293,7 +1293,7 @@ namespace UniSetTypes
}
}
// инициализация исключений для libcommoncpp
// инициализация исключений для libcommoncpp
ost
::
Thread
::
setException
(
ost
::
Thread
::
throwException
);
//
ost::Thread::setException(ost::Thread::throwException);
atexit
(
UniSetActivator
::
normalexit
);
atexit
(
UniSetActivator
::
normalexit
);
set_terminate
(
UniSetActivator
::
normalterminate
);
// ловушка для неизвестных исключений
set_terminate
(
UniSetActivator
::
normalterminate
);
// ловушка для неизвестных исключений
...
...
src/Various/Mutex.cc
View file @
6d6bd388
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
* \author Pavel Vainerman
* \author Pavel Vainerman
*/
*/
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
#include <memory>
#include <chrono>
#include <chrono>
#include <thread>
#include <thread>
#include <unistd.h>
#include <unistd.h>
...
@@ -35,11 +35,13 @@ using namespace UniSetTypes;
...
@@ -35,11 +35,13 @@ using namespace UniSetTypes;
uniset_rwmutex
::
uniset_rwmutex
(
const
std
::
string
&
name
)
:
uniset_rwmutex
::
uniset_rwmutex
(
const
std
::
string
&
name
)
:
nm
(
name
)
nm
(
name
)
{
{
m
=
std
::
unique_ptr
<
Poco
::
RWLock
>
(
new
Poco
::
RWLock
());
}
}
uniset_rwmutex
::
uniset_rwmutex
()
:
uniset_rwmutex
::
uniset_rwmutex
()
:
nm
(
""
)
nm
(
""
)
{
{
m
=
std
::
unique_ptr
<
Poco
::
RWLock
>
(
new
Poco
::
RWLock
());
}
}
uniset_rwmutex
::~
uniset_rwmutex
()
uniset_rwmutex
::~
uniset_rwmutex
()
...
@@ -54,42 +56,42 @@ std::ostream& UniSetTypes::operator<<(std::ostream& os, uniset_rwmutex& m )
...
@@ -54,42 +56,42 @@ std::ostream& UniSetTypes::operator<<(std::ostream& os, uniset_rwmutex& m )
void
uniset_rwmutex
::
lock
()
void
uniset_rwmutex
::
lock
()
{
{
MUTEX_DEBUG
(
cerr
<<
nm
<<
" prepare Locked.."
<<
endl
;)
MUTEX_DEBUG
(
cerr
<<
nm
<<
" prepare Locked.."
<<
endl
;)
m
.
writeLock
();
m
->
writeLock
();
MUTEX_DEBUG
(
cerr
<<
nm
<<
" Locked.."
<<
endl
;)
MUTEX_DEBUG
(
cerr
<<
nm
<<
" Locked.."
<<
endl
;)
}
}
void
uniset_rwmutex
::
wrlock
()
void
uniset_rwmutex
::
wrlock
()
{
{
MUTEX_DEBUG
(
cerr
<<
nm
<<
" prepare WRLocked.."
<<
endl
;)
MUTEX_DEBUG
(
cerr
<<
nm
<<
" prepare WRLocked.."
<<
endl
;)
m
.
writeLock
();
m
->
writeLock
();
MUTEX_DEBUG
(
cerr
<<
nm
<<
" WRLocked.."
<<
endl
;)
MUTEX_DEBUG
(
cerr
<<
nm
<<
" WRLocked.."
<<
endl
;)
}
}
void
uniset_rwmutex
::
rlock
()
void
uniset_rwmutex
::
rlock
()
{
{
MUTEX_DEBUG
(
cerr
<<
nm
<<
" prepare RLocked.."
<<
endl
;)
MUTEX_DEBUG
(
cerr
<<
nm
<<
" prepare RLocked.."
<<
endl
;)
m
.
readLock
();
m
->
readLock
();
MUTEX_DEBUG
(
cerr
<<
nm
<<
" RLocked.."
<<
endl
;)
MUTEX_DEBUG
(
cerr
<<
nm
<<
" RLocked.."
<<
endl
;)
}
}
void
uniset_rwmutex
::
unlock
()
void
uniset_rwmutex
::
unlock
()
{
{
m
.
unlock
();
m
->
unlock
();
MUTEX_DEBUG
(
cerr
<<
nm
<<
" Unlocked.."
<<
endl
;)
MUTEX_DEBUG
(
cerr
<<
nm
<<
" Unlocked.."
<<
endl
;)
}
}
bool
uniset_rwmutex
::
try_rlock
()
bool
uniset_rwmutex
::
try_rlock
()
{
{
return
m
.
tryReadLock
();
return
m
->
tryReadLock
();
}
}
bool
uniset_rwmutex
::
try_wrlock
()
bool
uniset_rwmutex
::
try_wrlock
()
{
{
return
m
.
tryWriteLock
();
return
m
->
tryWriteLock
();
}
}
bool
uniset_rwmutex
::
try_lock
()
bool
uniset_rwmutex
::
try_lock
()
{
{
return
m
.
tryWriteLock
();
return
m
->
tryWriteLock
();
}
}
// -------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------
uniset_rwmutex_wrlock
::
uniset_rwmutex_wrlock
(
uniset_rwmutex
&
_m
)
:
uniset_rwmutex_wrlock
::
uniset_rwmutex_wrlock
(
uniset_rwmutex
&
_m
)
:
...
...
src/Various/VMonitor.cc
View file @
6d6bd388
...
@@ -21,6 +21,22 @@
...
@@ -21,6 +21,22 @@
#include <algorithm>
#include <algorithm>
#include "VMonitor.h"
#include "VMonitor.h"
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
#define VMON_IMPL_ADD_N(T,m) void VMonitor::add( const std::string& name, const T& v ) \
{\
m.emplace(&v,name); \
} \
\
const std::string VMonitor::pretty_str( const std::string& name, const T* v, int nwidth ) \
{ \
std::ostringstream s; \
s << std::right << std::setw(nwidth) << name << std::left << " = " << std::right << std::setw(10) << *(v); \
return std::move(s.str()); \
} \
const std::string VMonitor::pretty_str( const std::string& name, const T& v, int nwidth ) \
{ \
return pretty_str(name,&v,nwidth); \
}
// --------------------------------------------------------------------------
#define VMON_IMPL_ADD(T) void VMonitor::add( const std::string& name, const T& v ) \
#define VMON_IMPL_ADD(T) void VMonitor::add( const std::string& name, const T& v ) \
{\
{\
m_##T.emplace(&v,name); \
m_##T.emplace(&v,name); \
...
@@ -121,6 +137,7 @@ VMON_IMPL_ADD2(char)
...
@@ -121,6 +137,7 @@ VMON_IMPL_ADD2(char)
VMON_IMPL_ADD
(
bool
)
VMON_IMPL_ADD
(
bool
)
VMON_IMPL_ADD
(
float
)
VMON_IMPL_ADD
(
float
)
VMON_IMPL_ADD
(
double
)
VMON_IMPL_ADD
(
double
)
VMON_IMPL_ADD_N
(
Poco
::
Int64
,
m_Int64
)
VMON_IMPL_ADD3
(
std
::
string
,
string
)
VMON_IMPL_ADD3
(
std
::
string
,
string
)
//VMON_IMPL_ADD3(UniSetTypes::ObjectId,ObjectId)
//VMON_IMPL_ADD3(UniSetTypes::ObjectId,ObjectId)
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
...
...
tests/MQPerfTest/Makefile.am
View file @
6d6bd388
noinst_PROGRAMS
=
mq-test
noinst_PROGRAMS
=
mq-test
mq_test_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(SIGC_LIBS)
$(
COMCPP_LIBS)
mq_test_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(SIGC_LIBS)
$(
POCO_LIBS)
-lpthread
mq_test_CPPFLAGS
=
-I
$(top_builddir)
/include
-I
$(top_builddir)
/extensions/include
$(SIGC_CFLAGS)
$(
COMCPP
_CFLAGS)
mq_test_CPPFLAGS
=
-I
$(top_builddir)
/include
-I
$(top_builddir)
/extensions/include
$(SIGC_CFLAGS)
$(
POCO
_CFLAGS)
mq_test_SOURCES
=
mq-test.cc
mq_test_SOURCES
=
mq-test.cc
tests/Makefile.am
View file @
6d6bd388
SUBDIRS
=
MQPerfTest
SUBDIRS
=
MQPerfTest
PocoTest
if
HAVE_TESTS
if
HAVE_TESTS
############################################################################
############################################################################
# This file is part of the UniSet library #
# This file is part of the UniSet library #
...
@@ -8,8 +8,8 @@ if HAVE_TESTS
...
@@ -8,8 +8,8 @@ if HAVE_TESTS
noinst_PROGRAMS
=
tests tests_with_conf develop
noinst_PROGRAMS
=
tests tests_with_conf develop
#umutex threadtst dlog
#umutex threadtst dlog
tests_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(SIGC_LIBS)
$(
COMCPP_LIBS)
tests_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(SIGC_LIBS)
$(
POCO_LIBS)
-lpthread
tests_CPPFLAGS
=
-I
$(top_builddir)
/include
$(SIGC_CFLAGS)
$(
COMCPP
_CFLAGS)
tests_CPPFLAGS
=
-I
$(top_builddir)
/include
$(SIGC_CFLAGS)
$(
POCO
_CFLAGS)
tests_SOURCES
=
tests.cc
\
tests_SOURCES
=
tests.cc
\
test_passivetimer.cc
\
test_passivetimer.cc
\
test_passivecondtimer.cc
\
test_passivecondtimer.cc
\
...
...
tests/test_tcpcheck.cc
View file @
6d6bd388
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include <future>
#include <future>
#include <ostream>
#include <ostream>
#include "UTCPSocket.h"
#include "TCPCheck.h"
#include "TCPCheck.h"
#include "UniSetTypes.h"
#include "UniSetTypes.h"
using
namespace
std
;
using
namespace
std
;
...
@@ -15,12 +16,14 @@ static atomic_bool cancel = {false};
...
@@ -15,12 +16,14 @@ static atomic_bool cancel = {false};
// --------------------------------------------------------
// --------------------------------------------------------
bool
run_test_server
()
bool
run_test_server
()
{
{
ost
::
InetAddress
addr
=
host
.
c_str
();
UTCPSocket
sock
(
host
,
port
);
ost
::
TCPSocket
sock
(
addr
,
port
);
while
(
!
cancel
)
while
(
!
cancel
)
{
{
if
(
sock
.
isPendingConnection
(
500
)
)
{}
if
(
sock
.
poll
(
500
,
Poco
::
Net
::
Socket
::
SELECT_READ
)
)
{
}
}
}
return
true
;
return
true
;
...
...
uniset2.files
View file @
6d6bd388
...
@@ -479,6 +479,7 @@ tests/threadtst.cc
...
@@ -479,6 +479,7 @@ tests/threadtst.cc
tests/umutex.cc
tests/umutex.cc
tests/perf_test.cc
tests/perf_test.cc
tests/MQPerfTest/mq-test.cc
tests/MQPerfTest/mq-test.cc
tests/PocoTest/poco-test.cc
testsuite/Makefile.am
testsuite/Makefile.am
Utilities/Admin/admin.cc
Utilities/Admin/admin.cc
Utilities/Admin/Makefile.am
Utilities/Admin/Makefile.am
...
...
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