Exemple #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;
}
Exemple #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;
}
Exemple #3
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;
}