X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=protocol%2Futil%2FAsyncEventServer.cpp;h=68d97530ae7787cddcd78ba35637d455d0cc84da;hb=123d4092ff3137a112d07799858dc0957b8aceba;hp=386826d83561926ce1ecf11031b709c60b9c2388;hpb=a4be8ab869a87e9d71c9b8e7c5543c32c6c724bb;p=casparcg diff --git a/protocol/util/AsyncEventServer.cpp b/protocol/util/AsyncEventServer.cpp index 386826d83..68d97530a 100644 --- a/protocol/util/AsyncEventServer.cpp +++ b/protocol/util/AsyncEventServer.cpp @@ -31,7 +31,6 @@ #include #include -#include #include #include @@ -290,18 +289,17 @@ private: struct AsyncEventServer::implementation { - boost::asio::io_service service_; - tcp::acceptor acceptor_; - protocol_strategy_factory::ptr protocol_factory_; - spl::shared_ptr connection_set_; - boost::thread thread_; - std::vector lifecycle_factories_; + std::shared_ptr service_; + tcp::acceptor acceptor_; + protocol_strategy_factory::ptr protocol_factory_; + spl::shared_ptr connection_set_; + std::vector lifecycle_factories_; tbb::mutex mutex_; - implementation(const protocol_strategy_factory::ptr& protocol, unsigned short port) - : acceptor_(service_, tcp::endpoint(tcp::v4(), port)) + implementation(std::shared_ptr service, const protocol_strategy_factory::ptr& protocol, unsigned short port) + : service_(std::move(service)) + , acceptor_(*service_, tcp::endpoint(tcp::v4(), port)) , protocol_factory_(protocol) - , thread_([&] { service_.run(); }) { start_accept(); } @@ -317,19 +315,17 @@ struct AsyncEventServer::implementation CASPAR_LOG_CURRENT_EXCEPTION(); } - service_.post([=] + service_->post([=] { auto connections = *connection_set_; for (auto& connection : connections) connection->stop(); }); - - thread_.join(); } - void start_accept() + void start_accept() { - spl::shared_ptr socket(new tcp::socket(service_)); + spl::shared_ptr socket(new tcp::socket(*service_)); acceptor_.async_accept(*socket, std::bind(&implementation::handle_accept, this, socket, std::placeholders::_1)); } @@ -354,13 +350,13 @@ struct AsyncEventServer::implementation void add_client_lifecycle_object_factory(const lifecycle_factory_t& factory) { - service_.post([=]{ lifecycle_factories_.push_back(factory); }); + service_->post([=]{ lifecycle_factories_.push_back(factory); }); } }; AsyncEventServer::AsyncEventServer( - const protocol_strategy_factory::ptr& protocol, unsigned short port) - : impl_(new implementation(protocol, port)) {} + std::shared_ptr service, const protocol_strategy_factory::ptr& protocol, unsigned short port) + : impl_(new implementation(std::move(service), protocol, port)) {} AsyncEventServer::~AsyncEventServer() {} void AsyncEventServer::add_client_lifecycle_object_factory(const lifecycle_factory_t& factory) { impl_->add_client_lifecycle_object_factory(factory); }