77#include < boost/asio/dispatch.hpp>
88#include < boost/beast/core/flat_buffer.hpp>
99#include < boost/beast/core/tcp_stream.hpp>
10+ #include < boost/beast/http.hpp>
1011
1112#include " logger.h"
1213
14+ namespace http = boost::beast::http;
15+
1316class session : public std ::enable_shared_from_this<session> {
1417 using error_code = boost::beast::error_code;
1518 using tcp = boost::asio::ip::tcp;
@@ -32,7 +35,8 @@ class session : public std::enable_shared_from_this<session> {
3235 // otherwise the operation behavior is undefined.
3336 req_ = {};
3437 stream_.expires_after (std::chrono::seconds (30 ));
35- http::async_read (stream_, buffer_, req_, boost::beast::bind_front_handler (&session::on_read, shared_from_this ()));
38+ http::async_read (stream_, buffer_, req_,
39+ boost::beast::bind_front_handler (&session::on_read, shared_from_this ()));
3640 }
3741
3842 void on_read (error_code ec, std::size_t bytes_transferred) {
@@ -68,13 +72,18 @@ class session : public std::enable_shared_from_this<session> {
6872 void do_close () {
6973 error_code ec;
7074 stream_.socket ().shutdown (tcp::socket::shutdown_send, ec);
75+
76+ if (ec && ec != boost::asio::error::not_connected) {
77+ fail (ec, " shutdown" );
78+ }
7179 }
7280
7381 template <class Body , class Fields >
7482 void send (http::response<Body, Fields> &&msg) {
7583 auto sp = std::make_shared<typename std::remove_reference<decltype (msg)>::type>(std::move (msg));
7684 res_ = sp;
77- http::async_write (stream_, *sp, boost::beast::bind_front_handler (&session::on_write, shared_from_this (), sp->need_eof ()));
85+ http::async_write (stream_, *sp,
86+ boost::beast::bind_front_handler (&session::on_write, shared_from_this (), sp->need_eof ()));
7887 }
7988
8089 boost::beast::tcp_stream stream_;
0 commit comments