From 211869c631576f0be064174aca30b316f3484040 Mon Sep 17 00:00:00 2001 From: Sithas777 Date: Wed, 13 Sep 2023 16:20:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83?= =?UTF-8?q?=D0=BA=D1=82=D0=BE=D1=80=20Listener'=D0=B0=20=D1=81=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/listener.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/listener.h b/src/listener.h index 85cffee..b072c40 100644 --- a/src/listener.h +++ b/src/listener.h @@ -18,6 +18,23 @@ 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 \ No newline at end of file