#pragma once #include "sdk.h" // boost.beast будет использовать std::string_view вместо boost::string_view #define BOOST_BEAST_USE_STD_STRING_VIEW #include #include #include #include namespace http_server { namespace net = boost::asio; using tcp = net::ip::tcp; namespace beast = boost::beast; namespace http = beast::http; template class Listener : public std::enable_shared_from_this> { net::io_context& ioc_; tcp::acceptor acceptor_; RequestHandler request_handler_; public: template Listener(net::io_context& ioc, const tcp::endpoint& endpoint, Handler&& request_handler) : ioc_(ioc), acceptor_(net::make_strand(ioc)), request_handler_(std::forward(request_handler)) { acceptor_.open(endpoint.protocol()); acceptor_.set_option(net::socket_base::reuse_address(true)); acceptor_.bind(endpoint); acceptor_.listen(net::socket_base::max_listen_connections); } }; } // namespace http_server