15 const std::shared_ptr<application::AppStateManager> &app_state_manager,
19 context_{std::make_shared<Context>()},
20 config_{std::move(exposer_config)},
22 BOOST_ASSERT(app_state_manager);
23 app_state_manager->takeControl(*
this);
33 }
catch (
const boost::wrapexcept<boost::system::system_error> &exception) {
35 logger_,
"Failed to prepare a listener: {}", exception.what());
37 }
catch (
const std::exception &exception) {
39 logger_,
"Exception when preparing a listener: {}", exception.what());
43 boost::system::error_code ec;
44 acceptor_->set_option(boost::asio::socket_base::reuse_address(
true), ec);
46 logger_->error(
"Failed to set `reuse address` option to acceptor");
56 logger_->error(
"error: trying to start on non opened acceptor");
60 logger_->info(
"Listening for new connections on {}:{}",
65 thread_ = std::make_shared<std::thread>(
66 [context =
context_]() { context->run(); });
83 std::placeholders::_1,
84 std::placeholders::_2));
86 auto on_accept = [wp = weak_from_this()](boost::system::error_code ec) {
87 if (
auto self = wp.lock()) {
89 self->new_session_->start();
92 if (self->acceptor_->is_open()) {
std::shared_ptr< std::thread > thread_
std::unique_ptr< Acceptor > acceptor_
bool start() override
start interface for AppStateManager
std::shared_ptr< Session > new_session_
ExposerImpl(const std::shared_ptr< application::AppStateManager > &app_state_manager, Exposer::Configuration exposer_config, Session::Configuration session_config)
virtual void onSessionRequest(Session::Request request, std::shared_ptr< Session > session)=0
main interface for session request handling
const Session::Configuration session_config_
std::unique_ptr< Acceptor > acceptOnFreePort(std::shared_ptr< boost::asio::io_context > context, Endpoint endpoint, uint16_t port_tolerance, const log::Logger &logger)
const Configuration config_
bool prepare() override
prepare interface for AppStateManager
std::shared_ptr< Handler > handler_
void stop() override
stop interface for AppStateManager
constexpr uint16_t kDefaultPortTolerance
Logger createLogger(const std::string &tag)
std::shared_ptr< Context > context_