Commit f4ca89ff authored by Pavel Vainerman's avatar Pavel Vainerman

(LogServer): небольшая оптимизация и удаление лишнего кода

(uniset-log): исправил сообщение о неизвестной команде для -m, доработал чтобы программа "выходила" после неё, исправил ошибку с "долгим отображением логов от сервера"(рассинхронизация).
parent 3e4e6738
...@@ -55,7 +55,7 @@ static void print_help() ...@@ -55,7 +55,7 @@ static void print_help()
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main( int argc, char** argv ) int main( int argc, char** argv )
{ {
std::ios::sync_with_stdio(false); // std::ios::sync_with_stdio(false); // нельзя отключать.. тогда "обмен с сервером" рассинхронизируется
int optindex = 0; int optindex = 0;
int opt = 0; int opt = 0;
......
...@@ -34,7 +34,7 @@ static void print_help() ...@@ -34,7 +34,7 @@ static void print_help()
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
int main( int argc, char** argv ) int main( int argc, char** argv )
{ {
std::ios::sync_with_stdio(false); // std::ios::sync_with_stdio(false);
int optindex = 0; int optindex = 0;
int opt = 0; int opt = 0;
......
...@@ -25,6 +25,8 @@ void TestGen::step() ...@@ -25,6 +25,8 @@ void TestGen::step()
cout << "str: " << str(input2_s) << endl; cout << "str: " << str(input2_s) << endl;
cout << "===========" << endl; cout << "===========" << endl;
cout << dumpIO() << endl; cout << dumpIO() << endl;
myinfo << str(input2_s) << endl;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void TestGen::sensorInfo( const SensorMessage* sm ) void TestGen::sensorInfo( const SensorMessage* sm )
......
...@@ -6,6 +6,6 @@ ulimit -Sc 10000000000 ...@@ -6,6 +6,6 @@ ulimit -Sc 10000000000
./uniset2-start.sh -f ./uniset2-smemory --smemory-id SharedMemory --pulsar-id DO_C --pulsar-iotype DO --pulsar-msec 100 \ ./uniset2-start.sh -f ./uniset2-smemory --smemory-id SharedMemory --pulsar-id DO_C --pulsar-iotype DO --pulsar-msec 100 \
--confile test.xml --datfile test.xml --db-logging 1 --ulog-add-levels system \ --confile test.xml --datfile test.xml --db-logging 1 --ulog-add-levels system \
--sm-log-add-levels any $* \ --sm-log-add-levels any $* --sm-run-logserver \
#--ulog-add-levels info,crit,warn,level9,system \ #--ulog-add-levels info,crit,warn,level9,system \
#--dlog-add-levels info,crit,warn \ #--dlog-add-levels info,crit,warn \
...@@ -115,8 +115,6 @@ class LogServer ...@@ -115,8 +115,6 @@ class LogServer
ost::TCPSocket* tcp; ost::TCPSocket* tcp;
std::shared_ptr<DebugStream> elog; std::shared_ptr<DebugStream> elog;
std::ostream* oslog;
std::shared_ptr<NullLogSession> nullsess; std::shared_ptr<NullLogSession> nullsess;
}; };
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
......
...@@ -72,6 +72,7 @@ class LogSession: ...@@ -72,6 +72,7 @@ class LogSession:
std::atomic_bool cancelled; std::atomic_bool cancelled;
DebugStream slog; DebugStream slog;
std::ostringstream sbuf;
std::mutex log_mutex; std::mutex log_mutex;
std::condition_variable log_event; std::condition_variable log_event;
......
...@@ -176,11 +176,7 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ ...@@ -176,11 +176,7 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
{ {
if( tcp->isPending(ost::Socket::pendingOutput, outTimeout) ) if( tcp->isPending(ost::Socket::pendingOutput, outTimeout) )
{ {
rlog.info() << "(LogReader): ** send command: logname='" << msg.logname << "' cmd='" << msg.cmd << "' data='" << msg.data << "'" << endl; rlog.info() << "(LogReader): ** send command: cmd='" << msg.cmd << "' logname='" << msg.logname << "' data='" << msg.data << "'" << endl;
// LogServerTypes::lsMessage msg;
// msg.cmd = cmd;
// msg.data = data;
for( size_t i = 0; i < sizeof(msg); i++ ) for( size_t i = 0; i < sizeof(msg); i++ )
(*tcp) << ((unsigned char*)(&msg))[i]; (*tcp) << ((unsigned char*)(&msg))[i];
...@@ -190,14 +186,14 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ ...@@ -190,14 +186,14 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
else else
rlog.warn() << "(LogReader): **** SEND COMMAND ('" << msg.cmd << "' FAILED!" << endl; rlog.warn() << "(LogReader): **** SEND COMMAND ('" << msg.cmd << "' FAILED!" << endl;
if( cmdonly ) if( cmdonly && msg.cmd!=LogServerTypes::cmdList )
{ {
disconnect(); disconnect();
return; return;
} }
} }
while( !cmdonly && tcp->isPending(ost::Socket::pendingInput, inTimeout) ) while( (!cmdonly || msg.cmd==LogServerTypes::cmdList) && tcp->isPending(ost::Socket::pendingInput, inTimeout) )
{ {
int n = tcp->peek( buf, sizeof(buf) - 1 ); int n = tcp->peek( buf, sizeof(buf) - 1 );
...@@ -206,6 +202,9 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ ...@@ -206,6 +202,9 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
tcp->read(buf, n); tcp->read(buf, n);
buf[n] = '\0'; buf[n] = '\0';
log << buf; log << buf;
if( msg.cmd==LogServerTypes::cmdList )
break;
} }
else else
break; break;
...@@ -224,6 +223,9 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ ...@@ -224,6 +223,9 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
cerr << "(LogReader): " << ex.what() << endl; cerr << "(LogReader): " << ex.what() << endl;
} }
if( cmdonly )
break;
if( readcount > 0 ) if( readcount > 0 )
n--; n--;
} }
......
...@@ -51,8 +51,7 @@ LogServer::LogServer( std::shared_ptr<DebugStream> log ): ...@@ -51,8 +51,7 @@ LogServer::LogServer( std::shared_ptr<DebugStream> log ):
cancelled(false), cancelled(false),
thr(0), thr(0),
tcp(0), tcp(0),
elog(log), elog(log)
oslog(0)
{ {
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
......
...@@ -25,6 +25,9 @@ std::ostream& LogServerTypes::operator<<(std::ostream& os, LogServerTypes::Comma ...@@ -25,6 +25,9 @@ std::ostream& LogServerTypes::operator<<(std::ostream& os, LogServerTypes::Comma
case LogServerTypes::cmdOnLogFile: case LogServerTypes::cmdOnLogFile:
return os << "cmdOnLogFile"; return os << "cmdOnLogFile";
case LogServerTypes::cmdList:
return os << "cmdList";
default: default:
return os << "Unknown"; return os << "Unknown";
} }
......
...@@ -85,10 +85,7 @@ void LogSession::run() ...@@ -85,10 +85,7 @@ void LogSession::run()
slog.crit() << peername << "(run): LOG NULL!!" << endl; slog.crit() << peername << "(run): LOG NULL!!" << endl;
// ptSessionTimeout.setTiming(sessTimeout);
setKeepAlive(true); setKeepAlive(true);
// setTimeout(sessTimeout);
// Команды могут посылаться только в начале сессии.. // Команды могут посылаться только в начале сессии..
if( isPending(Socket::pendingInput, cmdTimeout) ) if( isPending(Socket::pendingInput, cmdTimeout) )
...@@ -241,7 +238,7 @@ void LogSession::run() ...@@ -241,7 +238,7 @@ void LogSession::run()
// чтобы не застревать на посылке в сеть.. // чтобы не застревать на посылке в сеть..
// делаем через промежуточный буффер (stringstream) // делаем через промежуточный буффер (stringstream)
ostringstream sbuf; sbuf.str("");
bool send = false; bool send = false;
{ {
std::unique_lock<std::mutex> lk(log_mutex); std::unique_lock<std::mutex> lk(log_mutex);
......
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