Beispiel #1
0
bool SessionManager::closeSession( const String& sSID, uint32 token )
{
   m_mtx.lock();
   SessionMap::iterator iter = m_smap.find( sSID );
   if( iter != m_smap.end() )
   {
      SessionData* sd = iter->second;
      m_smap.erase( sSID );
      sd->clearRefs();
      m_mtx.unlock();

      sd->dispose();
      delete sd;
      return true;
   }

   m_mtx.unlock();
   return false;
}
Beispiel #2
0
void SessionManager::expireOldSessions()
{
   numeric now = Sys::_seconds();

   std::deque<SessionData*> expiredSessions;
   m_mtx.lock();
   while( ! m_expmap.empty() && m_expmap.begin()->first < now )
   {
      SessionData::WeakRef* wsd = m_expmap.begin()->second;
      SessionData* sd = wsd->get();
      
      // Is the session still alive?
      if ( sd != 0 && sd->lastTouched() + timeout() < now )
      {
         // the data is dead, so we remove it now from the available map
         m_smap.erase( sd->sID() );

         // prevents others (and ourselves) to use it again
         sd->clearRefs();

         // and we push it aside for later clearing
         expiredSessions.push_back( sd );
      }

      // also, take it away from our expired data
      m_expmap.erase( m_expmap.begin() );
   }

   m_mtx.unlock();

   // now we can destroy the expired sessions
   std::deque<SessionData*>::iterator elem = expiredSessions.begin();
   while( elem != expiredSessions.end() )
   {
      SessionData* sd = *elem;
      sd->dispose();
      delete sd;
      ++elem;
   }
}