From ef5282ebcff9e2de3eb021091e0d3c63d262c698 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Wed, 27 Feb 2019 16:39:47 -0800 Subject: [PATCH] Tidy up websocket service --- include/boost/beast/src.hpp | 1 + .../boost/beast/websocket/detail/service.hpp | 36 +++------- .../boost/beast/websocket/detail/service.ipp | 65 +++++++++++++++++++ 3 files changed, 74 insertions(+), 28 deletions(-) create mode 100644 include/boost/beast/websocket/detail/service.ipp diff --git a/include/boost/beast/src.hpp b/include/boost/beast/src.hpp index d564dd73..5fdc050f 100644 --- a/include/boost/beast/src.hpp +++ b/include/boost/beast/src.hpp @@ -46,6 +46,7 @@ the program, with the macro BOOST_BEAST_SPLIT_COMPILATION defined. #include #include +#include #include #include diff --git a/include/boost/beast/websocket/detail/service.hpp b/include/boost/beast/websocket/detail/service.hpp index b34e4215..c9a493b4 100644 --- a/include/boost/beast/websocket/detail/service.hpp +++ b/include/boost/beast/websocket/detail/service.hpp @@ -36,25 +36,13 @@ public: public: virtual ~impl_type() = default; + BOOST_BEAST_DECL explicit - impl_type(net::execution_context& ctx) - : svc_(net::use_service(ctx)) - { - std::lock_guard g(svc_.m_); - index_ = svc_.v_.size(); - svc_.v_.push_back(this); - } + impl_type(net::execution_context& ctx); BOOST_BEAST_DECL void - remove() - { - std::lock_guard g(svc_.m_); - auto& other = *svc_.v_.back(); - other.index_ = index_; - svc_.v_[index_] = &other; - svc_.v_.pop_back(); - } + remove(); virtual void @@ -67,19 +55,7 @@ private: BOOST_BEAST_DECL void - shutdown() override - { - std::vector> v; - { - std::lock_guard g(m_); - v.reserve(v_.size()); - for(auto p : v_) - v.emplace_back(p->weak_from_this()); - } - for(auto wp : v) - if(auto sp = wp.lock()) - sp->shutdown(); - } + shutdown() override; public: BOOST_BEAST_DECL @@ -95,4 +71,8 @@ public: } // beast } // boost +#if BOOST_BEAST_HEADER_ONLY +#include +#endif + #endif diff --git a/include/boost/beast/websocket/detail/service.ipp b/include/boost/beast/websocket/detail/service.ipp new file mode 100644 index 00000000..86e9a972 --- /dev/null +++ b/include/boost/beast/websocket/detail/service.ipp @@ -0,0 +1,65 @@ +// +// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// Official repository: https://github.com/boostorg/beast +// + +#ifndef BOOST_BEAST_WEBSOCKET_DETAIL_SERVICE_IPP +#define BOOST_BEAST_WEBSOCKET_DETAIL_SERVICE_IPP + +#include + +namespace boost { +namespace beast { +namespace websocket { +namespace detail { + +service:: +impl_type:: +impl_type(net::execution_context& ctx) + : svc_(net::use_service(ctx)) +{ + std::lock_guard g(svc_.m_); + index_ = svc_.v_.size(); + svc_.v_.push_back(this); +} + +void +service:: +impl_type:: +remove() +{ + std::lock_guard g(svc_.m_); + auto& other = *svc_.v_.back(); + other.index_ = index_; + svc_.v_[index_] = &other; + svc_.v_.pop_back(); +} + +//--- + +void +service:: +shutdown() +{ + std::vector> v; + { + std::lock_guard g(m_); + v.reserve(v_.size()); + for(auto p : v_) + v.emplace_back(p->weak_from_this()); + } + for(auto wp : v) + if(auto sp = wp.lock()) + sp->shutdown(); +} + +} // detail +} // websocket +} // beast +} // boost + +#endif