1 Star 0 Fork 0

蝎子莱莱xo/cpp_projects

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
compile_server.cc 1.85 KB
一键复制 编辑 原始数据 按行查看 历史
lmx-xo 提交于 1年前 . 顶层makefile
#include "compile_run.hpp"
#include "../comm/httplib.h"
using namespace ns_compiler;
using namespace ns_runner;
using namespace ns_compile_and_run;
using namespace httplib;
void Usage(const string proc)
{
std::cerr << "Usage: " << "\n\t" << proc << "port" << endl;
}
int main(int argc, char *argv[])
{
if(argc != 2)
{
Usage(argv[0]);
return 1;
}
Server svr;
//用户如果请求根目录下的hello服务,服务器就会调用回调函数并返回响应
svr.Get("/hello", [](const Request &req, Response &resp){
//content-type中text/plain表示文本格式
//编码格式设置为为utf-8
resp.set_content("hello httplib!", "text/plain;charset=utf-8");
});
svr.Post("/compile_and_run", [](const Request &req, Response &resp){
//用户请求的服务正文是我们想要的json string
string in_json = req.body;
string out_json;
if(!in_json.empty())
{
CompileAndRun::Start(in_json, &out_json);
resp.set_content(out_json, "application/json;charset=utf-8");
}
});
svr.listen("0.0.0.0", atoi(argv[1]));
// std::string file = "code";
// Compiler::Compile(file);
// Runner::Run(file, 10, 10);
// //充当客户端请求的json串
// string in_json;
// Json::Value in_value;
// //c++11原生字符串:R"()"
// in_value["code"] = R"(#include<iostream>
// int main()
// {
// std::cout << "hello world" << std::endl;
// return 0;
// })";
// in_value["input"] = "";
// in_value["cpu_limit"] = 1;
// in_value["mem_limit"] = 10240 * 3;
// Json::FastWriter writer;
// in_json = writer.write(in_value);
// // cout << in_json << endl;
// string out_json;
// CompileAndRun::Start(in_json, &out_json);
// cout << out_json << endl;
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/lmx-xo/cpp_projects.git
git@gitee.com:lmx-xo/cpp_projects.git
lmx-xo
cpp_projects
cpp_projects
master

搜索帮助