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