Switching from asio deadline_timer to asio steady_timer in order to fix #55. This requires the (boost or native) chrono lib.

This commit is contained in:
lotodore
2014-03-29 16:13:53 +01:00
parent 8a1e3a4371
commit 757f12f35b
17 changed files with 137 additions and 78 deletions
+15 -9
View File
@@ -60,6 +60,12 @@
using namespace std;
using namespace boost::filesystem;
#ifdef BOOST_ASIO_HAS_STD_CHRONO
using namespace std::chrono;
#else
using namespace boost::chrono;
#endif
#define CLIENT_WAIT_TIMEOUT_MSEC 50
#define CLIENT_CONNECT_TIMEOUT_SEC 10
@@ -238,7 +244,7 @@ void
ClientStateDownloadingServerList::Enter(boost::shared_ptr<ClientThread> client)
{
client->GetStateTimer().expires_from_now(
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
client->GetStateTimer().async_wait(
boost::bind(
&ClientStateDownloadingServerList::TimerLoop, this, boost::asio::placeholders::error, client));
@@ -265,7 +271,7 @@ ClientStateDownloadingServerList::TimerLoop(const boost::system::error_code& ec,
client->SetState(ClientStateReadingServerList::Instance());
} else {
client->GetStateTimer().expires_from_now(
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
client->GetStateTimer().async_wait(
boost::bind(
&ClientStateDownloadingServerList::TimerLoop, this, boost::asio::placeholders::error, client));
@@ -409,7 +415,7 @@ void
ClientStateWaitChooseServer::Enter(boost::shared_ptr<ClientThread> client)
{
client->GetStateTimer().expires_from_now(
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
client->GetStateTimer().async_wait(
boost::bind(
&ClientStateWaitChooseServer::TimerLoop, this, boost::asio::placeholders::error, client));
@@ -432,7 +438,7 @@ ClientStateWaitChooseServer::TimerLoop(const boost::system::error_code& ec, boos
client->SetState(ClientStateStartResolve::Instance());
} else {
client->GetStateTimer().expires_from_now(
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
client->GetStateTimer().async_wait(
boost::bind(
&ClientStateWaitChooseServer::TimerLoop, this, boost::asio::placeholders::error, client));
@@ -461,7 +467,7 @@ void
ClientStateStartConnect::Enter(boost::shared_ptr<ClientThread> client)
{
client->GetStateTimer().expires_from_now(
boost::posix_time::seconds(CLIENT_CONNECT_TIMEOUT_SEC));
seconds(CLIENT_CONNECT_TIMEOUT_SEC));
client->GetStateTimer().async_wait(
boost::bind(
&ClientStateStartConnect::TimerTimeout, this, boost::asio::placeholders::error, client));
@@ -986,7 +992,7 @@ void
ClientStateWaitEnterLogin::Enter(boost::shared_ptr<ClientThread> client)
{
client->GetStateTimer().expires_from_now(
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
client->GetStateTimer().async_wait(
boost::bind(
&ClientStateWaitEnterLogin::TimerLoop, this, boost::asio::placeholders::error, client));
@@ -1065,7 +1071,7 @@ ClientStateWaitEnterLogin::TimerLoop(const boost::system::error_code& ec, boost:
}
} else {
client->GetStateTimer().expires_from_now(
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
client->GetStateTimer().async_wait(
boost::bind(
&ClientStateWaitEnterLogin::TimerLoop, this, boost::asio::placeholders::error, client));
@@ -1399,7 +1405,7 @@ void
ClientStateSynchronizeStart::Enter(boost::shared_ptr<ClientThread> client)
{
client->GetStateTimer().expires_from_now(
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
client->GetStateTimer().async_wait(
boost::bind(
&ClientStateSynchronizeStart::TimerLoop, this, boost::asio::placeholders::error, client));
@@ -1429,7 +1435,7 @@ ClientStateSynchronizeStart::TimerLoop(const boost::system::error_code& ec, boos
client->SetState(ClientStateWaitStart::Instance());
} else {
client->GetStateTimer().expires_from_now(
boost::posix_time::milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
milliseconds(CLIENT_WAIT_TIMEOUT_MSEC));
client->GetStateTimer().async_wait(
boost::bind(
&ClientStateSynchronizeStart::TimerLoop, this, boost::asio::placeholders::error, client));
+9 -3
View File
@@ -66,6 +66,12 @@ using namespace std;
using namespace boost::filesystem;
using boost::asio::ip::tcp;
#ifdef BOOST_ASIO_HAS_STD_CHRONO
using namespace std::chrono;
#else
using namespace boost::chrono;
#endif
ClientThread::ClientThread(GuiInterface &gui, AvatarManager &avatarManager, Log *myLog)
: m_ioService(new boost::asio::io_service), m_clientLog(myLog), m_curState(NULL), m_gui(gui),
m_avatarManager(avatarManager), m_isServerSelected(false),
@@ -586,7 +592,7 @@ void
ClientThread::RegisterTimers()
{
m_avatarTimer.expires_from_now(
boost::posix_time::milliseconds(CLIENT_AVATAR_LOOP_MSEC));
milliseconds(CLIENT_AVATAR_LOOP_MSEC));
m_avatarTimer.async_wait(
boost::bind(
&ClientThread::TimerCheckAvatarDownloads, shared_from_this(), boost::asio::placeholders::error));
@@ -910,7 +916,7 @@ ClientThread::TimerCheckAvatarDownloads(const boost::system::error_code& ec)
PassAvatarFileToManager(playerId, tmpAvatar);
}
m_avatarTimer.expires_from_now(
boost::posix_time::milliseconds(CLIENT_AVATAR_LOOP_MSEC));
milliseconds(CLIENT_AVATAR_LOOP_MSEC));
m_avatarTimer.async_wait(
boost::bind(
&ClientThread::TimerCheckAvatarDownloads, shared_from_this(), boost::asio::placeholders::error));
@@ -1022,7 +1028,7 @@ ClientThread::SetState(ClientState &newState)
m_curState->Enter(shared_from_this());
}
boost::asio::deadline_timer &
boost::asio::steady_timer &
ClientThread::GetStateTimer()
{
return m_stateTimer;
+12 -6
View File
@@ -49,6 +49,12 @@
using namespace std;
using namespace boost::filesystem;
#ifdef BOOST_ASIO_HAS_STD_CHRONO
using namespace std::chrono;
#else
using namespace boost::chrono;
#endif
ServerAdminBot::ServerAdminBot(boost::shared_ptr<boost::asio::io_service> ioService)
: m_notifyTimeoutMinutes(0), m_notifyIntervalMinutes(0), m_notifyCounter(0),
m_notifyTimer(boost::posix_time::time_duration(0, 0, 0), boost::timers::portable::second_timer::manual_start),
@@ -272,17 +278,17 @@ ServerAdminBot::Run()
if (m_ircAdminThread) {
// Initialise the timers.
m_reconnectTimer.expires_from_now(
boost::posix_time::seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC));
seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC));
m_reconnectTimer.async_wait(
boost::bind(
&ServerAdminBot::ReconnectHandler, shared_from_this(), boost::asio::placeholders::error));
m_notifyLoopTimer.expires_from_now(
boost::posix_time::seconds(SERVER_NOTIFY_IRC_BOT_INTERVAL_SEC));
seconds(SERVER_NOTIFY_IRC_BOT_INTERVAL_SEC));
m_notifyLoopTimer.async_wait(
boost::bind(
&ServerAdminBot::NotifyLoop, shared_from_this(), boost::asio::placeholders::error));
m_checkFileTimer.expires_from_now(
boost::posix_time::seconds(SERVER_CHECK_IRC_BOT_INTERVAL_SEC));
seconds(SERVER_CHECK_IRC_BOT_INTERVAL_SEC));
m_checkFileTimer.async_wait(
boost::bind(
&ServerAdminBot::CheckFileHandler, shared_from_this(), boost::asio::placeholders::error));
@@ -298,7 +304,7 @@ ServerAdminBot::ReconnectHandler(const boost::system::error_code& ec)
Reconnect();
m_reconnectTimer.expires_from_now(
boost::posix_time::seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC));
seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC));
m_reconnectTimer.async_wait(
boost::bind(
&ServerAdminBot::ReconnectHandler, shared_from_this(), boost::asio::placeholders::error));
@@ -330,7 +336,7 @@ ServerAdminBot::CheckFileHandler(const boost::system::error_code& ec)
Reconnect();
}
m_checkFileTimer.expires_from_now(
boost::posix_time::seconds(SERVER_CHECK_IRC_BOT_INTERVAL_SEC));
seconds(SERVER_CHECK_IRC_BOT_INTERVAL_SEC));
m_checkFileTimer.async_wait(
boost::bind(
&ServerAdminBot::CheckFileHandler, shared_from_this(), boost::asio::placeholders::error));
@@ -386,7 +392,7 @@ ServerAdminBot::NotifyLoop(const boost::system::error_code& ec)
}
}
m_notifyLoopTimer.expires_from_now(
boost::posix_time::seconds(SERVER_NOTIFY_IRC_BOT_INTERVAL_SEC));
seconds(SERVER_NOTIFY_IRC_BOT_INTERVAL_SEC));
m_notifyLoopTimer.async_wait(
boost::bind(
&ServerAdminBot::NotifyLoop, shared_from_this(), boost::asio::placeholders::error));
+12 -7
View File
@@ -34,6 +34,11 @@
using namespace std;
#ifdef BOOST_ASIO_HAS_STD_CHRONO
using namespace std::chrono;
#else
using namespace boost::chrono;
#endif
ServerBanManager::ServerBanManager(boost::shared_ptr<boost::asio::io_service> ioService)
: m_ioService(ioService), m_curBanId(0)
@@ -126,7 +131,7 @@ ServerBanManager::GetBanList(list<string> &list) const
banText << (*i_nick).first << ": (nickStr) - " << (*i_nick).second.nameStr;
if ((*i_nick).second.timer)
banText << " duration: " << (*i_nick).second.timer->expires_from_now().hours() << "h";
banText << " duration: " << duration_cast<hours>((*i_nick).second.timer->expires_from_now()).count() << "h";
list.push_back(banText.str());
++i_nick;
}
@@ -136,7 +141,7 @@ ServerBanManager::GetBanList(list<string> &list) const
ostringstream banText;
banText << (*i_ip).first << ": (IP) - " << (*i_ip).second.ipAddress;
if ((*i_ip).second.timer)
banText << " duration: " << (*i_ip).second.timer->expires_from_now().hours() << "h";
banText << " duration: " << duration_cast<hours>((*i_ip).second.timer->expires_from_now()).count() << "h";
list.push_back(banText.str());
++i_ip;
}
@@ -235,14 +240,14 @@ ServerBanManager::IsBadGameName(const std::string &name) const
return retVal;
}
boost::shared_ptr<boost::asio::deadline_timer>
boost::shared_ptr<boost::asio::steady_timer>
ServerBanManager::InternalRegisterTimedBan(unsigned timerId, unsigned durationHours)
{
boost::shared_ptr<boost::asio::deadline_timer> tmpTimer;
boost::shared_ptr<boost::asio::steady_timer> tmpTimer;
if (durationHours) {
tmpTimer.reset(new boost::asio::deadline_timer(*m_ioService));
tmpTimer.reset(new boost::asio::steady_timer(*m_ioService));
tmpTimer->expires_from_now(
boost::posix_time::hours(durationHours));
hours(durationHours));
tmpTimer->async_wait(
boost::bind(
&ServerBanManager::TimerRemoveBan, shared_from_this(), boost::asio::placeholders::error, timerId, tmpTimer));
@@ -251,7 +256,7 @@ ServerBanManager::InternalRegisterTimedBan(unsigned timerId, unsigned durationHo
}
void
ServerBanManager::TimerRemoveBan(const boost::system::error_code &ec, unsigned banId, boost::shared_ptr<boost::asio::deadline_timer> timer)
ServerBanManager::TimerRemoveBan(const boost::system::error_code &ec, unsigned banId, boost::shared_ptr<boost::asio::steady_timer> timer)
{
if (!ec && timer)
UnBan(banId);
+10 -4
View File
@@ -53,6 +53,12 @@
using namespace std;
#ifdef BOOST_ASIO_HAS_STD_CHRONO
using namespace std::chrono;
#else
using namespace boost::chrono;
#endif
static bool LessThanPlayerHandStartMoney(const boost::shared_ptr<PlayerInterface> p1, const boost::shared_ptr<PlayerInterface> p2)
{
return p1->getMyRoundStartCash() < p2->getMyRoundStartCash();
@@ -276,7 +282,7 @@ ServerGame::TimerVoteKick(const boost::system::error_code &ec)
m_voteKickData.reset();
}
m_voteKickTimer.expires_from_now(
boost::posix_time::milliseconds(SERVER_CHECK_VOTE_KICK_INTERVAL_MSEC));
milliseconds(SERVER_CHECK_VOTE_KICK_INTERVAL_MSEC));
m_voteKickTimer.async_wait(
boost::bind(
&ServerGame::TimerVoteKick, shared_from_this(), boost::asio::placeholders::error));
@@ -514,7 +520,7 @@ ServerGame::InternalAskVoteKick(boost::shared_ptr<SessionData> byWhom, unsigned
SendToAllPlayers(packet, SessionData::Game);
m_voteKickTimer.expires_from_now(
boost::posix_time::milliseconds(SERVER_CHECK_VOTE_KICK_INTERVAL_MSEC));
milliseconds(SERVER_CHECK_VOTE_KICK_INTERVAL_MSEC));
m_voteKickTimer.async_wait(
boost::bind(
&ServerGame::TimerVoteKick, shared_from_this(), boost::asio::placeholders::error));
@@ -1072,13 +1078,13 @@ ServerGame::SetState(ServerGameState &newState)
m_curState->Enter(shared_from_this());
}
boost::asio::deadline_timer &
boost::asio::steady_timer &
ServerGame::GetStateTimer1()
{
return m_stateTimer1;
}
boost::asio::deadline_timer &
boost::asio::steady_timer &
ServerGame::GetStateTimer2()
{
return m_stateTimer2;
+19 -13
View File
@@ -52,6 +52,12 @@
using namespace std;
#ifdef BOOST_ASIO_HAS_STD_CHRONO
using namespace std::chrono;
#else
using namespace boost::chrono;
#endif
//#define POKERTH_SERVER_TEST
#ifdef POKERTH_SERVER_TEST
@@ -570,7 +576,7 @@ ServerGameStateInit::RegisterAdminTimer(boost::shared_ptr<ServerGame> server)
// No admin timeout in LAN or ranking games.
if (server->GetLobbyThread().GetServerMode() != SERVER_MODE_LAN && server->GetGameData().gameType != GAME_TYPE_RANKING) {
server->GetStateTimer1().expires_from_now(
boost::posix_time::seconds(SERVER_GAME_ADMIN_TIMEOUT_SEC - SERVER_GAME_ADMIN_WARNING_REMAINING_SEC));
seconds(SERVER_GAME_ADMIN_TIMEOUT_SEC - SERVER_GAME_ADMIN_WARNING_REMAINING_SEC));
server->GetStateTimer1().async_wait(
boost::bind(
&ServerGameStateInit::TimerAdminWarning, this, boost::asio::placeholders::error, server));
@@ -589,7 +595,7 @@ ServerGameStateInit::RegisterAutoStartTimer(boost::shared_ptr<ServerGame> server
// No autostart in LAN games.
if (server->GetLobbyThread().GetServerMode() != SERVER_MODE_LAN) {
server->GetStateTimer2().expires_from_now(
boost::posix_time::seconds(SERVER_AUTOSTART_GAME_DELAY_SEC));
seconds(SERVER_AUTOSTART_GAME_DELAY_SEC));
server->GetStateTimer2().async_wait(
boost::bind(
&ServerGameStateInit::TimerAutoStart, this, boost::asio::placeholders::error, server));
@@ -627,7 +633,7 @@ ServerGameStateInit::TimerAdminWarning(const boost::system::error_code &ec, boos
}
// Start timeout timer.
server->GetStateTimer1().expires_from_now(
boost::posix_time::seconds(SERVER_GAME_ADMIN_WARNING_REMAINING_SEC));
seconds(SERVER_GAME_ADMIN_WARNING_REMAINING_SEC));
server->GetStateTimer1().async_wait(
boost::bind(
&ServerGameStateInit::TimerAdminTimeout, this, boost::asio::placeholders::error, server));
@@ -762,7 +768,7 @@ void
ServerGameStateStartGame::Enter(boost::shared_ptr<ServerGame> server)
{
server->GetStateTimer1().expires_from_now(
boost::posix_time::seconds(SERVER_START_GAME_TIMEOUT_SEC));
seconds(SERVER_START_GAME_TIMEOUT_SEC));
server->GetStateTimer1().async_wait(
boost::bind(
&ServerGameStateStartGame::TimerTimeout, this, boost::asio::placeholders::error, server));
@@ -925,7 +931,7 @@ void
ServerGameStateHand::Enter(boost::shared_ptr<ServerGame> server)
{
server->GetStateTimer1().expires_from_now(
boost::posix_time::milliseconds(SERVER_LOOP_DELAY_MSEC));
milliseconds(SERVER_LOOP_DELAY_MSEC));
server->GetStateTimer1().async_wait(
boost::bind(
&ServerGameStateHand::TimerLoop, this, boost::asio::placeholders::error, server));
@@ -1002,7 +1008,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
curGame.getCurrentHand()->setCardsShown(true);
server->GetStateTimer1().expires_from_now(
boost::posix_time::seconds(SERVER_SHOW_CARDS_DELAY_SEC));
seconds(SERVER_SHOW_CARDS_DELAY_SEC));
server->GetStateTimer1().async_wait(
boost::bind(
&ServerGameStateHand::TimerShowCards, this, boost::asio::placeholders::error, server));
@@ -1010,7 +1016,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
SendNewRoundCards(*server, curGame, newRound);
server->GetStateTimer1().expires_from_now(
boost::posix_time::seconds(GetDealCardsDelaySec(*server)));
seconds(GetDealCardsDelaySec(*server)));
server->GetStateTimer1().async_wait(
boost::bind(
&ServerGameStateHand::TimerLoop, this, boost::asio::placeholders::error, server));
@@ -1038,7 +1044,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
// If the player is computer controlled, let the engine act.
if (curPlayer->getMyType() == PLAYER_TYPE_COMPUTER) {
server->GetStateTimer1().expires_from_now(
boost::posix_time::seconds(SERVER_COMPUTER_ACTION_DELAY_SEC));
seconds(SERVER_COMPUTER_ACTION_DELAY_SEC));
server->GetStateTimer1().async_wait(
boost::bind(
&ServerGameStateHand::TimerComputerAction, this, boost::asio::placeholders::error, server));
@@ -1049,7 +1055,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
PerformPlayerAction(*server, curPlayer, PLAYER_ACTION_FOLD, 0);
server->GetStateTimer1().expires_from_now(
boost::posix_time::milliseconds(SERVER_LOOP_DELAY_MSEC));
milliseconds(SERVER_LOOP_DELAY_MSEC));
server->GetStateTimer1().async_wait(
boost::bind(
&ServerGameStateHand::TimerLoop, this, boost::asio::placeholders::error, server));
@@ -1117,7 +1123,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
// View a dialog for a new game - delayed.
server->GetStateTimer1().expires_from_now(
boost::posix_time::seconds(SERVER_DELAY_NEXT_GAME_SEC));
seconds(SERVER_DELAY_NEXT_GAME_SEC));
server->GetStateTimer1().async_wait(
boost::bind(
&ServerGameStateHand::TimerNextGame, this, boost::asio::placeholders::error, server, winnerPlayer->getMyUniqueID()));
@@ -1136,7 +1142,7 @@ ServerGameStateHand::TimerShowCards(const boost::system::error_code &ec, boost::
SendNewRoundCards(*server, curGame, curGame.getCurrentHand()->getCurrentRound());
server->GetStateTimer1().expires_from_now(
boost::posix_time::seconds(GetDealCardsDelaySec(*server)));
seconds(GetDealCardsDelaySec(*server)));
server->GetStateTimer1().async_wait(
boost::bind(
&ServerGameStateHand::TimerLoop, this, boost::asio::placeholders::error, server));
@@ -1507,7 +1513,7 @@ ServerGameStateWaitPlayerAction::Enter(boost::shared_ptr<ServerGame> server)
int timeoutSec = server->GetGameData().playerActionTimeoutSec + SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC;
#endif
server->GetStateTimer1().expires_from_now(boost::posix_time::seconds(timeoutSec));
server->GetStateTimer1().expires_from_now(seconds(timeoutSec));
server->GetStateTimer1().async_wait(
boost::bind(
&ServerGameStateWaitPlayerAction::TimerTimeout, this, boost::asio::placeholders::error, server));
@@ -1641,7 +1647,7 @@ ServerGameStateWaitNextHand::Enter(boost::shared_ptr<ServerGame> server)
#endif
server->GetStateTimer1().expires_from_now(
boost::posix_time::seconds(timeoutSec));
seconds(timeoutSec));
server->GetStateTimer1().async_wait(
boost::bind(
+8 -2
View File
@@ -45,6 +45,12 @@
using namespace std;
#ifdef BOOST_ASIO_HAS_STD_CHRONO
using namespace std::chrono;
#else
using namespace boost::chrono;
#endif
ServerLobbyBot::ServerLobbyBot(boost::shared_ptr<boost::asio::io_service> ioService)
: m_reconnectTimer(*ioService)
{
@@ -110,7 +116,7 @@ ServerLobbyBot::Run()
if (m_ircLobbyThread) {
// Initialise the reconnect timer.
m_reconnectTimer.expires_from_now(
boost::posix_time::seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC));
seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC));
m_reconnectTimer.async_wait(
boost::bind(
&ServerLobbyBot::Reconnect, shared_from_this(), boost::asio::placeholders::error));
@@ -132,7 +138,7 @@ ServerLobbyBot::Reconnect(const boost::system::error_code& ec)
}
}
m_reconnectTimer.expires_from_now(
boost::posix_time::seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC));
seconds(SERVER_RESTART_IRC_BOT_INTERVAL_SEC));
m_reconnectTimer.async_wait(
boost::bind(
&ServerLobbyBot::Reconnect, shared_from_this(), boost::asio::placeholders::error));
+11 -6
View File
@@ -95,6 +95,11 @@
using namespace std;
using boost::asio::ip::tcp;
#ifdef BOOST_ASIO_HAS_STD_CHRONO
using namespace std::chrono;
#else
using namespace boost::chrono;
#endif
class InternalServerCallback : public SessionDataCallback, public ChatCleanerCallback, public ServerDBCallback
{
@@ -859,19 +864,19 @@ ServerLobbyThread::RegisterTimers()
{
// Remove closed games.
m_removeGameTimer.expires_from_now(
boost::posix_time::milliseconds(SERVER_REMOVE_GAME_INTERVAL_MSEC));
milliseconds(SERVER_REMOVE_GAME_INTERVAL_MSEC));
m_removeGameTimer.async_wait(
boost::bind(
&ServerLobbyThread::TimerRemoveGame, shared_from_this(), boost::asio::placeholders::error));
// Update the statistics file.
m_saveStatisticsTimer.expires_from_now(
boost::posix_time::seconds(SERVER_SAVE_STATISTICS_INTERVAL_SEC));
seconds(SERVER_SAVE_STATISTICS_INTERVAL_SEC));
m_saveStatisticsTimer.async_wait(
boost::bind(
&ServerLobbyThread::TimerSaveStatisticsFile, shared_from_this(), boost::asio::placeholders::error));
// Update the avatar upload locks.
m_loginLockTimer.expires_from_now(
boost::posix_time::milliseconds(SERVER_UPDATE_LOGIN_LOCK_INTERVAL_MSEC));
milliseconds(SERVER_UPDATE_LOGIN_LOCK_INTERVAL_MSEC));
m_loginLockTimer.async_wait(
boost::bind(
&ServerLobbyThread::TimerUpdateClientLoginLock, shared_from_this(), boost::asio::placeholders::error));
@@ -1859,7 +1864,7 @@ ServerLobbyThread::TimerRemoveGame(const boost::system::error_code &ec)
}
// Restart timer
m_removeGameTimer.expires_from_now(
boost::posix_time::milliseconds(SERVER_REMOVE_GAME_INTERVAL_MSEC));
milliseconds(SERVER_REMOVE_GAME_INTERVAL_MSEC));
m_removeGameTimer.async_wait(
boost::bind(
&ServerLobbyThread::TimerRemoveGame, shared_from_this(), boost::asio::placeholders::error));
@@ -1884,7 +1889,7 @@ ServerLobbyThread::TimerUpdateClientLoginLock(const boost::system::error_code &e
}
// Restart timer
m_loginLockTimer.expires_from_now(
boost::posix_time::milliseconds(SERVER_UPDATE_LOGIN_LOCK_INTERVAL_MSEC));
milliseconds(SERVER_UPDATE_LOGIN_LOCK_INTERVAL_MSEC));
m_loginLockTimer.async_wait(
boost::bind(
&ServerLobbyThread::TimerUpdateClientLoginLock, shared_from_this(), boost::asio::placeholders::error));
@@ -2231,7 +2236,7 @@ ServerLobbyThread::TimerSaveStatisticsFile(const boost::system::error_code &ec)
}
// Restart timer
m_saveStatisticsTimer.expires_from_now(
boost::posix_time::seconds(SERVER_SAVE_STATISTICS_INTERVAL_SEC));
seconds(SERVER_SAVE_STATISTICS_INTERVAL_SEC));
m_saveStatisticsTimer.async_wait(
boost::bind(
&ServerLobbyThread::TimerSaveStatisticsFile, shared_from_this(), boost::asio::placeholders::error));
+11 -5
View File
@@ -41,6 +41,12 @@
using namespace std;
using boost::asio::ip::tcp;
#ifdef BOOST_ASIO_HAS_STD_CHRONO
using namespace std::chrono;
#else
using namespace boost::chrono;
#endif
SessionData::SessionData(boost::shared_ptr<boost::asio::ip::tcp::socket> sock, SessionId id, SessionDataCallback &cb, boost::asio::io_service &ioService)
: m_socket(sock), m_id(id), m_state(SessionData::Init), m_readyFlag(false), m_wantsLobbyMsg(true),
m_activityTimeoutSec(0), m_activityWarningRemainingSec(0), m_initTimeoutTimer(ioService), m_globalTimeoutTimer(ioService),
@@ -236,7 +242,7 @@ SessionData::TimerActivityWarning(const boost::system::error_code &ec)
m_callback.SessionTimeoutWarning(shared_from_this(), m_activityWarningRemainingSec);
m_activityTimeoutTimer.expires_from_now(
boost::posix_time::seconds(m_activityWarningRemainingSec));
seconds(m_activityWarningRemainingSec));
m_activityTimeoutTimer.async_wait(
boost::bind(
&SessionData::TimerSessionTimeout, shared_from_this(), boost::asio::placeholders::error));
@@ -322,7 +328,7 @@ SessionData::ResetActivityTimer()
{
boost::mutex::scoped_lock lock(m_dataMutex);
m_activityTimeoutTimer.expires_from_now(
boost::posix_time::seconds(m_activityTimeoutSec - m_activityWarningRemainingSec));
seconds(m_activityTimeoutSec - m_activityWarningRemainingSec));
m_activityTimeoutTimer.async_wait(
boost::bind(
&SessionData::TimerActivityWarning, shared_from_this(), boost::asio::placeholders::error));
@@ -333,7 +339,7 @@ SessionData::StartTimerInitTimeout(unsigned timeoutSec)
{
boost::mutex::scoped_lock lock(m_dataMutex);
m_initTimeoutTimer.expires_from_now(
boost::posix_time::seconds(timeoutSec));
seconds(timeoutSec));
m_initTimeoutTimer.async_wait(
boost::bind(
&SessionData::TimerInitTimeout, shared_from_this(), boost::asio::placeholders::error));
@@ -344,7 +350,7 @@ SessionData::StartTimerGlobalTimeout(unsigned timeoutSec)
{
boost::mutex::scoped_lock lock(m_dataMutex);
m_globalTimeoutTimer.expires_from_now(
boost::posix_time::seconds(timeoutSec));
seconds(timeoutSec));
m_globalTimeoutTimer.async_wait(
boost::bind(
&SessionData::TimerSessionTimeout, shared_from_this(), boost::asio::placeholders::error));
@@ -358,7 +364,7 @@ SessionData::StartTimerActivityTimeout(unsigned timeoutSec, unsigned warningRema
m_activityWarningRemainingSec = warningRemainingSec;
m_activityTimeoutTimer.expires_from_now(
boost::posix_time::seconds(timeoutSec - warningRemainingSec));
seconds(timeoutSec - warningRemainingSec));
m_activityTimeoutTimer.async_wait(
boost::bind(
&SessionData::TimerActivityWarning, shared_from_this(), boost::asio::placeholders::error));