File tree Expand file tree Collapse file tree 2 files changed +59
-6
lines changed
include/boost/beast2/server/detail Expand file tree Collapse file tree 2 files changed +59
-6
lines changed Original file line number Diff line number Diff line change 1616#include < boost/http_proto/method.hpp>
1717#include < boost/url/segments_encoded_view.hpp>
1818#include < boost/core/detail/string_view.hpp>
19- #include < memory>
2019#include < type_traits>
2120
2221namespace boost {
@@ -98,8 +97,14 @@ class any_router
9897 template <class Request , class Response , class Handler >
9998 struct errfn_impl ;
10099
101- any_router (
102- any_router const &) = default ;
100+ any_router () = default ;
101+
102+ BOOST_BEAST2_DECL ~any_router ();
103+ BOOST_BEAST2_DECL any_router (any_router&&) noexcept ;
104+ BOOST_BEAST2_DECL any_router (any_router const &) noexcept ;
105+ BOOST_BEAST2_DECL any_router& operator =(any_router&&) noexcept ;
106+ BOOST_BEAST2_DECL any_router& operator =(any_router const &) noexcept ;
107+
103108 BOOST_BEAST2_DECL any_router (
104109 http_proto::method (*)(void *),
105110 urls::segments_encoded_view&(*)(void *));
@@ -114,7 +119,7 @@ class any_router
114119 BOOST_BEAST2_DECL void append_err (errfn_ptr);
115120 void append (bool , http_proto::method, core::string_view) {}
116121
117- std::shared_ptr< impl> impl_;
122+ impl* impl_ = nullptr ;
118123};
119124
120125// ------------------------------------------------
Original file line number Diff line number Diff line change 1212#include < boost/beast2/server/detail/any_router.hpp>
1313#include < boost/beast2/error.hpp>
1414#include < boost/beast2/detail/except.hpp>
15- #include < map >
15+ #include < atomic >
1616#include < string>
1717#include < vector>
1818
@@ -56,6 +56,7 @@ struct any_router::entry
5656
5757struct any_router ::impl
5858{
59+ std::atomic<std::size_t > refs{1 };
5960 std::size_t size = 0 ;
6061 std::vector<entry> list;
6162 std::vector<errfn_ptr> errfns;
@@ -65,11 +66,58 @@ struct any_router::impl
6566
6667// ------------------------------------------------
6768
69+ any_router::
70+ ~any_router ()
71+ {
72+ if (! impl_)
73+ return ;
74+ if (--impl_->refs == 0 )
75+ delete impl_;
76+ }
77+
78+ any_router::
79+ any_router (any_router&& other) noexcept
80+ :impl_(other.impl_)
81+ {
82+ other.impl_ = nullptr ;
83+ }
84+
85+ any_router::
86+ any_router (any_router const & other) noexcept
87+ {
88+ impl_ = other.impl_ ;
89+ ++impl_->refs ;
90+ }
91+
92+ any_router&
93+ any_router::
94+ operator =(any_router&& other) noexcept
95+ {
96+ auto p = impl_;
97+ impl_ = other.impl_ ;
98+ other.impl_ = nullptr ;
99+ if (p && --p->refs == 0 )
100+ delete p;
101+ return *this ;
102+ }
103+
104+ any_router&
105+ any_router::
106+ operator =(any_router const & other) noexcept
107+ {
108+ auto p = impl_;
109+ impl_ = other.impl_ ;
110+ ++impl_->refs ;
111+ if (p && --p->refs == 0 )
112+ delete p;
113+ return *this ;
114+ }
115+
68116any_router::
69117any_router (
70118 http_proto::method (*get_method)(void *),
71119 urls::segments_encoded_view&(*get_path)(void *))
72- : impl_(std::make_shared< impl>() )
120+ : impl_(new impl)
73121{
74122 impl_->get_path = get_path;
75123 impl_->get_method = get_method;
You can’t perform that action at this time.
0 commit comments