1//
2// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3//
4// Distributed under the Boost Software License, Version 1.0. (See accompanying
5// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6//
7// Official repository: https://github.com/boostorg/beast
8//
9
10#ifndef BOOST_BEAST_WEBSOCKET_DETAIL_SERVICE_IPP
11#define BOOST_BEAST_WEBSOCKET_DETAIL_SERVICE_IPP
12
13#include <boost/beast/websocket/detail/service.hpp>
14
15namespace boost {
16namespace beast {
17namespace websocket {
18namespace detail {
19
20service::
21impl_type::
22impl_type(net::execution_context& ctx)
23 : svc_(net::use_service<service>(e&: ctx))
24{
25 std::lock_guard<std::mutex> g(svc_.m_);
26 index_ = svc_.v_.size();
27 svc_.v_.push_back(x: this);
28}
29
30void
31service::
32impl_type::
33remove()
34{
35 std::lock_guard<std::mutex> g(svc_.m_);
36 auto& other = *svc_.v_.back();
37 other.index_ = index_;
38 svc_.v_[index_] = &other;
39 svc_.v_.pop_back();
40}
41
42//---
43
44void
45service::
46shutdown()
47{
48 std::vector<boost::weak_ptr<impl_type>> v;
49 {
50 std::lock_guard<std::mutex> g(m_);
51 v.reserve(n: v_.size());
52 for(auto p : v_)
53 v.emplace_back(args: p->weak_from_this());
54 }
55 for(auto wp : v)
56 if(auto sp = wp.lock())
57 sp->shutdown();
58}
59
60} // detail
61} // websocket
62} // beast
63} // boost
64
65#endif
66

source code of boost/libs/beast/include/boost/beast/websocket/detail/service.ipp