Commit f4ca89ff authored by Pavel Vainerman's avatar Pavel Vainerman

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

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