Example #1
0
SessionData* SessionManager::startSession( uint32 token )
{
   SessionData* sd = 0;
   Falcon::String sSID;

   // No one can possibly use this SD as no one can know it.
   sd = createUniqueId( sSID );
   m_mtx.lock();
   m_susers[token].push_back( sd->getWeakRef() );
   // assign the session
   sd->assign( token );
   m_mtx.unlock();

   return sd;
}
Example #2
0
SessionData* SessionManager::startSession( uint32 token, const Falcon::String &sSID )
{
	SessionData* sd = 0;

	m_mtx.lock();
	if ( m_smap.find( sSID ) == m_smap.end() )
	{
	   sd = createSession(sSID);
      m_smap[ sSID ] = sd;
      m_susers[token].push_back( sd->getWeakRef() );
      // assign the session
      sd->assign( token );
	}
   m_mtx.unlock();

	// else, it's still 0
   return sd;
}
Example #3
0
// release all the sessions associated with this token
bool SessionManager::releaseSessions( uint32 token )
{
   m_mtx.lock();
   // do we have the session?
   SessionUserMap::iterator pos = m_susers.find( token );
   if( pos != m_susers.end() )
   {
      // copy the list of sessions to be closed, so that we can work on it.
      SessionList lCopy = pos->second;
      m_susers.erase( pos );
      m_mtx.unlock();


      SessionList::iterator iter = lCopy.begin();
      while( iter != lCopy.end() )
      {
         SessionData::WeakRef* wsd = *iter;
         SessionData* sd = wsd->get();

         // Still a valid reference?
         if( sd != 0 )
         {
            // store on persistent media
            sd->store();

            // mark as used now
            sd->touch();

            // make available for other requests
            m_mtx.lock();
            if( timeout() > 0 )
            {
               m_expmap.insert( ExpirationMap::value_type( sd->lastTouched() + timeout(), sd->getWeakRef() ) );
            }

            sd->release();
            m_mtx.unlock();
            
         }

         wsd->dropped();
         ++iter;
      }
   }
   else
   {
      m_mtx.unlock();
   }

   return true;
}
Example #4
0
SessionData* SessionManager::getSession( const Falcon::String& sSID, uint32 token )
{
   SessionData* sd = 0;
   bool bCreated;
   
   // Should we start a new thread for this?
   if( timeout() > 0 )
      expireOldSessions();

   m_mtx.lock();
   SessionMap::iterator iter = m_smap.find( sSID );
   if( iter != m_smap.end() )
   {
      sd = iter->second;
      if ( sd == 0 || sd->isAssigned() )
      {
         m_mtx.unlock();
         return 0;
      }

      sd->assign( token );
      // We must manipulate m_susers in the lock to prevent concurrent update
      // from other threads.
      m_susers[token].push_back( sd->getWeakRef() );

      // now that the session is assigned, we are free to manipulate it outside the lock.
      m_mtx.unlock();

      bCreated = false;
   }
   else
   {
      // create the session (fast)
      sd = createSession( sSID );
      // assign to our maps
      m_smap[sSID] = sd;
      m_susers[token].push_back( sd->getWeakRef() );
      // assign the session
      sd->assign( token );

      // try to resume after unlock
      m_mtx.unlock();

      bCreated = true;
   }

   // can we resume this session?
   if( ! sd->resume() )
   {
      // all useless work.
      m_mtx.lock();
      m_smap.erase( sSID );
      sd->clearRefs();
      m_mtx.unlock();

      //If the session was created, we should have done it.
      if( ! bCreated )
      {
         sd->setInvalid();
      }
      else
      {
         delete sd;
         sd = 0;
      }
   }

   return sd;
}