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