#include <workflow/WFFacilities.h> //facilities 设施
#include <iostream>
#include <signal.h>
#include <workflow/WFHttpServer.h> //服务端
using namespace std;
static WFFacilities::WaitGroup wait_group(1);
void sighandler(int signum)
{
wait_group.done();
cout << "signal go\n";
}
void process(WFHttpTask *servertask)
{ // process是用户写的
//cout << "process" << endl;
protocol::HttpRequest *req = servertask->get_req();
protocol::HttpResponse *resp = servertask->get_resp();
// 获取请求体
const void *body;
size_t body_len;
req->get_parsed_body(&body, &body_len);
// 设置响应体
resp->append_output_body(body, body_len);
}
int main()
{
signal(SIGINT, sighandler);
WFHttpServer server(process);
if (server.start(8080) == 0) // 成功
{
// start是非阻塞的
cout << "server start success" << endl;
wait_group.wait();
server.stop(); // 停止服务器
return 0;
}
else
{
cout << "server start failed" << endl;
return -1;
}
}
基于c++的workflow框架实现个http简单echo服务端
于 2025-02-26 13:02:49 首次发布