service.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #ifndef BOOST_BEAST_WEBSOCKET_DETAIL_SERVICE_HPP
  10. #define BOOST_BEAST_WEBSOCKET_DETAIL_SERVICE_HPP
  11. #include <boost/beast/core/detail/service_base.hpp>
  12. #include <boost/asio/execution_context.hpp>
  13. #include <boost/enable_shared_from_this.hpp>
  14. #include <mutex>
  15. #include <vector>
  16. namespace boost {
  17. namespace beast {
  18. namespace websocket {
  19. namespace detail {
  20. class service
  21. : public beast::detail::service_base<service>
  22. {
  23. public:
  24. class impl_type
  25. : public boost::enable_shared_from_this<impl_type>
  26. {
  27. service& svc_;
  28. std::size_t index_;
  29. friend class service;
  30. public:
  31. virtual ~impl_type() = default;
  32. BOOST_BEAST_DECL
  33. explicit
  34. impl_type(net::execution_context& ctx);
  35. BOOST_BEAST_DECL
  36. void
  37. remove();
  38. virtual
  39. void
  40. shutdown() = 0;
  41. };
  42. private:
  43. std::mutex m_;
  44. std::vector<impl_type*> v_;
  45. BOOST_BEAST_DECL
  46. void
  47. shutdown() override;
  48. public:
  49. BOOST_BEAST_DECL
  50. explicit
  51. service(net::execution_context& ctx)
  52. : beast::detail::service_base<service>(ctx)
  53. {
  54. }
  55. };
  56. } // detail
  57. } // websocket
  58. } // beast
  59. } // boost
  60. #if BOOST_BEAST_HEADER_ONLY
  61. #include <boost/beast/websocket/detail/service.ipp>
  62. #endif
  63. #endif