Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
ZLMediaKit
概览
Overview
Details
Activity
Cycle Analytics
版本库
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
问题
0
Issues
0
列表
Board
标记
里程碑
合并请求
0
Merge Requests
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
Snippets
成员
Collapse sidebar
Close sidebar
活动
图像
聊天
创建新问题
作业
提交
Issue Boards
Open sidebar
张翔宇
ZLMediaKit
Commits
052cca07
Unverified
Commit
052cca07
authored
Dec 19, 2021
by
lawrencehj
Committed by
GitHub
Dec 19, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
实现Windows系统下restartServer API接口 (#1292)
parent
ee13ca57
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
59 行增加
和
0 行删除
+59
-0
server/WebApi.cpp
+59
-0
没有找到文件。
server/WebApi.cpp
查看文件 @
052cca07
...
...
@@ -42,6 +42,12 @@
#include "../webrtc/WebRtcPusher.h"
#include "../webrtc/WebRtcEchoTest.h"
#endif
#ifdef _WIN32
#include <io.h>
#include <iostream>
#include <tchar.h>
#endif // _WIN32
using
namespace
toolkit
;
using
namespace
mediakit
;
...
...
@@ -508,6 +514,59 @@ void installWebApi() {
});
val
[
"msg"
]
=
"服务器将在一秒后自动重启"
;
});
#else
//增加Windows下的重启代码
api_regist
(
"/index/api/restartServer"
,
[](
API_ARGS_MAP
)
{
CHECK_SECRET
();
//创建重启批处理脚本文件
FILE
*
pf
;
errno_t
err
=
::
_wfopen_s
(
&
pf
,
L"RestartServer.cmd"
,
L"w"
);
//“w”如果该文件存在,其内容将被覆盖
if
(
err
==
0
)
{
char
szExeName
[
1024
];
char
drive
[
_MAX_DRIVE
]
=
{
0
};
char
dir
[
_MAX_DIR
]
=
{
0
};
char
fname
[
_MAX_FNAME
]
=
{
0
};
char
ext
[
_MAX_EXT
]
=
{
0
};
char
exeName
[
_MAX_FNAME
]
=
{
0
};
GetModuleFileNameA
(
NULL
,
szExeName
,
1024
);
//获取进程的全路径
_splitpath
(
szExeName
,
drive
,
dir
,
fname
,
ext
);
strcpy
(
exeName
,
fname
);
strcat
(
exeName
,
ext
);
fprintf
(
pf
,
"@echo off
\n
taskkill /f /im %s
\n
start
\"\"
\"
%s
\"\n
del %%0"
,
exeName
,
szExeName
);
fclose
(
pf
);
// 1秒后执行创建的批处理脚本
EventPollerPool
::
Instance
().
getPoller
()
->
doDelayTask
(
1000
,
[]()
{
STARTUPINFO
si
;
PROCESS_INFORMATION
pi
;
ZeroMemory
(
&
si
,
sizeof
si
);
ZeroMemory
(
&
pi
,
sizeof
pi
);
si
.
cb
=
sizeof
si
;
si
.
dwFlags
=
STARTF_USESHOWWINDOW
;
si
.
wShowWindow
=
SW_HIDE
;
TCHAR
winSysDir
[
1024
];
ZeroMemory
(
winSysDir
,
sizeof
winSysDir
);
GetSystemDirectory
(
winSysDir
,
1024
);
TCHAR
appName
[
1024
];
ZeroMemory
(
appName
,
sizeof
appName
);
_stprintf
(
appName
,
"%s
\\
cmd.exe"
,
winSysDir
);
BOOL
bRet
=
CreateProcess
(
appName
,
" /c RestartServer.cmd"
,
NULL
,
NULL
,
FALSE
,
0
,
NULL
,
NULL
,
&
si
,
&
pi
);
if
(
bRet
==
FALSE
)
{
int
err
=
GetLastError
();
cout
<<
endl
<<
"无法执行重启操作,错误代码:"
<<
err
<<
endl
;
}
WaitForSingleObject
(
pi
.
hProcess
,
INFINITE
);
CloseHandle
(
pi
.
hProcess
);
CloseHandle
(
pi
.
hThread
);
return
0
;
});
val
[
"msg"
]
=
"服务器将在一秒后自动重启"
;
}
else
{
val
[
"msg"
]
=
"创建重启脚本文件失败"
;
val
[
"code"
]
=
API
::
OtherFailed
;
}
});
#endif//#if !defined(_WIN32)
//获取流列表,可选筛选参数
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论