标签:style http io ar color os sp for on
记录下我们游戏服务器的架构
ListenSocket<ClientSocket> * cl = new ListenSocket<ClientSocket>(host.c_str(), wsport);
sSocketMgr.SpawnWorkerThreads();
bool authsockCreated = cl->IsOpen(); if(authsockCreated ) { #ifdef WIN32 ThreadPool.ExecuteTask(cl); #endif
sLog.outString("Hooking signals..."); signal(SIGINT, _OnSignal); signal(SIGTERM, _OnSignal); signal(SIGABRT, _OnSignal); #ifdef _WIN32 signal(SIGBREAK, _OnSignal); #else signal(SIGHUP, _OnSignal); #endif
/* write pid file */ FILE* fPid = fopen("logonserver.pid", "w"); if(fPid) { uint32 pid; #ifdef WIN32 pid = GetCurrentProcessId(); #else pid = getpid(); #endif fprintf(fPid, "%", (unsigned int)pid); fclose(fPid); }
uint32 loop_counter = 0; //ThreadPool.Gobble(); sLog.outString("Success! Ready fOrconnections"); while(mrunning.GetVal()) { loop_counter++; if (!(loop_counter %2)) // 2s { //sAccountMgr.CheckUpdate(); }
if(!(loop_counter %5)) { //sInfoCore.TimeoutSockets(); sSocketGarbageCollector.Update(); //sSessionsManager.CheckPing();
//CheckForDeadSockets(); // Flood Protection UNIXTIME = time(NULL); g_localTime = *localtime(&UNIXTIME); } if (!(loop_counter %600)) // 10mins { //sAccountMgr.CheckDelete(); }
if(!(loop_counter %300)) // 5mins { ThreadPool.IntegrityCheck(); }
if(!(loop_counter %5)) { UNIXTIME = time(NULL); g_localTime = *localtime(&UNIXTIME); }
Arcemu::Sleep(1000); }
sLog.outString("Shutting down..."); signal(SIGINT, 0); signal(SIGTERM, 0); signal(SIGABRT, 0); #ifdef _WIN32 signal(SIGBREAK, 0); #else signal(SIGHUP, 0); #endif } else { LOG_ERROR("ErrOrcreating sockets. Shutting down..."); }
gr->SetThreadState(THREADSTATE_TERMINATE);
cl->Close();
sSocketMgr.CloseAll(); #ifdef WIN32 sSocketMgr.ShutdownThreads(); #endif
// kill db sLog.outString("Waiting fOrdatabase to close..");
ThreadPool.Shutdown();
Delete ServerConnect::getSingletonPtr();
// Delete pid file remove("logonserver.pid");
Delete SocketMgr::getSingletonPtr(); Delete SocketGarbageCollector::getSingletonPtr(); Delete CSessionsManager::getSingletonPtr(); Delete CMatchManager::getSingletonPtr(); Delete cl;
UnregisterProtocols();
LOG_BASIC("Shutdown complete."); sLog.Close();
Delete CModuleManager::getSingletonPtr(); Delete CRoomManager::getSingletonPtr(); Delete CPlayerManager::getSingletonPtr();
//string host = Config.MainConfig.GetStringDefault("Listen", "Host", DEFAULT_HOST); //int wsport = Config.MainConfig.GetIntDefault("Listen", "WorldServerPort", DEFAULT_WORLDSERVER_PORT);
return true;
转自:http://www.dcscms.com/article/content.php?seq=21
标签:style http io ar color os sp for on
原文地址:http://www.cnblogs.com/mule/p/4132342.html