Commit 13719a7b authored by Pavel Vainerman's avatar Pavel Vainerman

(LogServer): ушёл от использования переменной scount (перевёл на vector)

parent 1ff72a00
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#ifndef LogServer_H_ #ifndef LogServer_H_
#define LogServer_H_ #define LogServer_H_
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
#include <list> #include <vector>
#include <string> #include <string>
#include <memory> #include <memory>
#include <unordered_map> #include <unordered_map>
...@@ -138,9 +138,8 @@ class LogServer: ...@@ -138,9 +138,8 @@ class LogServer:
std::string onCommand( LogSession* s, LogServerTypes::Command cmd, const std::string& logname ); std::string onCommand( LogSession* s, LogServerTypes::Command cmd, const std::string& logname );
private: private:
typedef std::list< std::shared_ptr<LogSession> > SessionList; typedef std::vector< std::shared_ptr<LogSession> > SessionList;
SessionList slist; SessionList slist;
size_t scount = { 0 };
UniSetTypes::uniset_rwmutex mutSList; UniSetTypes::uniset_rwmutex mutSList;
timeout_t timeout = { UniSetTimer::WaitUpTime }; timeout_t timeout = { UniSetTimer::WaitUpTime };
......
...@@ -46,6 +46,7 @@ LogServer::LogServer( std::shared_ptr<LogAgregator> log ) noexcept: ...@@ -46,6 +46,7 @@ LogServer::LogServer( std::shared_ptr<LogAgregator> log ) noexcept:
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
LogServer::LogServer( std::shared_ptr<DebugStream> log ) noexcept: LogServer::LogServer( std::shared_ptr<DebugStream> log ) noexcept:
slist(sessMaxCount),
timeout(UniSetTimer::WaitUpTime), timeout(UniSetTimer::WaitUpTime),
cmdTimeout(2000), cmdTimeout(2000),
sessLogLevel(Debug::NONE), sessLogLevel(Debug::NONE),
...@@ -55,6 +56,7 @@ LogServer::LogServer( std::shared_ptr<DebugStream> log ) noexcept: ...@@ -55,6 +56,7 @@ LogServer::LogServer( std::shared_ptr<DebugStream> log ) noexcept:
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
LogServer::LogServer() noexcept: LogServer::LogServer() noexcept:
slist(sessMaxCount),
timeout(UniSetTimer::WaitUpTime), timeout(UniSetTimer::WaitUpTime),
cmdTimeout(2000), cmdTimeout(2000),
sessLogLevel(Debug::NONE), sessLogLevel(Debug::NONE),
...@@ -213,7 +215,7 @@ void LogServer::ioAccept( ev::io& watcher, int revents ) ...@@ -213,7 +215,7 @@ void LogServer::ioAccept( ev::io& watcher, int revents )
{ {
uniset_rwmutex_wrlock l(mutSList); uniset_rwmutex_wrlock l(mutSList);
if( scount >= sessMaxCount ) if( slist.size() >= sessMaxCount )
{ {
if( mylog.is_crit() ) if( mylog.is_crit() )
mylog.crit() << myname << "(LogServer::ioAccept): session limit(" << sessMaxCount << ")" << endl; mylog.crit() << myname << "(LogServer::ioAccept): session limit(" << sessMaxCount << ")" << endl;
...@@ -233,13 +235,10 @@ void LogServer::ioAccept( ev::io& watcher, int revents ) ...@@ -233,13 +235,10 @@ void LogServer::ioAccept( ev::io& watcher, int revents )
s->signal_logsession_command().connect( sigc::mem_fun(this, &LogServer::onCommand) ); s->signal_logsession_command().connect( sigc::mem_fun(this, &LogServer::onCommand) );
{ {
uniset_rwmutex_wrlock l(mutSList); uniset_rwmutex_wrlock l(mutSList);
scount++; slist.push_back(s);
// на первой сессии запоминаем состояние логов // на первой сессии запоминаем состояние логов
if( scount == 1 ) if( slist.size() == 1 )
saveDefaultLogLevels("ALL"); saveDefaultLogLevels("ALL");
slist.push_back(s);
} }
s->run(watcher.loop); s->run(watcher.loop);
...@@ -259,14 +258,12 @@ void LogServer::sessionFinished( LogSession* s ) ...@@ -259,14 +258,12 @@ void LogServer::sessionFinished( LogSession* s )
if( i->get() == s ) if( i->get() == s )
{ {
slist.erase(i); slist.erase(i);
scount--;
break; break;
} }
} }
if( slist.empty() ) if( slist.empty() )
{ {
scount = 0;
// восстанавливаем уровни логов по умолчанию // восстанавливаем уровни логов по умолчанию
restoreDefaultLogLevels("ALL"); restoreDefaultLogLevels("ALL");
} }
......
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