class session_http {
public:
session_http(boost::asio::io_context &io) : socket_(io) {};
void run(boost::asio::yield_context yield) {
boost::system::error_code ec;
boost::beast::flat_buffer buffer;
while (true) {
// Read a request
boost::beast::http::async_read(socket_, buffer, req_, yield[ec]);
if(ec) {
BOOST_LOG_TRIVIAL(error) << "Read fail: " << ec.message();
break;
}
BOOST_LOG_TRIVIAL(debug) << "Read: " << req_;
BOOST_LOG_TRIVIAL(info) << "Read: " << req_.method_string() << " " << req_.target();
send_response(yield, "success");
if(req_.need_eof()) {// ture means Connection: close
// This means we should close the connection, usually because
// the response indicated the "Connection: close" semantic.
break;
}
req_.body().clear();
}
// Send a TCP shutdown
socket_.shutdown(boost::asio::ip::tcp:
使用boost::asio库实现多个子进程监听同一个端口
最新推荐文章于 2024-10-09 11:08:52 发布