-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_run.cpp
More file actions
26 lines (21 loc) · 763 Bytes
/
api_run.cpp
File metadata and controls
26 lines (21 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
int main() {
try {
// Boost.Asio setup
boost::asio::io_context ioc{1};
boost::asio::ip::tcp::acceptor acceptor{ioc, {boost::asio::ip::tcp::v4(), 8080}};
for (;;) {
boost::asio::ip::tcp::socket socket{ioc};
acceptor.accept(socket);
std::thread{[sock = std::move(socket)]() mutable {
beast::flat_buffer buffer;
http::request<http::string_body> req;
http::read(sock, buffer, req);
auto response = handle_requests(std::move(req));
http::write(sock, std::move(response));
}}.detach();
}
}
catch (std::exception const& e) {
std::cerr << "Error: " << e.what() << "\n";
}
}