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