Commit 15b81657 authored by Pavel Vainerman's avatar Pavel Vainerman

Попытка исправить ошибку компиляции под p7, make style

parent 04b387b3
...@@ -532,6 +532,13 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname ...@@ -532,6 +532,13 @@ mv -f %buildroot%python_sitelibdir_noarch/* %buildroot%python_sitelibdir/%oname
* Mon Jan 18 2016 Pavel Vainerman <pv@altlinux.ru> 2.2-alt19 * Mon Jan 18 2016 Pavel Vainerman <pv@altlinux.ru> 2.2-alt19
- rebuild new version - rebuild new version
* Mon Jan 18 2016 Pavel Vainerman <pv@altlinux.ru> 2.2-alt17.2.3.alt1
- add supported libev:
- refactoring ModbusSlave (use libev)
- refactoring LogServer (use libev)
- refactoring UNetReceiver (use libev)
- minor fixes
* Fri Jan 15 2016 Pavel Vainerman <pv@altlinux.ru> 2.2-alt17 * Fri Jan 15 2016 Pavel Vainerman <pv@altlinux.ru> 2.2-alt17
- rebuild new version - rebuild new version
......
...@@ -297,8 +297,10 @@ AC_SUBST(COV_CFLAGS) ...@@ -297,8 +297,10 @@ AC_SUBST(COV_CFLAGS)
AM_CONDITIONAL(HAVE_COVERAGE, test ${buildgcov} = true) AM_CONDITIONAL(HAVE_COVERAGE, test ${buildgcov} = true)
AM_CONDITIONAL(HAVE_TESTS, test ${buildtests} = true) AM_CONDITIONAL(HAVE_TESTS, test ${buildtests} = true)
# -D_GLIBCXX_USE_NANOSLEEP - for std::this_thread::sleep_for
# -Weffc++ -Wno-unused-variable -Werror -Wctor-dtor-privacy # -Weffc++ -Wno-unused-variable -Werror -Wctor-dtor-privacy
CXX_EXTRA_FLAGS="-Wnon-virtual-dtor -Woverloaded-virtual -Woverflow" 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} ${COMCPP_LIBS}"
......
...@@ -331,6 +331,7 @@ CORBA::Boolean SharedMemory::exist() ...@@ -331,6 +331,7 @@ CORBA::Boolean SharedMemory::exist()
void SharedMemory::sigterm( int signo ) void SharedMemory::sigterm( int signo )
{ {
workready = false; workready = false;
if( signo == SIGTERM && wdt ) if( signo == SIGTERM && wdt )
wdt->stop(); wdt->stop();
......
...@@ -126,8 +126,8 @@ UNetExchange::UNetExchange(UniSetTypes::ObjectId objId, UniSetTypes::ObjectId sh ...@@ -126,8 +126,8 @@ UNetExchange::UNetExchange(UniSetTypes::ObjectId objId, UniSetTypes::ObjectId sh
// Если указано поле unet_broadcast_ip непосредственно у узла - берём его // Если указано поле unet_broadcast_ip непосредственно у узла - берём его
// если не указано берём общий broadcast_ip // если не указано берём общий broadcast_ip
string h = { n_it.getProp2("unet_broadcast_ip",default_ip) }; string h = { n_it.getProp2("unet_broadcast_ip", default_ip) };
string h2 = { n_it.getProp2("unet_broadcast_ip2",default_ip2) }; string h2 = { n_it.getProp2("unet_broadcast_ip2", default_ip2) };
if( h.empty() ) if( h.empty() )
{ {
...@@ -142,10 +142,10 @@ UNetExchange::UNetExchange(UniSetTypes::ObjectId objId, UniSetTypes::ObjectId sh ...@@ -142,10 +142,10 @@ UNetExchange::UNetExchange(UniSetTypes::ObjectId objId, UniSetTypes::ObjectId sh
// Если указано поле unet_port - используем его // Если указано поле unet_port - используем его
// Иначе port = идентификатору узла // Иначе port = идентификатору узла
int p = n_it.getPIntProp("unet_port",n_it.getIntProp("id")); int p = n_it.getPIntProp("unet_port", n_it.getIntProp("id"));
// по умолчанию порт на втором канале такой же как на первом (если не задан отдельно) // по умолчанию порт на втором канале такой же как на первом (если не задан отдельно)
int p2 = n_it.getPIntProp("unet_port2",p); int p2 = n_it.getPIntProp("unet_port2", p);
string n(n_it.getProp("name")); string n(n_it.getProp("name"));
......
...@@ -53,7 +53,8 @@ ...@@ -53,7 +53,8 @@
Основная идея заключается в том, что каждый узел на порту равном своему ID Основная идея заключается в том, что каждый узел на порту равном своему ID
посылает в сеть UDP-пакеты содержащие данные считанные из локальной SM. Формат данных - это набор посылает в сеть UDP-пакеты содержащие данные считанные из локальной SM. Формат данных - это набор
пар [id,value]. Другие узлы принимают их. Помимо этого данный процесс запускает пар [id,value]. Другие узлы принимают их. Помимо этого данный процесс запускает
по потоку приёма для каждого другого узла и ловит пакеты от них, сохраняя данные в SM. "получателей" по одному на каждый (другой) узел и ловит пакеты от них, сохраняя данные в SM.
При этом "получатели" работют на одном(!) потоке с использованием событий libev (см. UNetReceiver).
\par \par
При своём старте процесс считывает из секции \<nodes> список узлов которые необходимо "слушать", При своём старте процесс считывает из секции \<nodes> список узлов которые необходимо "слушать",
...@@ -173,7 +174,7 @@ class UNetExchange: ...@@ -173,7 +174,7 @@ class UNetExchange:
tmStep tmStep
}; };
private: private:
UNetExchange(); UNetExchange();
timeout_t initPause; timeout_t initPause;
UniSetTypes::uniset_rwmutex mutex_start; UniSetTypes::uniset_rwmutex mutex_start;
......
...@@ -132,7 +132,8 @@ void UNetReceiver::setReceivePause( timeout_t msec ) ...@@ -132,7 +132,8 @@ void UNetReceiver::setReceivePause( timeout_t msec )
void UNetReceiver::setUpdatePause( timeout_t msec ) void UNetReceiver::setUpdatePause( timeout_t msec )
{ {
updatepause = msec; updatepause = msec;
updateTime = (double)updatepause/1000.0; updateTime = (double)updatepause / 1000.0;
if( evUpdate.is_active() ) if( evUpdate.is_active() )
evUpdate.start(updateTime); evUpdate.start(updateTime);
} }
...@@ -179,10 +180,11 @@ void UNetReceiver::resetTimeout() ...@@ -179,10 +180,11 @@ void UNetReceiver::resetTimeout()
void UNetReceiver::start() void UNetReceiver::start()
{ {
unetinfo << myname << ":... start... " << endl; unetinfo << myname << ":... start... " << endl;
if( !activated ) if( !activated )
{ {
activated = true; activated = true;
loop.evrun(this,true); loop.evrun(this, true);
} }
else else
forceUpdate(); forceUpdate();
...@@ -191,7 +193,7 @@ void UNetReceiver::start() ...@@ -191,7 +193,7 @@ void UNetReceiver::start()
void UNetReceiver::evprepare( const ev::loop_ref& eloop ) void UNetReceiver::evprepare( const ev::loop_ref& eloop )
{ {
evReceive.set(eloop); evReceive.set(eloop);
evReceive.start(udp->getSocket(),ev::READ); evReceive.start(udp->getSocket(), ev::READ);
evUpdate.set(eloop); evUpdate.set(eloop);
evUpdate.start( updateTime ); evUpdate.start( updateTime );
...@@ -200,6 +202,7 @@ void UNetReceiver::evprepare( const ev::loop_ref& eloop ) ...@@ -200,6 +202,7 @@ void UNetReceiver::evprepare( const ev::loop_ref& eloop )
void UNetReceiver::evfinish( const ev::loop_ref& eloop ) void UNetReceiver::evfinish( const ev::loop_ref& eloop )
{ {
activated = false; activated = false;
if( evReceive.is_active() ) if( evReceive.is_active() )
evReceive.stop(); evReceive.stop();
...@@ -399,6 +402,7 @@ void UNetReceiver::readEvent( ev::io& watcher ) ...@@ -399,6 +402,7 @@ void UNetReceiver::readEvent( ev::io& watcher )
return; return;
bool tout = false; bool tout = false;
try try
{ {
if( receive() ) if( receive() )
...@@ -427,6 +431,7 @@ void UNetReceiver::readEvent( ev::io& watcher ) ...@@ -427,6 +431,7 @@ void UNetReceiver::readEvent( ev::io& watcher )
if( ptPrepare.checkTime() && trTimeout.change(tout) ) if( ptPrepare.checkTime() && trTimeout.change(tout) )
{ {
auto w = shared_from_this(); auto w = shared_from_this();
if( w ) if( w )
{ {
if( tout ) if( tout )
...@@ -496,13 +501,13 @@ void UNetReceiver::stop() ...@@ -496,13 +501,13 @@ void UNetReceiver::stop()
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool UNetReceiver::receive() bool UNetReceiver::receive()
{ {
// if( !udp->isInputReady(recvTimeout) ) // if( !udp->isInputReady(recvTimeout) )
// return false; // return false;
//udp->UDPReceive::receive((char*)(r_buf.data), sizeof(r_buf.data)); //udp->UDPReceive::receive((char*)(r_buf.data), sizeof(r_buf.data));
//ssize_t ret = ::recv(udp->getSocket(),r_buf.data,sizeof(r_buf.data),0); //ssize_t ret = ::recv(udp->getSocket(),r_buf.data,sizeof(r_buf.data),0);
ssize_t ret = udp->receive(r_buf.data,sizeof(r_buf.data)); ssize_t ret = udp->receive(r_buf.data, sizeof(r_buf.data));
if( ret < 0 ) if( ret < 0 )
{ {
......
...@@ -163,7 +163,10 @@ class UNetReceiver: ...@@ -163,7 +163,10 @@ class UNetReceiver:
void updateEvent( ev::periodic& watcher, int revents ); void updateEvent( ev::periodic& watcher, int revents );
virtual void evprepare( const ev::loop_ref& eloop ) override; virtual void evprepare( const ev::loop_ref& eloop ) override;
virtual void evfinish(const ev::loop_ref& eloop ) override; virtual void evfinish(const ev::loop_ref& eloop ) override;
virtual std::string wname(){ return myname; } virtual std::string wname()
{
return myname;
}
void initIterators(); void initIterators();
......
...@@ -287,6 +287,7 @@ void UNetSender::real_send(UniSetUDP::UDPMessage& mypack) ...@@ -287,6 +287,7 @@ void UNetSender::real_send(UniSetUDP::UDPMessage& mypack)
void UNetSender::stop() void UNetSender::stop()
{ {
activated = false; activated = false;
// s_thr->stop(); // s_thr->stop();
if( s_thr ) if( s_thr )
s_thr->join(); s_thr->join();
......
...@@ -12,18 +12,21 @@ ...@@ -12,18 +12,21 @@
class EvWatcher class EvWatcher
{ {
public: public:
EvWatcher(){} EvWatcher() {}
virtual ~EvWatcher(){} virtual ~EvWatcher() {}
// подготовка перед запуском loop // подготовка перед запуском loop
// запуск своих ev::xxx.start() // запуск своих ev::xxx.start()
virtual void evprepare( const ev::loop_ref& ){} virtual void evprepare( const ev::loop_ref& ) {}
// действия при завершении // действия при завершении
// завершение своих ev::xxx.stop() // завершение своих ev::xxx.stop()
virtual void evfinish( const ev::loop_ref& ){} virtual void evfinish( const ev::loop_ref& ) {}
virtual std::string wname(){ return ""; } virtual std::string wname()
{
return "";
}
}; };
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
/*! /*!
...@@ -52,7 +55,10 @@ class CommonEventLoop ...@@ -52,7 +55,10 @@ class CommonEventLoop
/*! \return TRUE - если это был последний EvWatcher и loop остановлен */ /*! \return TRUE - если это был последний EvWatcher и loop остановлен */
bool evstop( EvWatcher* w ); bool evstop( EvWatcher* w );
inline const ev::loop_ref evloop(){ return loop; } inline const ev::loop_ref evloop()
{
return loop;
}
protected: protected:
......
...@@ -23,11 +23,11 @@ class EventLoopServer ...@@ -23,11 +23,11 @@ class EventLoopServer
protected: protected:
// действия при завершении // действия при завершении
// завершение своих ev::xxx.stop() // завершение своих ev::xxx.stop()
virtual void evfinish(){} virtual void evfinish() {}
// подготовка перед запуском loop // подготовка перед запуском loop
// запусу своих ev::xxx.start() // запусу своих ev::xxx.start()
virtual void evprepare(){} virtual void evprepare() {}
// Управление потоком событий // Управление потоком событий
void evrun( bool thread = true ); void evrun( bool thread = true );
......
...@@ -113,7 +113,10 @@ class LogServer: ...@@ -113,7 +113,10 @@ class LogServer:
virtual void evprepare( const ev::loop_ref& loop ) override; virtual void evprepare( const ev::loop_ref& loop ) override;
virtual void evfinish( const ev::loop_ref& loop ) override; virtual void evfinish( const ev::loop_ref& loop ) override;
virtual std::string wname(){ return myname; } virtual std::string wname()
{
return myname;
}
void ioAccept( ev::io& watcher, int revents ); void ioAccept( ev::io& watcher, int revents );
void sessionFinished( LogSession* s ); void sessionFinished( LogSession* s );
......
...@@ -12,13 +12,16 @@ class UDPSocketU: ...@@ -12,13 +12,16 @@ class UDPSocketU:
{ {
public: public:
UDPSocketU( const ost::IPV4Address &bind, ost::tpport_t port): UDPSocketU( const ost::IPV4Address& bind, ost::tpport_t port):
ost::UDPSocket(bind,port) ost::UDPSocket(bind, port)
{} {}
virtual ~UDPSocketU(){} virtual ~UDPSocketU() {}
inline SOCKET getSocket(){ return ost::UDPSocket::so; } inline SOCKET getSocket()
{
return ost::UDPSocket::so;
}
}; };
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
class UDPReceiveU: class UDPReceiveU:
...@@ -26,14 +29,20 @@ class UDPReceiveU: ...@@ -26,14 +29,20 @@ class UDPReceiveU:
{ {
public: public:
UDPReceiveU( const ost::IPV4Address &bind, ost::tpport_t port): UDPReceiveU( const ost::IPV4Address& bind, ost::tpport_t port):
ost::UDPReceive(bind,port) ost::UDPReceive(bind, port)
{} {}
virtual ~UDPReceiveU(){} virtual ~UDPReceiveU() {}
inline SOCKET getSocket(){ return ost::UDPReceive::so; } inline SOCKET getSocket()
inline void setCompletion( bool set ){ ost::UDPReceive::setCompletion(set); } {
return ost::UDPReceive::so;
}
inline void setCompletion( bool set )
{
ost::UDPReceive::setCompletion(set);
}
}; };
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
class UDPDuplexU: class UDPDuplexU:
...@@ -41,14 +50,20 @@ class UDPDuplexU: ...@@ -41,14 +50,20 @@ class UDPDuplexU:
{ {
public: public:
UDPDuplexU(const ost::IPV4Address &bind, ost::tpport_t port): UDPDuplexU(const ost::IPV4Address& bind, ost::tpport_t port):
ost::UDPDuplex(bind,port) ost::UDPDuplex(bind, port)
{} {}
virtual ~UDPDuplexU(){} virtual ~UDPDuplexU() {}
SOCKET getReceiveSocket(){ return ost::UDPReceive::so; } SOCKET getReceiveSocket()
void setReceiveCompletion( bool set ){ ost::UDPReceive::setCompletion(set); } {
return ost::UDPReceive::so;
}
void setReceiveCompletion( bool set )
{
ost::UDPReceive::setCompletion(set);
}
}; };
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
#endif // UDPReceiveU_H_ #endif // UDPReceiveU_H_
......
// -------------------------------------------------------------------------
#ifndef USocket_H_
#define USocket_H_
// -------------------------------------------------------------------------
#include <cc++/socket.h>
// -------------------------------------------------------------------------
class USocket:
public ost::Socket
{
public:
// dup and accept...raw socket
USocket( int sock );
virtual ~USocket();
// set keepalive params
// return true if OK
bool setKeepAliveParams( timeout_t timeout_sec = 5, int conn_keepcnt = 1, int keepintvl = 2 );
int getSocket();
protected:
void init( bool throwflag = false );
private:
};
// -------------------------------------------------------------------------
#endif // USocket_H_
// -------------------------------------------------------------------------
...@@ -88,8 +88,6 @@ class ModbusTCPServer: ...@@ -88,8 +88,6 @@ class ModbusTCPServer:
return port; return port;
} }
virtual bool isAcive() override;
// ------------------------------------------------- // -------------------------------------------------
// Таймер. // Таймер.
// Т.к. eventLoop() "бесконечный", то сделана возможность // Т.к. eventLoop() "бесконечный", то сделана возможность
......
...@@ -183,12 +183,14 @@ void ModbusTCPServer::setTimer( timeout_t msec ) ...@@ -183,12 +183,14 @@ void ModbusTCPServer::setTimer( timeout_t msec )
if( msec == TIMEOUT_INF ) if( msec == TIMEOUT_INF )
{ {
tmTime = 0; tmTime = 0;
if( ioTimer.is_active() ) if( ioTimer.is_active() )
ioTimer.stop(); ioTimer.stop();
} }
else else
{ {
tmTime = (double)msec / 1000.; tmTime = (double)msec / 1000.;
if( ioTimer.is_active() ) if( ioTimer.is_active() )
ioTimer.start( tmTime ); ioTimer.start( tmTime );
} }
......
...@@ -207,6 +207,7 @@ void LogServer::ioAccept( ev::io& watcher, int revents ) ...@@ -207,6 +207,7 @@ void LogServer::ioAccept( ev::io& watcher, int revents )
void LogServer::sessionFinished( LogSession* s ) void LogServer::sessionFinished( LogSession* s )
{ {
uniset_rwmutex_wrlock l(mutSList); uniset_rwmutex_wrlock l(mutSList);
for( SessionList::iterator i = slist.begin(); i != slist.end(); ++i ) for( SessionList::iterator i = slist.begin(); i != slist.end(); ++i )
{ {
if( i->get() == s ) if( i->get() == s )
......
...@@ -19,6 +19,7 @@ CommonEventLoop::~CommonEventLoop() ...@@ -19,6 +19,7 @@ CommonEventLoop::~CommonEventLoop()
{ {
cancelled = true; cancelled = true;
evterm.send(); evterm.send();
if( thr ) if( thr )
{ {
thr->join(); thr->join();
...@@ -49,6 +50,7 @@ bool CommonEventLoop::evrun(EvWatcher* w, bool thread ) ...@@ -49,6 +50,7 @@ bool CommonEventLoop::evrun(EvWatcher* w, bool thread )
// ждём.. // ждём..
std::unique_lock<std::mutex> locker(prep_mutex); std::unique_lock<std::mutex> locker(prep_mutex);
while( !prep_notify ) while( !prep_notify )
prep_event.wait(locker); prep_event.wait(locker);
...@@ -64,6 +66,7 @@ bool CommonEventLoop::evrun(EvWatcher* w, bool thread ) ...@@ -64,6 +66,7 @@ bool CommonEventLoop::evrun(EvWatcher* w, bool thread )
// ожидаем завершения основного потока.. // ожидаем завершения основного потока..
std::unique_lock<std::mutex> locker(term_mutex); std::unique_lock<std::mutex> locker(term_mutex);
while( !term_notify ) while( !term_notify )
term_event.wait(locker); term_event.wait(locker);
...@@ -84,6 +87,7 @@ bool CommonEventLoop::evstop( EvWatcher* w ) ...@@ -84,6 +87,7 @@ bool CommonEventLoop::evstop( EvWatcher* w )
return false; return false;
std::unique_lock<std::mutex> l(wlist_mutex); std::unique_lock<std::mutex> l(wlist_mutex);
try try
{ {
w->evfinish(loop); // для этого Watcher это уже finish.. w->evfinish(loop); // для этого Watcher это уже finish..
...@@ -112,6 +116,7 @@ bool CommonEventLoop::evstop( EvWatcher* w ) ...@@ -112,6 +116,7 @@ bool CommonEventLoop::evstop( EvWatcher* w )
cancelled = false; cancelled = false;
} }
} }
return true; return true;
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
...@@ -142,7 +147,7 @@ void CommonEventLoop::onStop() ...@@ -142,7 +147,7 @@ void CommonEventLoop::onStop()
// потому-что onStop будет вызываться // потому-что onStop будет вызываться
// из evstop, где он уже будет под "блокировкой" // из evstop, где он уже будет под "блокировкой"
// т.е. чтобы не получить deadlock // т.е. чтобы не получить deadlock
for( const auto& w: wlist ) for( const auto& w : wlist )
{ {
try try
{ {
......
...@@ -41,6 +41,7 @@ void EventLoopServer::evstop() ...@@ -41,6 +41,7 @@ void EventLoopServer::evstop()
{ {
cancelled = true; cancelled = true;
evterm.send(); evterm.send();
if( thr ) if( thr )
{ {
thr->join(); thr->join();
......
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