Commit a20dcb5f authored by Pavel Vainerman's avatar Pavel Vainerman

(LogServer): решение проблеммы с закрытием соединения на стороне сервера

parent 7e0f414b
......@@ -20,10 +20,7 @@ cmdonly(false)
LogReader::~LogReader()
{
if( isConnection() )
{
(*tcp) << endl;
disconnect();
}
}
// -------------------------------------------------------------------------
void LogReader::connect( const std::string& addr, ost::tpport_t _port, timeout_t msec )
......@@ -155,8 +152,11 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
rlog.warn() << "**** SEND COMMAND ('" << msg.cmd << "' FAILED!" << endl;
if( cmdonly )
{
disconnect();
return;
}
}
while( !cmdonly && tcp->isPending(ost::Socket::pendingInput,inTimeout) )
{
......@@ -177,9 +177,6 @@ void LogReader::readlogs( const std::string& _addr, ost::tpport_t _port, LogServ
}
if( isConnection() )
{
(*tcp) << endl;
disconnect();
}
}
// -------------------------------------------------------------------------
......@@ -10,18 +10,24 @@ using namespace UniSetTypes;
LogServer::~LogServer()
{
cancelled = true;
if( thr )
{
thr->stop();
if( thr->isRunning() )
thr->join();
delete thr;
}
{
uniset_rwmutex_wrlock l(mutSList);
// uniset_rwmutex_wrlock l(mutSList);
for( auto& i: slist )
{
if( i->isRunning() )
delete i;
}
if( thr )
{
thr->stop();
delete thr;
}
delete tcp;
}
// -------------------------------------------------------------------------
LogServer::LogServer( std::ostream& os ):
......@@ -102,7 +108,7 @@ void LogServer::work()
{
try
{
while( tcp->isPendingConnection(timeout) )
while( !cancelled && tcp->isPendingConnection(timeout) )
{
LogSession* s = new LogSession(*tcp, elog, sessTimeout, cmdTimeout, outTimeout);
{
......@@ -129,10 +135,12 @@ void LogServer::work()
}
}
cerr << "*** LOG SERVER THREAD STOPPED.." << endl;
{
uniset_rwmutex_wrlock l(mutSList);
for( SessionList::iterator i=slist.begin(); i!=slist.end(); ++i )
(*i)->disconnect();
// uniset_rwmutex_wrlock l(mutSList);
for( auto& i: slist )
i->disconnect();
}
}
// -------------------------------------------------------------------------
......@@ -143,7 +151,6 @@ void LogServer::sessionFinished( LogSession* s )
{
if( (*i) == s )
{
// cerr << "session '" << s->getClientAddress() << "' closed.." << endl;
slist.erase(i);
return;
}
......
......@@ -68,6 +68,9 @@ void LogSession::run()
string oldLogFile( log->getLogFile() );
setKeepAlive(true);
// setTimeout(sessTimeout);
// Команды могут посылаться только в начале сессии..
if( isPending(Socket::pendingInput, cmdTimeout) )
{
......@@ -142,7 +145,7 @@ void LogSession::run()
}
cancelled = false;
while( !cancelled && !ptSessionTimeout.checkTime() )
while( !cancelled && isConnected() ) // !ptSessionTimeout.checkTime()
{
// проверка только ради проверки "целостности" соединения
if( isPending(Socket::pendingInput, 10) )
......@@ -155,11 +158,9 @@ void LogSession::run()
if( isPending(Socket::pendingOutput, outTimeout) )
{
// slog.warn() << peername << "(run): send.." << endl;
ptSessionTimeout.reset();
//slog.info() << peername << "(run): send.." << endl;
// ptSessionTimeout.reset();
if( log )
{
// чтобы не застревать на посылке в сеть..
// делаем через промежуточный буффер (stringstream)
ostringstream sbuf;
......@@ -177,6 +178,7 @@ void LogSession::run()
send = true;
}
}
if( send )
{
*tcp() << sbuf.str();
......@@ -187,7 +189,6 @@ void LogSession::run()
sleep(delayTime);
}
}
}
if( slog.debugging(Debug::INFO) )
slog[Debug::INFO] << peername << "(run): stop thread of sessions..disconnect.." << endl;
......
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