Commit 98b2caf9 authored by Pavel Vainerman's avatar Pavel Vainerman

(ULogServer): добавил возможность настраивать timeout-ы для сессий

parent d2f864c5
...@@ -124,7 +124,7 @@ int main( int argc, char **argv ) ...@@ -124,7 +124,7 @@ int main( int argc, char **argv )
data = (int)Debug::value(sdata); data = (int)Debug::value(sdata);
if( verb ) if( verb )
cout << "SEND COMMAND: '" << (LogServerTypes::Command)cmd << " data='" << sdata << "'" << endl; cout << "SEND COMMAND: '" << (LogServerTypes::Command)cmd << " data='" << sdata << "'" << endl;
} }
lr.readlogs( addr, port, (LogServerTypes::Command)cmd, data, verb ); lr.readlogs( addr, port, (LogServerTypes::Command)cmd, data, verb );
......
...@@ -17,6 +17,10 @@ class LogServer ...@@ -17,6 +17,10 @@ class LogServer
LogServer( DebugStream& log ); LogServer( DebugStream& log );
~LogServer(); ~LogServer();
inline void setSessionTimeout( timeout_t msec ){ sessTimeout = msec; }
inline void setCmdTimeout( timeout_t msec ){ cmdTimeout = msec; }
inline void setOutTimeout( timeout_t msec ){ outTimeout = msec; }
void run( const std::string& addr, ost::tpport_t port, bool thread=true ); void run( const std::string& addr, ost::tpport_t port, bool thread=true );
protected: protected:
...@@ -31,7 +35,10 @@ class LogServer ...@@ -31,7 +35,10 @@ class LogServer
UniSetTypes::uniset_rwmutex mutSList; UniSetTypes::uniset_rwmutex mutSList;
timeout_t timeout; timeout_t timeout;
timeout_t session_timeout; timeout_t sessTimeout;
timeout_t cmdTimeout;
timeout_t outTimeout;
std::atomic_bool cancelled; std::atomic_bool cancelled;
DebugStream mylog; DebugStream mylog;
ThreadCreator<LogServer>* thr; ThreadCreator<LogServer>* thr;
......
...@@ -14,7 +14,7 @@ class LogSession: ...@@ -14,7 +14,7 @@ class LogSession:
{ {
public: public:
LogSession( ost::TCPSocket &server, DebugStream* log, timeout_t timeout ); LogSession( ost::TCPSocket &server, DebugStream* log, timeout_t sessTimeout=10000, timeout_t cmdTimeout=2000, timeout_t outTimeout=2000 );
virtual ~LogSession(); virtual ~LogSession();
typedef sigc::slot<void, LogSession*> FinalSlot; typedef sigc::slot<void, LogSession*> FinalSlot;
...@@ -34,7 +34,9 @@ class LogSession: ...@@ -34,7 +34,9 @@ class LogSession:
std::string caddr; std::string caddr;
DebugStream* log; DebugStream* log;
timeout_t timeout; timeout_t sessTimeout;
timeout_t cmdTimeout;
timeout_t outTimeout;
PassiveTimer ptSessionTimeout; PassiveTimer ptSessionTimeout;
FinalSlot slFin; FinalSlot slFin;
......
...@@ -26,7 +26,9 @@ LogServer::~LogServer() ...@@ -26,7 +26,9 @@ LogServer::~LogServer()
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
LogServer::LogServer( DebugStream& log ): LogServer::LogServer( DebugStream& log ):
timeout(TIMEOUT_INF), timeout(TIMEOUT_INF),
session_timeout(3600000), sessTimeout(3600000),
cmdTimeout(2000),
outTimeout(2000),
cancelled(false), cancelled(false),
thr(0), thr(0),
tcp(0), tcp(0),
...@@ -36,7 +38,9 @@ elog(&log) ...@@ -36,7 +38,9 @@ elog(&log)
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
LogServer::LogServer(): LogServer::LogServer():
timeout(TIMEOUT_INF), timeout(TIMEOUT_INF),
session_timeout(3600000), sessTimeout(3600000),
cmdTimeout(2000),
outTimeout(2000),
cancelled(false), cancelled(false),
thr(0), thr(0),
tcp(0), tcp(0),
...@@ -86,7 +90,7 @@ void LogServer::work() ...@@ -86,7 +90,7 @@ void LogServer::work()
{ {
while( tcp->isPendingConnection(timeout) ) while( tcp->isPendingConnection(timeout) )
{ {
LogSession* s = new LogSession(*tcp, elog, session_timeout); LogSession* s = new LogSession(*tcp, elog, sessTimeout, cmdTimeout, outTimeout);
{ {
uniset_rwmutex_wrlock l(mutSList); uniset_rwmutex_wrlock l(mutSList);
slist.push_back(s); slist.push_back(s);
......
...@@ -21,12 +21,14 @@ LogSession::~LogSession() ...@@ -21,12 +21,14 @@ LogSession::~LogSession()
} }
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
LogSession::LogSession( ost::TCPSocket &server, DebugStream* _log, timeout_t msec ): LogSession::LogSession( ost::TCPSocket &server, DebugStream* _log, timeout_t _sessTimeout, timeout_t _cmdTimeout, timeout_t _outTimeout ):
TCPSession(server), TCPSession(server),
peername(""), peername(""),
caddr(""), caddr(""),
log(_log), log(_log),
timeout(msec), sessTimeout(_sessTimeout),
cmdTimeout(_cmdTimeout),
outTimeout(_outTimeout),
cancelled(false) cancelled(false)
{ {
// slog.addLevel(Debug::ANY); // slog.addLevel(Debug::ANY);
...@@ -59,14 +61,12 @@ void LogSession::run() ...@@ -59,14 +61,12 @@ void LogSession::run()
if( slog.debugging(Debug::INFO) ) if( slog.debugging(Debug::INFO) )
slog[Debug::INFO] << peername << "(run): run thread of sessions.." << endl; slog[Debug::INFO] << peername << "(run): run thread of sessions.." << endl;
ptSessionTimeout.setTiming(10000); ptSessionTimeout.setTiming(sessTimeout);
timeout_t inTimeout = 2000;
timeout_t outTimeout = 2000;
string oldLogFile( log->getLogFile() ); string oldLogFile( log->getLogFile() );
// Команды могут посылаться только в начале сессии.. // Команды могут посылаться только в начале сессии..
if( isPending(Socket::pendingInput, inTimeout) ) if( isPending(Socket::pendingInput, cmdTimeout) )
{ {
LogServerTypes::lsMessage msg; LogServerTypes::lsMessage msg;
// проверяем канал..(если данных нет, значит "клиент отвалился"... // проверяем канал..(если данных нет, значит "клиент отвалился"...
...@@ -167,7 +167,7 @@ void LogSession::run() ...@@ -167,7 +167,7 @@ void LogSession::run()
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
void LogSession::final() void LogSession::final()
{ {
*tcp() << endl; tcp()->sync();
slFin(this); slFin(this);
delete this; delete this;
} }
......
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