Skip to content

Commit 27d4b9a

Browse files
committed
improve: fix warnings
1 parent 87c8150 commit 27d4b9a

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

rest/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ add_library(rest)
44
target_sources(rest PRIVATE server.cpp)
55
target_include_directories(rest INTERFACE ..)
66

7-
target_compile_definitions(rest PRIVATE BOOST_ALL_NO_LIB)
7+
target_compile_definitions(rest PRIVATE BOOST_ALL_NO_LIB BOOST_ASIO_NO_DEPRECATED)
88

99
if(WIN32)
1010
target_compile_definitions(rest PRIVATE _WIN32_WINNT=0x0601)

rest/session.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
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+
1316
class 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_;

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
add_definitions(-DBOOST_ALL_NO_LIB)
1+
add_definitions(-DBOOST_ALL_NO_LIB -DBOOST_ASIO_NO_DEPRECATED)
22

33
if(WIN32)
44
add_definitions(-D_WIN32_WINNT=0x0601)

0 commit comments

Comments
 (0)