Commit 6d6bd388 authored by Pavel Vainerman's avatar Pavel Vainerman

ПЕРЕХОД НА libPoco: шаг первый (удаление cc++, быстрый перевод на Poco::Net)

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