]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/async: use asio::associator for Forwarding/CompletionHandler
authorCasey Bodley <cbodley@redhat.com>
Mon, 14 Oct 2024 18:44:19 +0000 (14:44 -0400)
committerCasey Bodley <cbodley@redhat.com>
Tue, 15 Oct 2024 01:59:15 +0000 (21:59 -0400)
asio keeps adding new types of associations. since this was written,
get_associated_cancellation_slot() and
get_associated_immediate_executor() were added. we can now specialize
the asio::associator<> template to forward all of them

Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/common/async/bind_handler.h
src/common/async/forward_handler.h

index 69128501a07f7d4cd01193d5501eb8765dbe07b1..4cc9a2a113d20c97be7bdac6c4f279ba0daff2b5 100644 (file)
@@ -16,8 +16,7 @@
 #define CEPH_ASYNC_BIND_HANDLER_H
 
 #include <tuple>
-#include <boost/asio/associated_allocator.hpp>
-#include <boost/asio/associated_executor.hpp>
+#include <boost/asio/associator.hpp>
 
 namespace ceph::async {
 
@@ -52,25 +51,25 @@ struct CompletionHandler {
   void operator()() && {
     std::apply(std::move(handler), std::move(args));
   }
-
-  using allocator_type = boost::asio::associated_allocator_t<Handler>;
-  allocator_type get_allocator() const noexcept {
-    return boost::asio::get_associated_allocator(handler);
-  }
 };
 
 } // namespace ceph::async
 
 namespace boost::asio {
 
-// specialize boost::asio::associated_executor<> for CompletionHandler
-template <typename Handler, typename Tuple, typename Executor>
-struct associated_executor<ceph::async::CompletionHandler<Handler, Tuple>, Executor> {
-  using type = boost::asio::associated_executor_t<Handler, Executor>;
-
-  static type get(const ceph::async::CompletionHandler<Handler, Tuple>& handler,
-                  const Executor& ex = Executor()) noexcept {
-    return boost::asio::get_associated_executor(handler.handler, ex);
+// forward the handler's associated executor, allocator, cancellation slot, etc
+template <template <typename, typename> class Associator,
+          typename Handler, typename Tuple, typename DefaultCandidate>
+struct associator<Associator,
+    ceph::async::CompletionHandler<Handler, Tuple>, DefaultCandidate>
+  : Associator<Handler, DefaultCandidate>
+{
+  static auto get(const ceph::async::CompletionHandler<Handler, Tuple>& h) noexcept {
+    return Associator<Handler, DefaultCandidate>::get(h.handler);
+  }
+  static auto get(const ceph::async::CompletionHandler<Handler, Tuple>& h,
+                  const DefaultCandidate& c) noexcept {
+    return Associator<Handler, DefaultCandidate>::get(h.handler, c);
   }
 };
 
index 1491ef6085d4fa6ace198fc3069481ae0c7de7a9..e204ca9862c3569447dcf31614a649c8616cf0dd 100644 (file)
@@ -15,8 +15,7 @@
 #ifndef CEPH_ASYNC_FORWARD_HANDLER_H
 #define CEPH_ASYNC_FORWARD_HANDLER_H
 
-#include <boost/asio/associated_allocator.hpp>
-#include <boost/asio/associated_executor.hpp>
+#include <boost/asio/associator.hpp>
 
 namespace ceph::async {
 
@@ -47,25 +46,25 @@ struct ForwardingHandler {
   void operator()(Args&& ...args) {
     std::move(handler)(std::forward<Args>(args)...);
   }
-
-  using allocator_type = boost::asio::associated_allocator_t<Handler>;
-  allocator_type get_allocator() const noexcept {
-    return boost::asio::get_associated_allocator(handler);
-  }
 };
 
 } // namespace ceph::async
 
 namespace boost::asio {
 
-// specialize boost::asio::associated_executor<> for ForwardingHandler
-template <typename Handler, typename Executor>
-struct associated_executor<ceph::async::ForwardingHandler<Handler>, Executor> {
-  using type = boost::asio::associated_executor_t<Handler, Executor>;
-
-  static type get(const ceph::async::ForwardingHandler<Handler>& handler,
-                  const Executor& ex = Executor()) noexcept {
-    return boost::asio::get_associated_executor(handler.handler, ex);
+// forward the handler's associated executor, allocator, cancellation slot, etc
+template <template <typename, typename> class Associator,
+          typename Handler, typename DefaultCandidate>
+struct associator<Associator,
+    ceph::async::ForwardingHandler<Handler>, DefaultCandidate>
+  : Associator<Handler, DefaultCandidate>
+{
+  static auto get(const ceph::async::ForwardingHandler<Handler>& h) noexcept {
+    return Associator<Handler, DefaultCandidate>::get(h.handler);
+  }
+  static auto get(const ceph::async::ForwardingHandler<Handler>& h,
+                  const DefaultCandidate& c) noexcept {
+    return Associator<Handler, DefaultCandidate>::get(h.handler, c);
   }
 };