重新启动应用程序:延迟
Restarting Application: Delay
我正在将重启功能编码到我最新的孤岛危机服务器修改中,该功能可以远程重新启动服务器。如果服务器出现问题并且简单的系统重新加载无法修复它,这很有用,对于告诉服务器在指定时间重新启动以释放内存也很有用。
为了实现这一点,我已经编写了所需的函数,并且应用程序本身重新启动没有问题。问题是端口关闭速度不够快,导致应用程序的新实例无法正常运行。
我正在寻找一个理想的解决方案,即程序关闭并在两秒钟后启动,而不是立即启动。这样做将使 Windows 有足够的时间来释放服务器正在使用的端口,并清理任何现有内存。
请注意:我已经删除了我的其他(相关)问题,因为显然关闭程序端口是不可能的,除非在分配端口时告诉它这样做,这是我无法做到的,因为我无法访问绑定到端口的代码的源代码。
代码(如果需要)
int CScriptBind_GameRules::Restart(IFunctionHandler *pH)
{
bool arg1 = false;
const char *arg2 = "";
gEnv->pScriptSystem->BeginCall("Dynamic","GetValue");
gEnv->pScriptSystem->PushFuncParam("r.enable");
gEnv->pScriptSystem->EndCall(arg1);
gEnv->pScriptSystem->BeginCall("Dynamic","GetValue");
gEnv->pScriptSystem->PushFuncParam("r.line");
gEnv->pScriptSystem->EndCall(arg2);
if (arg1)
{
LogMsg(2, "System restart initiated.");
if (arg2)
{
LogMsg(2, "System Reboot.");
gEnv->pScriptSystem->BeginCall("os","execute");
gEnv->pScriptSystem->PushFuncParam(arg2);
gEnv->pScriptSystem->EndCall(), close((int)gEnv->pConsole->GetCVar("sv_port")->GetString());
return pH->EndFunction();
}
else
{
LogMsg(2, "Internal Faliure.");
return pH->EndFunction();
}
return pH->EndFunction();
}
LogMsg(2, "System restart cancelled: Feature is Disabled.");
return pH->EndFunction();
}
我通常做的是添加一个命令行参数'StartupDelay'。 当服务器/任何东西启动时,在尝试运行侦听器等之前,它会检查该参数。如果没有参数,它正常运行,如果它找到"StartupDelay=2000",它会休眠 2 秒,然后尝试启动侦听器等。
结果 - 如果从桌面图标启动,它将立即启动。如果它需要"重新启动自身",它会设置参数以指示自身的新实例按照指示等待。
相关文章:
- 试图在visual studio上用C++创建一个桌面应用程序
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 在C应用程序中运行C++(带有STL)函数
- 使用VerQueryValue检索应用程序的文件描述
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 使用调试/崩溃报告将应用程序部署到客户端
- C++控制台应用程序阻止退出
- 我的 SDL2 应用程序仅在第一次键盘输入后出现严重延迟
- WINDOWS环境下的c++opencv应用程序的低延迟视频流
- c++UDP中继应用程序延迟
- 重新启动应用程序:延迟
- 如何测量低延迟 c++ 应用程序的延迟
- 如何提高多线程应用程序的延迟
- 我的应用程序加载缓慢或延迟
- 在最坏的情况下,多少QPI延迟可以减慢任意应用程序的速度
- 如何在不停止应用程序的情况下延迟一个函数
- 如何度量在多核系统上运行的多个应用程序之间的消息延迟
- 设计问题:从低延迟的c++应用程序更新数据库
- 网络延迟和应用程序>进程消息()
- UWP Windows 10 Direct3D 12 应用程序C++ KeyDown 延迟