No longer delay closing of sessions (not needed any more).

This commit is contained in:
lotodore
2007-10-28 15:21:24 +00:00
parent cdea81b2ba
commit f821f9c0a4
2 changed files with 5 additions and 35 deletions
+4 -30
View File
@@ -30,7 +30,6 @@
#include <boost/lambda/lambda.hpp> #include <boost/lambda/lambda.hpp>
#define SERVER_CLOSE_SESSION_DELAY_SEC 1
#define SERVER_MAX_NUM_SESSIONS 512 // Maximum number of idle users in lobby. #define SERVER_MAX_NUM_SESSIONS 512 // Maximum number of idle users in lobby.
#define SERVER_CACHE_CLEANUP_INTERVAL_SEC 86400 // 1 day #define SERVER_CACHE_CLEANUP_INTERVAL_SEC 86400 // 1 day
#define SERVER_INIT_SESSION_TIMEOUT_SEC 20 #define SERVER_INIT_SESSION_TIMEOUT_SEC 20
@@ -116,24 +115,16 @@ void
ServerLobbyThread::RemoveSessionFromGame(SessionWrapper session) ServerLobbyThread::RemoveSessionFromGame(SessionWrapper session)
{ {
// Just remove the session. Only for fatal errors. // Just remove the session. Only for fatal errors.
m_gameSessionManager.RemoveSession(session.sessionData->GetId()); CloseSession(session);
// Update stats (if needed).
BroadcastStatisticsUpdate();
} }
void void
ServerLobbyThread::CloseSessionDelayed(SessionWrapper session) ServerLobbyThread::CloseSession(SessionWrapper session)
{ {
m_initTimerSessionMap.erase(session.sessionData->GetId()); m_initTimerSessionMap.erase(session.sessionData->GetId());
m_sessionManager.RemoveSession(session.sessionData->GetId()); m_sessionManager.RemoveSession(session.sessionData->GetId());
m_gameSessionManager.RemoveSession(session.sessionData->GetId()); m_gameSessionManager.RemoveSession(session.sessionData->GetId());
boost::timers::portable::microsec_timer closeTimer;
CloseSessionList::value_type closeSessionData(closeTimer, session.sessionData);
boost::mutex::scoped_lock lock(m_closeSessionListMutex);
m_closeSessionList.push_back(closeSessionData);
// Update stats (if needed). // Update stats (if needed).
BroadcastStatisticsUpdate(); BroadcastStatisticsUpdate();
} }
@@ -299,10 +290,7 @@ ServerLobbyThread::ProcessLoop()
} catch (const NetException &) } catch (const NetException &)
{ {
// On error: Close this session. // On error: Close this session.
m_initTimerSessionMap.erase(session.sessionData->GetId()); CloseSession(session);
m_sessionManager.RemoveSession(session.sessionData->GetId());
// Update stats (if needed).
BroadcastStatisticsUpdate();
return; return;
} }
if (packet.get()) if (packet.get())
@@ -702,20 +690,6 @@ ServerLobbyThread::CloseSessionLoop()
i = next; i = next;
} }
} }
{
boost::mutex::scoped_lock lock(m_closeSessionListMutex);
CloseSessionList::iterator i = m_closeSessionList.begin();
CloseSessionList::iterator end = m_closeSessionList.end();
while (i != end)
{
CloseSessionList::iterator cur = i++;
if (cur->first.elapsed().total_seconds() >= SERVER_CLOSE_SESSION_DELAY_SEC)
m_closeSessionList.erase(cur);
}
}
} }
void void
@@ -860,7 +834,7 @@ ServerLobbyThread::SessionError(SessionWrapper session, int errorCode)
if (session.sessionData.get()) if (session.sessionData.get())
{ {
SendError(session.sessionData, errorCode); SendError(session.sessionData, errorCode);
CloseSessionDelayed(session); CloseSession(session);
} }
} }
+1 -5
View File
@@ -81,7 +81,6 @@ protected:
typedef std::deque<boost::shared_ptr<ConnectData> > ConnectQueue; typedef std::deque<boost::shared_ptr<ConnectData> > ConnectQueue;
typedef std::deque<SessionWrapper> SessionQueue; typedef std::deque<SessionWrapper> SessionQueue;
typedef std::list<SessionWrapper> SessionList; typedef std::list<SessionWrapper> SessionList;
typedef std::list<std::pair<boost::timers::portable::microsec_timer, boost::shared_ptr<SessionData> > > CloseSessionList;
typedef std::map<SessionId, boost::timers::portable::microsec_timer> InitTimerSessionMap; typedef std::map<SessionId, boost::timers::portable::microsec_timer> InitTimerSessionMap;
typedef std::map<unsigned, boost::shared_ptr<ServerGameThread> > GameMap; typedef std::map<unsigned, boost::shared_ptr<ServerGameThread> > GameMap;
typedef std::list<unsigned> RemoveGameList; typedef std::list<unsigned> RemoveGameList;
@@ -120,7 +119,7 @@ protected:
void CleanupConnectQueue(); void CleanupConnectQueue();
void CleanupSessionMap(); void CleanupSessionMap();
void CloseSessionDelayed(SessionWrapper session); void CloseSession(SessionWrapper session);
void SendError(boost::shared_ptr<SessionData> s, int errorCode); void SendError(boost::shared_ptr<SessionData> s, int errorCode);
void SendJoinGameFailed(boost::shared_ptr<SessionData> s, int reason); void SendJoinGameFailed(boost::shared_ptr<SessionData> s, int reason);
void SendGameList(boost::shared_ptr<SessionData> s); void SendGameList(boost::shared_ptr<SessionData> s);
@@ -152,9 +151,6 @@ private:
InitTimerSessionMap m_initTimerSessionMap; InitTimerSessionMap m_initTimerSessionMap;
CloseSessionList m_closeSessionList;
mutable boost::mutex m_closeSessionListMutex;
RemoveGameList m_removeGameList; RemoveGameList m_removeGameList;
mutable boost::mutex m_removeGameListMutex; mutable boost::mutex m_removeGameListMutex;