int main(int argc, char* argv[]) { static const ACE_TCHAR options[] = ACE_TEXT (":i:"); ACE_Get_Opt cmd_opts(argc, argv, options); int option; ACE_TCHAR optValue[1024]; while((option = cmd_opts())!=EOF) { switch(option) { case 'i': ACE_OS_String::strncpy(optValue, cmd_opts.opt_arg(), 1024); break; default: break; } } if(ACE_OS_String::strcmp(optValue, "S") == 0) { main_accept(); } else if(ACE_OS_String::strcmp(optValue, "C") == 0) { main_connect(); } return 0; };
int MeshTest::open(int argc, char** argv, Stheno* runtime) { printf("Open RPC test...\n"); m_runtime = runtime; m_ft = false; m_invocations = 0; m_replicasNo = 0; static const ACE_TCHAR options[] = ACE_TEXT("::"); ACE_Get_Opt cmd_opts(argc, argv, options); if (cmd_opts.long_option (ACE_TEXT("ft"), 'f', ACE_Get_Opt::ARG_REQUIRED) == -1) return -1; if (cmd_opts.long_option (ACE_TEXT("rpc"), 'r', ACE_Get_Opt::ARG_REQUIRED) == -1) return -1; //Touch of Death if (cmd_opts.long_option (ACE_TEXT("tod"), ACE_Get_Opt::NO_ARG) == -1) return -1; int option; m_tod = false; while ((option = cmd_opts()) != EOF) switch (option) { case 0: { //long_option const char *op = cmd_opts.long_option(); if (ACE_OS::strcmp("tod", op) == 0) { m_tod = true; break; } } case 'r': { const char *op = cmd_opts.opt_arg(); m_invocations = Integer::parseInt(op, 10); printf("%d invocations will be performed.\n", m_invocations); break; } case 'f': { const char *op = cmd_opts.opt_arg(); m_ft = true; m_replicasNo = Integer::parseInt(op, 10); break; } } CPUQoS* cpuQoS = new CPUPriorityQoS(CPUQoS::SCHEDULE_RT_DEFAULT, CPUQoS::MAX_RT_PRIO); CPUReservation* reserve = 0; return this->activate(reserve, cpuQoS); }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { // Example for a long option without a corresponding short option. // Just put some context here so the following compiles and runs. static const ACE_TCHAR options[] = ACE_TEXT (":f:"); ACE_Get_Opt cmd_opts (argc, argv, options); // Listing 1 code/ch04 cmd_opts.long_option (ACE_TEXT ("cool_option")); cmd_opts.long_option (ACE_TEXT ("the_answer"), 42); // Listing 1 int option; ACE_TCHAR config_file[MAXPATHLEN]; ACE_OS_String::strcpy (config_file, ACE_TEXT ("HAStatus.conf")); while ((option = cmd_opts ()) != EOF) switch (option) { case 'f': ACE_OS_String::strncpy (config_file, cmd_opts.opt_arg (), MAXPATHLEN); break; // Listing 2 code/ch04 case 0: ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Yes, very cool.\n"))); break; case 42: ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("the_answer is 42\n"))); break; // Listing 2 case ':': ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("-%c requires an argument\n"), cmd_opts.opt_opt ()), -1); default: ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Parse error.\n")), -1); } return 0; }
int ACE_TMAIN (int, ACE_TCHAR *[]) { static const ACE_TCHAR options[] = ACE_TEXT (":f:h:"); static const ACE_TCHAR cmdline[] = ACE_TEXT ("-f /home/managed.cfg -h $HOSTNAME"); ACE_ARGV cmdline_args (cmdline); ACE_Get_Opt cmd_opts (cmdline_args.argc (), cmdline_args.argv (), options, 0); // Don't skip any args // Listing 1 int option; ACE_TCHAR config_file[MAXPATHLEN]; ACE_TCHAR hostname[MAXHOSTNAMELEN]; ACE_OS_String::strcpy (config_file, ACE_TEXT ("HAStatus.conf")); ACE_OS_String::strcpy (hostname, ACE_TEXT ("not set")); while ((option = cmd_opts ()) != EOF) switch (option) { case 'f': ACE_OS_String::strncpy (config_file, cmd_opts.opt_arg (), MAXPATHLEN); break; case 'h': ACE_OS_String::strncpy (hostname, cmd_opts.opt_arg (), MAXHOSTNAMELEN); break; case ':': ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("-%c requires an argument\n"), cmd_opts.opt_opt ()), -1); default: ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Parse error.\n")), -1); } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Config file: %s\n"), config_file)); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Hostname: %s\n"), hostname)); return 0; }
/// Launch the mangos server extern int main(int argc, char** argv) { ///- Command line parsing char const* cfg_file = _MANGOSD_CONFIG; char const* options = ":a:c:s:"; ACE_Get_Opt cmd_opts(argc, argv, options); cmd_opts.long_option("version", 'v', ACE_Get_Opt::NO_ARG); cmd_opts.long_option("ahbot", 'a', ACE_Get_Opt::ARG_REQUIRED); char serviceDaemonMode = '\0'; int option; while ((option = cmd_opts()) != EOF) { switch (option) { case 'a': sAuctionBotConfig.SetConfigFileName(cmd_opts.opt_arg()); break; case 'c': cfg_file = cmd_opts.opt_arg(); break; case 'v': printf("%s\n", _FULLVERSION(REVISION_DATE, REVISION_TIME, REVISION_NR, REVISION_ID)); return 0; case 's': { const char* mode = cmd_opts.opt_arg(); if (!strcmp(mode, "run")) { serviceDaemonMode = 'r'; } #ifdef WIN32 else if (!strcmp(mode, "install")) { serviceDaemonMode = 'i'; } else if (!strcmp(mode, "uninstall")) { serviceDaemonMode = 'u'; } #else else if (!strcmp(mode, "stop")) { serviceDaemonMode = 's'; } #endif else { sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode); usage(argv[0]); Log::WaitBeforeContinueIfNeed(); return 1; } break; } case ':': sLog.outError("Runtime-Error: -%c option requires an input argument", cmd_opts.opt_opt()); usage(argv[0]); Log::WaitBeforeContinueIfNeed(); return 1; default: sLog.outError("Runtime-Error: bad format of commandline arguments"); usage(argv[0]); Log::WaitBeforeContinueIfNeed(); return 1; } } #ifdef WIN32 // windows service command need execute before config read switch (serviceDaemonMode) { case 'i': if (WinServiceInstall()) { sLog.outString("Installing service"); } return 1; case 'u': if (WinServiceUninstall()) { sLog.outString("Uninstalling service"); } return 1; case 'r': WinServiceRun(); break; } #endif if (!sConfig.SetSource(cfg_file)) { sLog.outError("Could not find configuration file %s.", cfg_file); Log::WaitBeforeContinueIfNeed(); return 1; } #ifndef WIN32 // posix daemon commands need apply after config read switch (serviceDaemonMode) { case 'r': startDaemon(); break; case 's': stopDaemon(); break; } #endif sLog.outString("%s [world-daemon]", _FULLVERSION(REVISION_DATE, REVISION_TIME, REVISION_NR, REVISION_ID)); sLog.outString("<Ctrl-C> to stop.\n" " __ __ _ _ ___ ___ ___ \n" " | \\/ |__ _| \\| |/ __|/ _ \\/ __| \n" " | |\\/| / _` | .` | (_ | (_) \\__ \\ \n" " |_| |_\\__,_|_|\\_|\\___|\\___/|___/ \n" " ___ \n" " Visit our website for support: |_ /___ _ _ ___ \n" " http://getmangos.com/ / // -_) '_/ _ \\ \n" " /___\\___|_| \\___/ \n" " We love vanilla WoW! \n" ); sLog.outString("Using configuration file %s.", cfg_file); DETAIL_LOG("%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION)); if (SSLeay() < 0x009080bfL) { DETAIL_LOG("WARNING: Outdated version of OpenSSL lib. Logins to server may not work!"); DETAIL_LOG("WARNING: Minimal required version [OpenSSL 0.9.8k]"); } DETAIL_LOG("Using ACE: %s", ACE_VERSION); ///- Set progress bars show mode BarGoLink::SetOutputState(sConfig.GetBoolDefault("ShowProgressBars", true)); ///- and run the 'Master' /// \todo Why do we need this 'Master'? Can't all of this be in the Main as for Realmd? return sMaster.Run(); // at sMaster return function exist with codes // 0 - normal shutdown // 1 - shutdown at error // 2 - restart command used, this code can be used by restarter for restart mangosd }
// Launch the auth server extern int main(int argc, char **argv) { // Command line parsing char const* cfg_file = _DARMIX_REALM_CONFIG; #ifdef _WIN32 char const *options = ":c:s:"; #else char const *options = ":c:"; #endif ACE_Get_Opt cmd_opts(argc, argv, options); cmd_opts.long_option("version", 'v'); int option; while ((option = cmd_opts()) != EOF) { switch (option) { case 'c': cfg_file = cmd_opts.opt_arg(); break; case 'v': printf("%s\n", _FULLVERSION); return 0; #ifdef _WIN32 case 's': { const char *mode = cmd_opts.opt_arg(); if (!strcmp(mode, "install")) { if (WinServiceInstall()) sLog.outString("Installing service"); return 1; } else if (!strcmp(mode, "uninstall")) { if (WinServiceUninstall()) sLog.outString("Uninstalling service"); return 1; } else if (!strcmp(mode, "run")) WinServiceRun(); else { sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode); usage(argv[0]); return 1; } break; } #endif case ':': sLog.outError("Runtime-Error: -%c option requires an input argument", cmd_opts.opt_opt()); usage(argv[0]); return 1; default: sLog.outError("Runtime-Error: bad format of commandline arguments"); usage(argv[0]); return 1; } } if (!sConfig.SetSource(cfg_file)) { sLog.outError("Invalid or missing configuration file : %s", cfg_file); sLog.outError("Verify that the file exists and has \'[realm-server]\' written in the top of the file!"); return 1; } sLog.Initialize(); sLog.outString("*************************************************************************"); sLog.outString(" %s(realm) Rev: %s Hash: %s ", _PACKAGENAME, _REVISION, _HASH); sLog.outString("*************************************************************************"); sLog.outString("<Ctrl-C> to stop."); sLog.outString(" "); // Check the version of the configuration file uint32 confVersion = sConfig.GetIntDefault("ConfVersion", 0); if (confVersion != _DARMIX_REALM_CONFVER) { sLog.outError(" WARNING:"); sLog.outError(" Your %s file is out of date.", cfg_file); sLog.outError(" Please, check for updates."); sleep(5); } sLog.outDetail("Using ACE: %s", ACE_VERSION); #if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL) ACE_Reactor::instance(new ACE_Reactor(new ACE_Dev_Poll_Reactor(ACE::max_handles(), 1), 1), true); #else ACE_Reactor::instance(new ACE_Reactor(new ACE_TP_Reactor(), true), true); #endif sLog.outBasic("Max allowed open files is %d", ACE::max_handles()); // RealmServer PID file creation std::string pidfile = sConfig.GetStringDefault("PidFile", ""); if (!pidfile.empty()) { uint32 pid = CreatePIDFile(pidfile); if (!pid) { sLog.outError( "Cannot create PID file %s.\n", pidfile.c_str() ); return 1; } sLog.outString( "Daemon PID: %u\n", pid ); } // Initialize the database connection if (!StartDB()) return 1; // Get the list of realms for the server sRealmList->Initialize(sConfig.GetIntDefault("RealmsStateUpdateDelay", 20)); if (sRealmList->size() == 0) { sLog.outError("No valid realms specified."); sleep(5); return 1; } // cleanup query // delete expired bans LoginDatabase.Execute("DELETE FROM account_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); // Launch the listening network socket ACE_Acceptor<AuthSocket, ACE_SOCK_Acceptor> acceptor; uint16 rmport = sConfig.GetIntDefault("AuthServerPort", DEFAULT_AUTHSERVER_PORT); std::string bind_ip = sConfig.GetStringDefault("BindIP", "0.0.0.0"); ACE_INET_Addr bind_addr(rmport, bind_ip.c_str()); if (acceptor.open(bind_addr, ACE_Reactor::instance(), ACE_NONBLOCK) == -1) { sLog.outError("Realm-Server can not bind to %s:%d", bind_ip.c_str(), rmport); return 1; } // Catch termination signals HookSignals(); sLog.outString("Realm-Server started"); // Handle affinity for multiple processors and process priority on Windows #ifdef _WIN32 { HANDLE hProcess = GetCurrentProcess(); uint32 Aff = sConfig.GetIntDefault("UseProcessors", 0); if (Aff > 0) { ULONG_PTR appAff; ULONG_PTR sysAff; if (GetProcessAffinityMask(hProcess,&appAff,&sysAff)) { ULONG_PTR curAff = Aff & appAff; // remove non accessible processors if (!curAff ) { sLog.outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for authserver. Accessible processors bitmask (hex): %x",Aff,appAff); } else { if (SetProcessAffinityMask(hProcess,curAff)) sLog.outString("Using processors (bitmask, hex): %x", curAff); else sLog.outError("Can't set used processors (hex): %x", curAff); } } sLog.outString(); } bool Prio = sConfig.GetBoolDefault("ProcessPriority", false); if (Prio) { if (SetPriorityClass(hProcess,HIGH_PRIORITY_CLASS)) sLog.outString("Realm-Server process priority class set to HIGH"); else sLog.outError("ERROR: Can't set AuthServer process priority class."); sLog.outString(); } } #endif // maximum counter for next ping uint32 numLoops = (sConfig.GetIntDefault( "MaxPingTime", 30 ) * (MINUTE * 1000000 / 100000)); uint32 loopCounter = 0; // Wait for termination signal while (!stopEvent) { // dont move this outside the loop, the reactor will modify it ACE_Time_Value interval(0, 100000); if (ACE_Reactor::instance()->run_reactor_event_loop(interval) == -1) break; if ( (++loopCounter) == numLoops ) { loopCounter = 0; sLog.outDetail("Ping MySQL to keep connection alive"); LoginDatabase.Query("SELECT 1 FROM realmlist LIMIT 1"); } #ifdef _WIN32 if (m_ServiceStatus == 0) stopEvent = true; while (m_ServiceStatus == 2) Sleep(1000); #endif } // Wait for the delay thread to exit LoginDatabase.HaltDelayThread(); // Remove signal handling before leaving UnhookSignals(); sLog.outString( "Halting process..." ); return 0; }
void SthenoCore::open(ACE_ARGV& args) throw (RuntimeException&) { ACE_GUARD(ACE_SYNCH_RECURSIVE_MUTEX, ace_mon, m_lock); m_reservationFlag = false; m_runNO = 0; //no run m_testNO = 0; //no test m_trace = true; m_maxServicesQoS = 2; //m_runtimeQoS = 950000; //absolute // dont need this m_runtimeQoS = RUNTIME_DEFAULT_QOS; //5000; m_runtimePeriod = CPUReservation::DEFAULT_PERIOD; //signal handling ACE_Sig_Action no_sigpipe((ACE_SignalHandler) SIG_IGN); ACE_Sig_Action original_action; no_sigpipe.register_action(SIGPIPE, &original_action); static const ACE_TCHAR options[] = ACE_TEXT("::"); const char* prefix = "\0"; ACE_Get_Opt cmd_opts(args.argc(), args.argv(), options); int option; if (cmd_opts.long_option (ACE_TEXT("prefix"), ACE_Get_Opt::ARG_REQUIRED) == -1) { throw RuntimeException(RuntimeException::INVALID_ARGS); } if (cmd_opts.long_option (ACE_TEXT("run"), ACE_Get_Opt::ARG_REQUIRED) == -1) { throw RuntimeException(RuntimeException::INVALID_ARGS); } if (cmd_opts.long_option (ACE_TEXT("test"), ACE_Get_Opt::ARG_REQUIRED) == -1) { throw RuntimeException(RuntimeException::INVALID_ARGS); } if (cmd_opts.long_option (ACE_TEXT("reservation"), ACE_Get_Opt::ARG_REQUIRED) == -1) { throw RuntimeException(RuntimeException::INVALID_ARGS); } if (cmd_opts.long_option (ACE_TEXT("maxservices"), ACE_Get_Opt::ARG_REQUIRED) == -1) { throw RuntimeException(RuntimeException::INVALID_ARGS); } if (cmd_opts.long_option (ACE_TEXT("runtimeqos"), ACE_Get_Opt::ARG_REQUIRED) == -1) { throw RuntimeException(RuntimeException::INVALID_ARGS); } if (cmd_opts.long_option (ACE_TEXT("runtimeqosperiod"), ACE_Get_Opt::ARG_REQUIRED) == -1) { throw RuntimeException(RuntimeException::INVALID_ARGS); } printf("AGRS=%d\n", args.argc()); while ((option = cmd_opts()) != EOF) switch (option) { case 0: { //long_option const char *op = cmd_opts.long_option(); printf("LONG=%s\n", cmd_opts.opt_arg()); if (ACE_OS::strcmp("prefix", op) == 0) { prefix = cmd_opts.opt_arg(); printf("Prefix=%s\n", prefix); break; } if (ACE_OS::strcmp("run", op) == 0) { m_runNO = Integer::parseInt(cmd_opts.opt_arg(), 10); printf("RunNo=%d %s\n", m_runNO, cmd_opts.opt_arg()); break; } if (ACE_OS::strcmp("test", op) == 0) { m_testNO = Integer::parseInt(cmd_opts.opt_arg(), 10); printf("TestNo=%d %s\n", m_testNO, cmd_opts.opt_arg()); break; } if (ACE_OS::strcmp("reservation", op) == 0) { if (strcasecmp(cmd_opts.opt_arg(), "true") == 0) { m_reservationFlag = true; } break; } if (ACE_OS::strcmp("maxservices", op) == 0) { m_maxServicesQoS = Integer::parseInt(cmd_opts.opt_arg(), 10); break; } if (ACE_OS::strcmp("runtimeqos", op) == 0) { m_runtimeQoS = Integer::parseInt(cmd_opts.opt_arg(), 10); printf("runtimeqos=%d %s\n", m_runtimeQoS, cmd_opts.opt_arg()); break; } if (ACE_OS::strcmp("runtimeqosperiod", op) == 0) { m_runtimePeriod = Integer::parseInt(cmd_opts.opt_arg(), 10); printf("runtimeqosPeriod=%d %s\n", m_runtimeQoS, cmd_opts.opt_arg()); break; } break; } case ':': { ACE_ERROR ((LM_ERROR, ACE_TEXT("-%c requires an argument\n"), cmd_opts.opt_opt())); throw RuntimeException(RuntimeException::INVALID_ARGS); } default: { } } m_p2pQoS = P2P_DEFAULT_QOS; //5000; m_servicesQoS = SERVICE_MANAGER_DEFAULT_QOS; //5000; //total=75K //m_perServicesQoS = 25000;//25000; /*m_p2pQoS = m_runtimeQoS * 0.2; m_servicesQoS = m_runtimeQoS * 0.8; m_perServicesQoS = m_servicesQoS / m_maxServicesQoS;*/ //services 100+50 = 150k //core 10k //p2p 125k // stringstream statFile; stringstream traceFile; stringstream debugFile; statFile << "stat_" << prefix << "_" << m_testNO << "_" << m_runNO << "_" << this->m_peerID->toString().c_str() << ".log"; traceFile << "trace_" << prefix << "_" << m_testNO << "_" << m_runNO << "_" << this->m_peerID->toString().c_str() << ".log"; debugFile << "debug_" << prefix << "_" << m_testNO << "_" << m_runNO << "_" << this->m_peerID->toString().c_str() << ".log"; initLogging(statFile.str().c_str(), traceFile.str().c_str(), debugFile.str().c_str()); initRuntimeQoS(args); UUIDPtr runtimeUUID; getUUID(runtimeUUID); String runtimeDomainPath = ""; m_runtimeQoSManager = this->getQoSManagerInterface(runtimeDomainPath, RUNTIME_DEFAULT_QOS, m_runtimePeriod, false); /*if(m_signalHandler.open()!=0){ throw RuntimeException(RuntimeException::INVALID_OVERLAY); }*/ try { QoSManagerInterface* qosManager = 0; if (m_reservationFlag) { //String p2pPath = "p2p"; //qosManager = this->getQoSManagerInterface(p2pPath, m_p2pQoS, m_runtimePeriod); qosManager = m_runtimeQoSManager; } getOverlay()->open(qosManager); if (m_reservationFlag) { //String servicesPath = "services"; //m_serviceQosManager = this->getQoSManagerInterface(servicesPath, m_servicesQoS, m_runtimePeriod); m_serviceQosManager = m_runtimeQoSManager; } } catch (OverlayException& ex) { throw RuntimeException(RuntimeException::INVALID_OVERLAY); } catch (RuntimeException& runtimeEx) { throw RuntimeException(RuntimeException::INVALID_OVERLAY); } toStart(); if (trace()) { TraceRuntimeSingleton::instance()->logRuntimeOpen(this->m_peerID); } }
/// Launch the realm server extern int main(int argc, char** argv) { ///- Command line parsing char const* cfg_file = _REALMD_CONFIG; char const* options = ":c:s:"; ACE_Get_Opt cmd_opts(argc, argv, options); cmd_opts.long_option("version", 'v'); char serviceDaemonMode = '\0'; int option; while ((option = cmd_opts()) != EOF) { switch (option) { case 'c': cfg_file = cmd_opts.opt_arg(); break; case 'v': printf("%s\n", _FULLVERSION(REVISION_DATE, REVISION_TIME, REVISION_NR, REVISION_ID)); return 0; case 's': { const char* mode = cmd_opts.opt_arg(); if (!strcmp(mode, "run")) { serviceDaemonMode = 'r'; } #ifdef WIN32 else if (!strcmp(mode, "install")) { serviceDaemonMode = 'i'; } else if (!strcmp(mode, "uninstall")) { serviceDaemonMode = 'u'; } #else else if (!strcmp(mode, "stop")) { serviceDaemonMode = 's'; } #endif else { sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode); usage(argv[0]); Log::WaitBeforeContinueIfNeed(); return 1; } break; } case ':': sLog.outError("Runtime-Error: -%c option requires an input argument", cmd_opts.opt_opt()); usage(argv[0]); Log::WaitBeforeContinueIfNeed(); return 1; default: sLog.outError("Runtime-Error: bad format of commandline arguments"); usage(argv[0]); Log::WaitBeforeContinueIfNeed(); return 1; } } #ifdef WIN32 // windows service command need execute before config read switch (serviceDaemonMode) { case 'i': if (WinServiceInstall()) { sLog.outString("Installing service"); } return 1; case 'u': if (WinServiceUninstall()) { sLog.outString("Uninstalling service"); } return 1; case 'r': WinServiceRun(); break; } #endif if (!sConfig.SetSource(cfg_file)) { sLog.outError("Could not find configuration file %s.", cfg_file); Log::WaitBeforeContinueIfNeed(); return 1; } #ifndef WIN32 // posix daemon commands need apply after config read switch (serviceDaemonMode) { case 'r': startDaemon(); break; case 's': stopDaemon(); break; } #endif sLog.Initialize(); sLog.outString("%s [realm-daemon]", _FULLVERSION(REVISION_DATE, REVISION_TIME, REVISION_NR, REVISION_ID)); sLog.outString("<Ctrl-C> to stop.\n"); sLog.outString("Using configuration file %s.", cfg_file); ///- Check the version of the configuration file uint32 confVersion = sConfig.GetIntDefault("ConfVersion", 0); if (confVersion < _REALMDCONFVERSION) { sLog.outError("*****************************************************************************"); sLog.outError(" WARNING: Your realmd.conf version indicates your conf file is out of date!"); sLog.outError(" Please check for updates, as your current default values may cause"); sLog.outError(" strange behavior."); sLog.outError("*****************************************************************************"); Log::WaitBeforeContinueIfNeed(); } DETAIL_LOG("%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION)); if (SSLeay() < 0x009080bfL) { DETAIL_LOG("WARNING: Outdated version of OpenSSL lib. Logins to server may not work!"); DETAIL_LOG("WARNING: Minimal required version [OpenSSL 0.9.8k]"); } DETAIL_LOG("Using ACE: %s", ACE_VERSION); #if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL) ACE_Reactor::instance(new ACE_Reactor(new ACE_Dev_Poll_Reactor(ACE::max_handles(), 1), 1), true); #else ACE_Reactor::instance(new ACE_Reactor(new ACE_TP_Reactor(), true), true); #endif sLog.outBasic("Max allowed open files is %d", ACE::max_handles()); /// realmd PID file creation std::string pidfile = sConfig.GetStringDefault("PidFile", ""); if (!pidfile.empty()) { uint32 pid = CreatePIDFile(pidfile); if (!pid) { sLog.outError("Can not create PID file %s.\n", pidfile.c_str()); Log::WaitBeforeContinueIfNeed(); return 1; } sLog.outString("Daemon PID: %u\n", pid); } ///- Initialize the database connection if (!StartDB()) { Log::WaitBeforeContinueIfNeed(); return 1; } ///- Get the list of realms for the server sRealmList.Initialize(sConfig.GetIntDefault("RealmsStateUpdateDelay", 20)); if (sRealmList.size() == 0) { sLog.outError("No valid realms specified."); Log::WaitBeforeContinueIfNeed(); return 1; } // cleanup query // set expired bans to inactive LoginDatabase.BeginTransaction(); LoginDatabase.Execute("UPDATE account_banned SET active = 0 WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); LoginDatabase.CommitTransaction(); ///- Launch the listening network socket ACE_Acceptor<AuthSocket, ACE_SOCK_Acceptor> acceptor; uint16 rmport = sConfig.GetIntDefault("RealmServerPort", DEFAULT_REALMSERVER_PORT); std::string bind_ip = sConfig.GetStringDefault("BindIP", "0.0.0.0"); ACE_INET_Addr bind_addr(rmport, bind_ip.c_str()); if (acceptor.open(bind_addr, ACE_Reactor::instance(), ACE_NONBLOCK) == -1) { sLog.outError("MaNGOS realmd can not bind to %s:%d", bind_ip.c_str(), rmport); Log::WaitBeforeContinueIfNeed(); return 1; } ///- Catch termination signals HookSignals(); ///- Handle affinity for multiple processors and process priority on Windows #ifdef WIN32 { HANDLE hProcess = GetCurrentProcess(); uint32 Aff = sConfig.GetIntDefault("UseProcessors", 0); if (Aff > 0) { ULONG_PTR appAff; ULONG_PTR sysAff; if (GetProcessAffinityMask(hProcess, &appAff, &sysAff)) { ULONG_PTR curAff = Aff & appAff; // remove non accessible processors if (!curAff) { sLog.outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for realmd. Accessible processors bitmask (hex): %x", Aff, appAff); } else { if (SetProcessAffinityMask(hProcess, curAff)) { sLog.outString("Using processors (bitmask, hex): %x", curAff); } else { sLog.outError("Can't set used processors (hex): %x", curAff); } } } sLog.outString(); } bool Prio = sConfig.GetBoolDefault("ProcessPriority", false); if (Prio) { if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS)) { sLog.outString("realmd process priority class set to HIGH"); } else { sLog.outError("Can't set realmd process priority class."); } sLog.outString(); } } #endif // server has started up successfully => enable async DB requests LoginDatabase.AllowAsyncTransactions(); // maximum counter for next ping uint32 numLoops = (sConfig.GetIntDefault("MaxPingTime", 30) * (MINUTE * 1000000 / 100000)); uint32 loopCounter = 0; #ifndef WIN32 detachDaemon(); #endif ///- Wait for termination signal while (!stopEvent) { // dont move this outside the loop, the reactor will modify it ACE_Time_Value interval(0, 100000); if (ACE_Reactor::instance()->run_reactor_event_loop(interval) == -1) { break; } if ((++loopCounter) == numLoops) { loopCounter = 0; DETAIL_LOG("Ping MySQL to keep connection alive"); LoginDatabase.Ping(); } #ifdef WIN32 if (m_ServiceStatus == 0) { stopEvent = true; } while (m_ServiceStatus == 2) { Sleep(1000); } #endif } ///- Wait for the delay thread to exit LoginDatabase.HaltDelayThread(); ///- Remove signal handling before leaving UnhookSignals(); sLog.outString("Halting process..."); return 0; }
// Launch the oregon server extern int main(int argc, char **argv) { // Command line parsing char const* cfg_file = _OREGON_CORE_CONFIG; #ifdef _WIN32 char const *options = ":c:s:"; #else char const *options = ":c:"; #endif ACE_Get_Opt cmd_opts(argc, argv, options); cmd_opts.long_option("version", 'v'); int option; while ((option = cmd_opts()) != EOF) { switch (option) { case 'c': cfg_file = cmd_opts.opt_arg(); break; case 'v': printf("%s\n", _FULLVERSION); return 0; #ifdef _WIN32 case 's': { const char *mode = cmd_opts.opt_arg(); if (!strcmp(mode, "install")) { if (WinServiceInstall()) sLog.outString("Installing service"); return 1; } else if (!strcmp(mode, "uninstall")) { if (WinServiceUninstall()) sLog.outString("Uninstalling service"); return 1; } else if (!strcmp(mode, "run")) WinServiceRun(); else { sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode); usage(argv[0]); return 1; } break; } #endif case ':': sLog.outError("Runtime-Error: -%c option requires an input argument", cmd_opts.opt_opt()); usage(argv[0]); return 1; default: sLog.outError("Runtime-Error: bad format of commandline arguments"); usage(argv[0]); return 1; } } if (!sConfig.SetSource(cfg_file)) { sLog.outError("Invalid or missing configuration file : %s", cfg_file); sLog.outError("Verify that the file exists and has \'[worldserver]' written in the top of the file!"); return 1; } sLog.outString("Using configuration file %s.", cfg_file); uint32 confVersion = sConfig.GetIntDefault("ConfVersion", 0); if (confVersion < _OREGON_CORE_CONFVER) { sLog.outError("*****************************************************************************"); sLog.outError(" WARNING: Your oregoncore.conf version indicates your conf file is out of date!"); sLog.outError(" Please check for updates, as your current default values may cause"); sLog.outError(" strange behavior."); sLog.outError("*****************************************************************************"); clock_t pause = 3000 + clock(); while (pause > clock()) {} } sLog.outDetail("Using ACE: %s", ACE_VERSION); // and run the 'Master' // todo - Why do we need this 'Master'? Can't all of this be in the Main as for Realmd? return sMaster.Run(); // at sMaster return function exist with codes // 0 - normal shutdown // 1 - shutdown at error // 2 - restart command used, this code can be used by restarter for restart OregonCore }
/// Launch the mangos server extern int main(int argc, char **argv) { // - Construct Memory Manager Instance MaNGOS::Singleton<MemoryManager>::Instance(); //char *leak = new char[1000]; // test leak detection ///- Command line parsing char const* cfg_file = _MANGOSD_CONFIG; #ifdef WIN32 char const *options = ":c:s:"; #else char const *options = ":c:"; #endif ACE_Get_Opt cmd_opts(argc, argv, options); cmd_opts.long_option("version", 'v'); int option; while ((option = cmd_opts()) != EOF) { switch (option) { case 'c': cfg_file = cmd_opts.opt_arg(); break; case 'v': printf("%s\n", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID)); return 0; #ifdef WIN32 case 's': { const char *mode = cmd_opts.opt_arg(); if (!strcmp(mode, "install")) { if (WinServiceInstall()) sLog.outString("Installing service"); return 1; } else if (!strcmp(mode, "uninstall")) { if (WinServiceUninstall()) sLog.outString("Uninstalling service"); return 1; } else if (!strcmp(mode, "run")) WinServiceRun(); else { sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode); usage(argv[0]); Log::WaitBeforeContinueIfNeed(); return 1; } break; } #endif case ':': sLog.outError("Runtime-Error: -%c option requires an input argument", cmd_opts.opt_opt()); usage(argv[0]); Log::WaitBeforeContinueIfNeed(); return 1; default: sLog.outError("Runtime-Error: bad format of commandline arguments"); usage(argv[0]); Log::WaitBeforeContinueIfNeed(); return 1; } } if (!sConfig.SetSource(cfg_file)) { sLog.outError("Could not find configuration file %s.", cfg_file); Log::WaitBeforeContinueIfNeed(); return 1; } sLog.outString( "%s [world-daemon]", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID) ); sLog.outString( "<Ctrl-C> to stop.\n\n" ); sLog.outTitle( " CCCCC TTTTTTTT CCCCC CCCC CCCCCC CCCCCCCC"); sLog.outTitle( " CCC TT CCC CC CC CC CC CC"); sLog.outTitle( "CC TT CC CC CC CC CC CC"); sLog.outTitle( "CC TT CC CC CC CC CC CC"); sLog.outTitle( "CC CCCCC TT CC CC CC CCCCCCC CCCCC"); sLog.outTitle( "CC C CCC TT CC CC CC CCCCCC CCCCC"); sLog.outTitle( "CC CCC TT CC CC CC CC CC CC"); sLog.outTitle( " CCC CCCCCCC TT CCC CC CC CC CC CC"); sLog.outTitle( " CCCCC CC CCC TT CCCCC CCCC CC CC CCCCCCCC"); sLog.outTitle( " CC CCC http://valhalla-team.com"); sLog.outTitle( " CCCCCC\n\n"); sLog.outString("Using configuration file %s.", cfg_file); DETAIL_LOG("%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION)); if (SSLeay() < 0x009080bfL ) { DETAIL_LOG("WARNING: Outdated version of OpenSSL lib. Logins to server may not work!"); DETAIL_LOG("WARNING: Minimal required version [OpenSSL 0.9.8k]"); } DETAIL_LOG("Using ACE: %s", ACE_VERSION); ///- and run the 'Master' /// \todo Why do we need this 'Master'? Can't all of this be in the Main as for Realmd? return sMaster.Run(); // at sMaster return function exist with codes // 0 - normal shutdown // 1 - shutdown at error // 2 - restart command used, this code can be used by restarter for restart mangosd }
//--------------------------------------------------------------------------------------------- int HA_ccifs::init ( int argc , ACE_TCHAR *argv[] ) { ACE_Trace _( ACE_TEXT( "%D HA_ccifs::init" ) , __LINE__ ); //command line //------------------------------------------------------------------------------- static const ACE_TCHAR options[] = ACE_TEXT (":f:"); ACE_Get_Opt cmd_opts (argc, argv, options, 0); if (cmd_opts.long_option (ACE_TEXT ( "config" ), 'f', ACE_Get_Opt::ARG_REQUIRED) == -1) { return -1; } int option; ACE_TCHAR config_file[MAXPATHLEN]; ACE_OS::strcpy ( config_file, ACE_TEXT ( conf_path.c_str() ) ); while ( ( option = cmd_opts ()) != EOF) switch ( option ) { case 'f' : ACE_OS::strncpy (config_file , cmd_opts.opt_arg () , MAXPATHLEN ); break; case ':': ACE_ERROR_RETURN ( ( LM_ERROR , ACE_TEXT ( "-%c requires an argument\n" ) , cmd_opts.opt_opt ()) , -1 ); default: ACE_ERROR_RETURN ( ( LM_ERROR , ACE_TEXT ( "parse error.\n" ) ) , - 1); } //configuration file //------------------------------------------------------------------------------- ACE_Configuration_Heap config; config.open (); ACE_Registry_ImpExp config_importer (config); if ( config_importer.import_config (config_file) == -1 ) { ACE_ERROR_RETURN ( ( LM_ERROR , ACE_TEXT ("%p\n") , config_file ) , -1 ); } ACE_Configuration_Section_Key dispatcher_section; if (config.open_section (config.root_section (), ACE_TEXT ("HA_ccifs"), 0, dispatcher_section) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ( "can't open HA_ccifs section" ) ) , -1 ); //fifo u_int dispatcher_port; if (config.get_integer_value ( dispatcher_section, ACE_TEXT ( "fifo" ) , dispatcher_port ) == -1 ) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("HA_ccifs fifo") ACE_TEXT (" does not exist\n") ) , -1 ); //ccifs ACE_TString ccifs; if (config.get_string_value ( dispatcher_section, ACE_TEXT ( "ccifs_tmpfs_mount" ) , ccifs ) == -1 ) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("HA_ccifs ccifs_mount") ACE_TEXT (" does not exist\n") ) , -1 ); if( ACE_Thread_Manager::instance()->spawn( ACE_THR_FUNC (ccifs_func) , (void*) this , THR_NEW_LWP , &m_thread_id ) ) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) ..spawned ccifs notify thread..\n"))); } else { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) ..spawning ccifs notify failed..\n"))); } return 0; }
/// Launch the mangos server extern int main(int argc, char** argv) { ///- Command line parsing char const* cfg_file = _MANGOSD_CONFIG; char const* options = ":a:c:s:"; ACE_Get_Opt cmd_opts(argc, argv, options); cmd_opts.long_option("version", 'v', ACE_Get_Opt::NO_ARG); int option; while ((option = cmd_opts()) != EOF) { switch (option) { case 'c': cfg_file = cmd_opts.opt_arg(); break; case 'v': printf("%s\n", _FULLVERSION(REVISION_DATE, REVISION_TIME, REVISION_NR, REVISION_ID)); return 0; case ':': sLog.outError("Runtime-Error: -%c option requires an input argument", cmd_opts.opt_opt()); usage(argv[0]); Log::WaitBeforeContinueIfNeed(); return 1; default: sLog.outError("Runtime-Error: bad format of commandline arguments"); usage(argv[0]); Log::WaitBeforeContinueIfNeed(); return 1; } } if (!sFileConfig.SetSource(cfg_file)) { sLog.outError("Could not find configuration file %s.", cfg_file); Log::WaitBeforeContinueIfNeed(); return 1; } sLog.outString("%s [world-daemon]", _FULLVERSION(REVISION_DATE, REVISION_TIME, REVISION_NR, REVISION_ID)); sLog.outString("<Ctrl-C> to stop."); sLog.outString("\n\n" " _____ __ __ _ _ _____ ____ _____ \n" " / ____| | \\/ | | \\ | |/ ____|/ __ \\ / ____|\n" " | | | \\ / | | \\| | | __ | | | (___ \n" " | |ontinued| |\\/| | __ _| . ` | | |_ | | | |\\___ \\ \n" " | |____ | | | |/ _` | |\\ | |__| | |__| |____) |\n" " \\_____| |_| |_| (_| |_| \\_|\\_____|\\____/ \\____/ \n" " http://cmangos.net\\__,_| Doing things right!\n\n"); sLog.outString("Using configuration file %s.", cfg_file); DETAIL_LOG("%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION)); if (SSLeay() < 0x009080bfL) { DETAIL_LOG("WARNING: Outdated version of OpenSSL lib. Logins to server may not work!"); DETAIL_LOG("WARNING: Minimal required version [OpenSSL 0.9.8k]"); } DETAIL_LOG("Using ACE: %s", ACE_VERSION); ///- and run the 'Master' /// \todo Why do we need this 'Master'? Can't all of this be in the Main as for Realmd? return sMaster.Run(); // at sMaster return function exist with codes // 0 - normal shutdown // 1 - shutdown at error // 2 - restart command used, this code can be used by restarter for restart mangosd }
/// Launch the realm server extern int main(int argc, char **argv) { ///- Command line parsing char const* cfg_file = _REALMD_CONFIG; #ifdef WIN32 char const *options = ":c:s:"; #else char const *options = ":c:"; #endif ACE_Get_Opt cmd_opts(argc, argv, options); cmd_opts.long_option("version", 'v'); int option; while ((option = cmd_opts()) != EOF) { switch (option) { case 'c': cfg_file = cmd_opts.opt_arg(); break; case 'v': printf("%s\n", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID)); return 0; #ifdef WIN32 case 's': { const char *mode = cmd_opts.opt_arg(); if (!strcmp(mode, "install")) { if (WinServiceInstall()) sLog.outString("Installing service"); return 1; } else if (!strcmp(mode, "uninstall")) { if (WinServiceUninstall()) sLog.outString("Uninstalling service"); return 1; } else if (!strcmp(mode, "run")) WinServiceRun(); else { sLog.outError("Runtime-Error: -%c unsupported argument %s", cmd_opts.opt_opt(), mode); usage(argv[0]); Log::WaitBeforeContinueIfNeed(); return 1; } break; } #endif case ':': sLog.outError("Runtime-Error: -%c option requires an input argument", cmd_opts.opt_opt()); usage(argv[0]); Log::WaitBeforeContinueIfNeed(); return 1; default: sLog.outError("Runtime-Error: bad format of commandline arguments"); usage(argv[0]); Log::WaitBeforeContinueIfNeed(); return 1; } } if (!sConfig.SetSource(cfg_file)) { sLog.outError("Could not find configuration file %s.", cfg_file); Log::WaitBeforeContinueIfNeed(); return 1; } sLog.Initialize(); sLog.outString( "%s [realm-daemon]", _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID) ); sLog.outString( "<Ctrl-C> to stop.\n" ); sLog.outString("Using configuration file %s.", cfg_file); ///- Check the version of the configuration file uint32 confVersion = sConfig.GetIntDefault("ConfVersion", 0); if (confVersion < _REALMDCONFVERSION) { sLog.outError("*****************************************************************************"); sLog.outError(" WARNING: Your realmd.conf version indicates your conf file is out of date!"); sLog.outError(" Please check for updates, as your current default values may cause"); sLog.outError(" strange behavior."); sLog.outError("*****************************************************************************"); Log::WaitBeforeContinueIfNeed(); } DETAIL_LOG("%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION)); if (SSLeay() < 0x009080bfL ) { DETAIL_LOG("WARNING: Outdated version of OpenSSL lib. Logins to server may not work!"); DETAIL_LOG("WARNING: Minimal required version [OpenSSL 0.9.8k]"); } DETAIL_LOG("Using ACE: %s", ACE_VERSION); #if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL) ACE_Reactor::instance(new ACE_Reactor(new ACE_Dev_Poll_Reactor(ACE::max_handles(), 1), 1), true); #else ACE_Reactor::instance(new ACE_Reactor(new ACE_TP_Reactor(), true), true); #endif sLog.outBasic("Max allowed open files is %d", ACE::max_handles()); /// realmd PID file creation std::string pidfile = sConfig.GetStringDefault("PidFile", ""); if(!pidfile.empty()) { uint32 pid = CreatePIDFile(pidfile); if( !pid ) { sLog.outError( "Cannot create PID file %s.\n", pidfile.c_str() ); Log::WaitBeforeContinueIfNeed(); return 1; } sLog.outString( "Daemon PID: %u\n", pid ); } ///- Initialize the database connection if(!StartDB()) { Log::WaitBeforeContinueIfNeed(); return 1; } ///- Get the list of realms for the server sRealmList.Initialize(sConfig.GetIntDefault("RealmsStateUpdateDelay", 20)); if (sRealmList.size() == 0) { sLog.outError("No valid realms specified."); Log::WaitBeforeContinueIfNeed(); return 1; } // cleanup query // set expired bans to inactive LoginDatabase.BeginTransaction(); LoginDatabase.Execute("UPDATE account_banned SET active = 0 WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); LoginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate"); LoginDatabase.CommitTransaction(); ///- Launch the listening network socket ACE_Acceptor<AuthSocket, ACE_SOCK_Acceptor> acceptor; uint16 rmport = sConfig.GetIntDefault("RealmServerPort", DEFAULT_REALMSERVER_PORT); std::string bind_ip = sConfig.GetStringDefault("BindIP", "0.0.0.0"); ACE_INET_Addr bind_addr(rmport, bind_ip.c_str()); if(acceptor.open(bind_addr, ACE_Reactor::instance(), ACE_NONBLOCK) == -1) { sLog.outError("MaNGOS realmd can not bind to %s:%d", bind_ip.c_str(), rmport); Log::WaitBeforeContinueIfNeed(); return 1; } // FG: "bad points" system related uint32 badPointsDropInterval = sConfig.GetIntDefault("BadPoints.DropInterval", HOUR); uint32 badPointsDropAmount = sConfig.GetIntDefault("BadPoints.DropAmount", 1); uint32 badPointsDropWaitTime = sConfig.GetIntDefault("BadPoints.WaitTime", WEEK); IntervalTimer badPointsTimer; badPointsTimer.SetInterval(badPointsDropInterval * IN_MILLISECONDS); ///- Catch termination signals HookSignals(); ///- Handle affinity for multiple processors and process priority on Windows #ifdef WIN32 { HANDLE hProcess = GetCurrentProcess(); uint32 Aff = sConfig.GetIntDefault("UseProcessors", 0); if(Aff > 0) { ULONG_PTR appAff; ULONG_PTR sysAff; if(GetProcessAffinityMask(hProcess,&appAff,&sysAff)) { ULONG_PTR curAff = Aff & appAff; // remove non accessible processors if(!curAff ) { sLog.outError("Processors marked in UseProcessors bitmask (hex) %x not accessible for realmd. Accessible processors bitmask (hex): %x",Aff,appAff); } else { if(SetProcessAffinityMask(hProcess,curAff)) sLog.outString("Using processors (bitmask, hex): %x", curAff); else sLog.outError("Can't set used processors (hex): %x", curAff); } } sLog.outString(); } bool Prio = sConfig.GetBoolDefault("ProcessPriority", false); if(Prio) { if(SetPriorityClass(hProcess,HIGH_PRIORITY_CLASS)) sLog.outString("realmd process priority class set to HIGH"); else sLog.outError("Can't set realmd process priority class."); sLog.outString(); } } #endif //server has started up successfully => enable async DB requests LoginDatabase.AllowAsyncTransactions(); // maximum counter for next ping uint32 numLoops = (sConfig.GetIntDefault( "MaxPingTime", 30 ) * (MINUTE * 1000000 / 100000)); uint32 loopCounter = 0; uint32 last_ping_time = 0; uint32 now = WorldTimer::getMSTime(); uint32 diff; uint32 lasttime = now; uint32 last_ipprops_cleanup = 0; ///- Wait for termination signal while (!stopEvent) { // dont move this outside the loop, the reactor will modify it ACE_Time_Value interval(0, 100000); if (ACE_Reactor::instance()->run_reactor_event_loop(interval) == -1) break; now = WorldTimer::getMSTime(); diff = WorldTimer::getMSTimeDiff(lasttime, now); lasttime = now; badPointsTimer.Update(diff); if( (++loopCounter) == numLoops ) { // FG: protect against network system overloading // if that happens, force realmd close (autorestarter ftw!) if(WorldTimer::getMSTimeDiff(last_ping_time, now) < 10000) { sLog.outError("NETWORK SYSTEM OVERLOAD"); raise(SIGSEGV); // force close abort(); } last_ping_time = now; loopCounter = 0; DETAIL_LOG("Ping MySQL to keep connection alive"); LoginDatabase.Ping(); } // FG: clear flood protect buffer periodically if(WorldTimer::getMSTimeDiff(last_ipprops_cleanup, now) > 30000) // flush stored IPs every 30 secs { last_ipprops_cleanup = now; uint32 flushed = 0, blocked = 0, stored = 0; CleanupIPPropmap(flushed, blocked, stored); sLog.outDetail("IPProp: Flushed %u total, %u of them blocked, now %u stored", flushed, blocked, stored); } // FG: handle "bad points" drop if(badPointsTimer.Passed()) { badPointsTimer.Reset(); if(badPointsDropAmount) { uint64 goodtime = uint64(time(NULL)) - badPointsDropWaitTime; LoginDatabase.Execute("UPDATE account_badpoints SET maxpts = curpts WHERE maxpts < curpts"); LoginDatabase.PExecute("UPDATE account_badpoints SET curpts = 0 WHERE curpts <= %u AND lasttime < "UI64FMTD, badPointsDropAmount, goodtime); LoginDatabase.PExecute("UPDATE account_badpoints SET curpts = curpts - %u WHERE curpts > %u AND lasttime < "UI64FMTD, badPointsDropAmount, badPointsDropAmount, goodtime); } } #ifdef WIN32 if (m_ServiceStatus == 0) stopEvent = true; while (m_ServiceStatus == 2) Sleep(1000); #endif } ///- Wait for the delay thread to exit LoginDatabase.HaltDelayThread(); ///- Remove signal handling before leaving UnhookSignals(); sLog.outString( "Halting process..." ); return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { DDS::DomainParticipantFactory_var dpf = DDS::DomainParticipantFactory::_nil(); DDS::DomainParticipant_var participant = DDS::DomainParticipant::_nil(); try { QuantLibAddinCpp::initializeAddin(); QuantLib::Calendar calendar = QuantLib::TARGET(); QuantLib::Date settlementDate(22, QuantLib::September, 2004); settlementDate = calendar.adjust(settlementDate); QuantLib::Integer fixingDays = 2; QuantLib::Date todaysDate = calendar.advance(settlementDate, -fixingDays, QuantLib::Days); QuantLibAddinCpp::qlSettingsSetEvaluationDate( todaysDate.serialNumber(), OH_NULL ); std::cout << "Today: " << todaysDate.weekday() << ", " << todaysDate << std::endl; std::cout << "Settlement date: " << settlementDate.weekday() << ", " << settlementDate << std::endl; // Initialize, and create a DomainParticipant dpf = TheParticipantFactoryWithArgs(argc, argv); qldds_utils::BasicDomainParticipant irs_participant( dpf, IRS_DOMAIN_ID ); irs_participant.createPublisher(); irs_participant.createSubscriber(); std::string term_structure; std::vector<std::string> rate_helpers; ACE_Get_Opt cmd_opts( argc, argv, ":c:n:i:" ); int option; while ( (option = cmd_opts()) != EOF ) { switch( option ) { case 'c' : { std::istringstream f( cmd_opts.opt_arg() ); std::string s; while (std::getline(f, s, '|')) { rate_helpers.push_back(s); } break; } case 'n' : { term_structure = cmd_opts.opt_arg(); break; } } } QuantLibAddinCpp::qlLibor("Libor", "USD", "6M", "", false, false, true); // Topics for Swap Components // Setting up schedule topic DDS::Topic_var schedule_topic = irs_participant.createTopicAndRegisterType < schedule::qlScheduleTypeSupport_var, schedule::qlScheduleTypeSupportImpl > ( SCHEDULE_TOPIC_NAME ); // setting up vanilla swap topic DDS::Topic_var vanilla_swap_topic = irs_participant.createTopicAndRegisterType < vanillaswap::qlVanillaSwapTypeSupport_var, vanillaswap::qlVanillaSwapTypeSupportImpl > ( VANILLA_SWAP_TOPIC_NAME ); // Topics for curve components // setting up deposit rate helper DDS::Topic_var deposit_rate_helper2_topic = irs_participant.createTopicAndRegisterType < ratehelpers::qlDepositRateHelper2TypeSupport_var, ratehelpers::qlDepositRateHelper2TypeSupportImpl > ( DEPOSIT_RATE_HELPER2_TOPIC_NAME ); // setting up FRA Rate helper DDS::Topic_var fra_rate_helper2_topic = irs_participant.createTopicAndRegisterType < ratehelpers::qlFraRateHelper2TypeSupport_var, ratehelpers::qlFraRateHelper2TypeSupportImpl > ( FRA_RATE_HELPER2_TOPIC_NAME ); // setting up Swap Rate helper DDS::Topic_var swap_rate_helper2_topic = irs_participant.createTopicAndRegisterType < ratehelpers::qlSwapRateHelper2TypeSupport_var, ratehelpers::qlSwapRateHelper2TypeSupportImpl > ( SWAP_RATE_HELPER2_TOPIC_NAME ); irs_participant.createDataReaderListener< schedule::qlScheduleDataReaderListenerImpl> ( qldds_lock, schedule_topic ); irs_participant.createDataReaderListener< VanillaSwapDataReaderListenerImpl > ( qldds_lock, vanilla_swap_topic ); irs_participant.createDataReaderListener< DepositRateHelper2DataReaderListenerImpl > ( qldds_lock,deposit_rate_helper2_topic ); irs_participant.createDataReaderListener< FraRateHelper2DataReaderListenerImpl > ( qldds_lock, fra_rate_helper2_topic ); irs_participant.createDataReaderListener< SwapRateHelper2DataReaderListenerImpl > ( qldds_lock, swap_rate_helper2_topic ); // setting up IRS Portfolio. Priced portfolios will be published on this topic DDS::Topic_var irs_portfolio_topic = irs_participant.createTopicAndRegisterType < IRS::PortfolioTypeSupport_var, IRS::PortfolioTypeSupportImpl > ( IRS_PORTFOLIO_TOPIC_NAME ); IRS::PortfolioDataWriter_var irs_portfolio_dw = irs_participant.createDataWriter < IRS::PortfolioDataWriter_var, IRS::PortfolioDataWriter > ( irs_portfolio_topic ); curves.insert( std::pair < std::string, std::vector< std::string > > ( term_structure, rate_helpers ) ); int calculation_performed = 0; while ( calculation_performed < 30 ) { IRS::Portfolio irs_portfolio_out; if ( computeNPVs( term_structure, irs_portfolio_out ) == false ) { ACE_Time_Value sleep_100ms( 0, 100000 ); ACE_OS::sleep( sleep_100ms ); continue; } else { calculation_performed++; ACE_OS::sleep(1); } std::cout << "Calculator ["<< term_structure << "] publishing NPVs for "<< irs_portfolio_out.swaps.length() << " interest rate swaps."<< std::endl; int ret = irs_portfolio_dw->write( irs_portfolio_out, DDS::HANDLE_NIL ); if (ret != DDS::RETCODE_OK) { ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ERROR: IRS Portfolio write returned %d.\n"), ret)); } } } catch (CORBA::Exception& e) { cerr << "Exception caught in main.cpp:" << endl << e << endl; ACE_OS::exit(1); } TheServiceParticipant->shutdown(); return 0; }
// Listing 1 code/ch19 int HA_Status::init (int argc, ACE_TCHAR *argv[]) { static const ACE_TCHAR options[] = ACE_TEXT (":f:"); ACE_Get_Opt cmd_opts (argc, argv, options, 0); if (cmd_opts.long_option (ACE_TEXT ("config"), 'f', ACE_Get_Opt::ARG_REQUIRED) == -1) return -1; int option; ACE_TCHAR config_file[MAXPATHLEN]; ACE_OS::strcpy (config_file, ACE_TEXT ("HAStatus.conf")); while ((option = cmd_opts ()) != EOF) switch (option) { case 'f': ACE_OS::strncpy (config_file, cmd_opts.opt_arg (), MAXPATHLEN); break; case ':': ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("-%c requires an argument\n"), cmd_opts.opt_opt ()), -1); default: ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("Parse error.\n")), -1); } ACE_Configuration_Heap config; config.open (); ACE_Registry_ImpExp config_importer (config); if (config_importer.import_config (config_file) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), config_file), -1); ACE_Configuration_Section_Key status_section; if (config.open_section (config.root_section (), ACE_TEXT ("HAStatus"), 0, status_section) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("Can't open HAStatus section")), -1); u_int status_port; if (config.get_integer_value (status_section, ACE_TEXT ("ListenPort"), status_port) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("HAStatus ListenPort ") ACE_TEXT ("does not exist\n")), -1); this->listen_addr_.set (static_cast<u_short> (status_port)); if (this->acceptor_.open (this->listen_addr_) != 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("HAStatus %p\n"), ACE_TEXT ("accept")), -1); return 0; }