Commit 9f437a81 authored by Pavel Vainerman's avatar Pavel Vainerman

(LogServer): починил проверку и переоткрытие сокета в функции check

parent 63ac267d
...@@ -476,7 +476,10 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::preSysCommand( const SystemMessage* ...@@ -476,7 +476,10 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::preSysCommand( const SystemMessage*
} }
if( logserv &amp;&amp; !logserv_host.empty() &amp;&amp; logserv_port != 0 ) if( logserv &amp;&amp; !logserv_host.empty() &amp;&amp; logserv_port != 0 )
{
mylogany &lt;&lt; myname &lt;&lt; "(preSysCommand): try restart logserver.." &lt;&lt; endl;
logserv-&gt;check(true); logserv-&gt;check(true);
}
} }
break; break;
......
...@@ -131,11 +131,15 @@ void LogServer::terminate() ...@@ -131,11 +131,15 @@ void LogServer::terminate()
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
bool LogServer::check( bool restart_if_fail ) bool LogServer::check( bool restart_if_fail )
{ {
// смущает пока только, что эта функция будет вызыватся (обычно) из другого потока
// и как к этому отнесётся evloop
try try
{ {
// для проверки пробуем открыть соединение.. // для проверки пробуем открыть соединение..
UTCPSocket s(addr, port); UTCPStream s;
s.close(); s.create(addr, port, 500);
s.disconnect();
return true; return true;
} }
catch(...) {} catch(...) {}
...@@ -143,17 +147,36 @@ bool LogServer::check( bool restart_if_fail ) ...@@ -143,17 +147,36 @@ bool LogServer::check( bool restart_if_fail )
if( !restart_if_fail ) if( !restart_if_fail )
return false; return false;
io.stop();
if( !sock ) if( !sock )
return false; {
try
{
evprepare(io.loop);
}
catch( UniSetTypes::SystemError& ex )
{
if( mylog.is_crit() )
mylog.crit() << myname << "(evprepare): " << ex << endl;
io.stop(); return false;
io.set<LogServer, &LogServer::ioAccept>(this); }
io.start(sock->getSocket(), ev::READ); }
if( !io.is_active() )
{
io.set<LogServer, &LogServer::ioAccept>(this);
io.start(sock->getSocket(), ev::READ);
isrunning = true;
}
// Проверяем..
try try
{ {
UTCPSocket s(addr, port); UTCPStream s;
s.close(); s.create(addr, port, 500);
s.disconnect();
return true; return true;
} }
catch( Poco::Net::NetException& ex ) catch( Poco::Net::NetException& ex )
......
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