changed: added Cur structure
we have there two pointers: Request * request; Session * session; these are the current request and the current session the session GC was moved to SessionManager (was in SessionContainer) git-svn-id: svn://ttmath.org/publicrep/winix/trunk@708 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -15,17 +15,13 @@
|
||||
|
||||
SessionContainer::SessionContainer()
|
||||
{
|
||||
request = 0;
|
||||
table_size = 0;
|
||||
work_mode = 1; // threading work mode
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void SessionContainer::SetRequest(Request * prequest)
|
||||
void SessionContainer::SetCur(Cur * pcur)
|
||||
{
|
||||
request = prequest;
|
||||
cur = pcur;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,32 +31,55 @@ void SessionContainer::SetConfig(Config * pconfig)
|
||||
}
|
||||
|
||||
|
||||
void SessionContainer::SetTmpSession(Session * psession)
|
||||
{
|
||||
tmp_session = psession;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SessionContainer::Clear()
|
||||
{
|
||||
Table::iterator i = table.begin();
|
||||
|
||||
log << log3 << "SC: deleting all sessions" << logend;
|
||||
|
||||
// don't use table.clear();
|
||||
// because plugins session data would not be erased
|
||||
// we must set cur->session for each session and then delete it
|
||||
while( i != table.end() )
|
||||
{
|
||||
request->session = &(*i);
|
||||
cur->session = &(*i);
|
||||
table.erase(i++);
|
||||
}
|
||||
|
||||
// erasing indexes
|
||||
index_id.clear();
|
||||
table_size = 0;
|
||||
request->session = 0;
|
||||
cur->session = tmp_session;
|
||||
}
|
||||
|
||||
|
||||
void SessionContainer::SetLastContainer(LastContainer * plast_container)
|
||||
|
||||
void SessionContainer::EraseById(IdIterator i)
|
||||
{
|
||||
last_container = plast_container;
|
||||
Session * old_session = tmp_session;
|
||||
|
||||
if( cur->session != &(*i->second) )
|
||||
old_session = cur->session;
|
||||
|
||||
cur->session = &(*i->second);
|
||||
|
||||
log << log4 << "SC: deleting session, id: " << i->second->id << logend;
|
||||
table.erase(i->second);
|
||||
index_id.erase(i);
|
||||
table_size -= 1;
|
||||
|
||||
cur->session = old_session;
|
||||
}
|
||||
|
||||
|
||||
|
||||
size_t SessionContainer::Size()
|
||||
{
|
||||
// don't use table.size() as it has O(n) complexity on FreeBSD
|
||||
@@ -86,6 +105,18 @@ Session & SessionContainer::Back()
|
||||
}
|
||||
|
||||
|
||||
SessionContainer::IdIterator SessionContainer::IdBegin()
|
||||
{
|
||||
return index_id.begin();
|
||||
}
|
||||
|
||||
|
||||
SessionContainer::IdIterator SessionContainer::IdEnd()
|
||||
{
|
||||
return index_id.end();
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool SessionContainer::PushBack(const Session & session)
|
||||
{
|
||||
@@ -128,93 +159,3 @@ return i->second;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* sessions gc (another thread)
|
||||
*
|
||||
*
|
||||
*/
|
||||
void SessionContainer::Work()
|
||||
{
|
||||
bool exit = false;
|
||||
IndexId::iterator i;
|
||||
|
||||
Lock();
|
||||
i = index_id.begin();
|
||||
Unlock();
|
||||
|
||||
while( !exit )
|
||||
{
|
||||
Lock();
|
||||
|
||||
if( i == index_id.end() )
|
||||
{
|
||||
i = index_id.begin();
|
||||
WaitForSignalSleep(10);
|
||||
//WaitForSignalSleep(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( IsSessionOutdated(*i->second) )
|
||||
DeleteSession(i++);
|
||||
else
|
||||
++i;
|
||||
}
|
||||
|
||||
exit = synchro->was_stop_signal;
|
||||
Unlock();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// it's called from the other thread (with Lock and Unlock)
|
||||
bool SessionContainer::IsSessionOutdated(const Session & s) const
|
||||
{
|
||||
bool outdated;
|
||||
|
||||
if( s.remember_me )
|
||||
outdated = s.last_time < std::time(0) - config->session_remember_max_idle;
|
||||
else
|
||||
outdated = s.last_time < std::time(0) - config->session_max_idle;
|
||||
|
||||
return outdated;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// it's called from the other thread (with Lock and Unlock)
|
||||
void SessionContainer::DeleteSession(SessionContainer::IndexId::iterator i)
|
||||
{
|
||||
Session * old_session = 0;
|
||||
Session * del_session = &(*i->second);
|
||||
|
||||
if( del_session != request->session )
|
||||
old_session = request->session;
|
||||
|
||||
request->session = del_session;
|
||||
|
||||
log << log4 << "SessionContainer: deleting outdated session, id: " << del_session->id << logend;
|
||||
|
||||
if( del_session->puser )
|
||||
last_container->UserLogout(del_session->puser->id, del_session->id);
|
||||
|
||||
table.erase(i->second);
|
||||
index_id.erase(i);
|
||||
table_size -= 1;
|
||||
|
||||
// !! tu moze byc zero
|
||||
request->session = old_session;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* end of sessions gc
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user