File indexing completed on 2025-01-18 09:29:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_BEAST_WEBSOCKET_DETAIL_SERVICE_IPP
0011 #define BOOST_BEAST_WEBSOCKET_DETAIL_SERVICE_IPP
0012
0013 #include <boost/beast/websocket/detail/service.hpp>
0014
0015 namespace boost {
0016 namespace beast {
0017 namespace websocket {
0018 namespace detail {
0019
0020 service::
0021 impl_type::
0022 impl_type(net::execution_context& ctx)
0023 : svc_(net::use_service<service>(ctx))
0024 {
0025 std::lock_guard<std::mutex> g(svc_.m_);
0026 index_ = svc_.v_.size();
0027 svc_.v_.push_back(this);
0028 }
0029
0030 void
0031 service::
0032 impl_type::
0033 remove()
0034 {
0035 std::lock_guard<std::mutex> g(svc_.m_);
0036 auto& other = *svc_.v_.back();
0037 other.index_ = index_;
0038 svc_.v_[index_] = &other;
0039 svc_.v_.pop_back();
0040 }
0041
0042
0043
0044 void
0045 service::
0046 shutdown()
0047 {
0048 std::vector<boost::weak_ptr<impl_type>> v;
0049 {
0050 std::lock_guard<std::mutex> g(m_);
0051 v.reserve(v_.size());
0052 for(auto p : v_)
0053 v.emplace_back(p->weak_from_this());
0054 }
0055 for(auto wp : v)
0056 if(auto sp = wp.lock())
0057 sp->shutdown();
0058 }
0059
0060 }
0061 }
0062 }
0063 }
0064
0065 #endif