]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librados/asio: add async_notify() to wrap aio_notify()
authorCasey Bodley <cbodley@redhat.com>
Sat, 24 Nov 2018 00:27:30 +0000 (19:27 -0500)
committerCasey Bodley <cbodley@redhat.com>
Fri, 29 Mar 2019 15:12:49 +0000 (11:12 -0400)
Signed-off-by: Casey Bodley <cbodley@redhat.com>
src/librados/librados_asio.h

index 3ddc1972c7c38e499f28409693f645ebf0cf1ed0..6ff00e3d0e6b27f9f83772aa4fe8151599dcfcb5 100644 (file)
@@ -185,6 +185,29 @@ auto async_operate(ExecutionContext& ctx, IoCtx& io, const std::string& oid,
   return init.result.get();
 }
 
+/// Calls IoCtx::aio_notify() and arranges for the AioCompletion to call a
+/// given handler with signature (boost::system::error_code, bufferlist).
+template <typename ExecutionContext, typename CompletionToken>
+auto async_notify(ExecutionContext& ctx, IoCtx& io, const std::string& oid,
+                  bufferlist& bl, uint64_t timeout_ms, CompletionToken &&token)
+{
+  using Op = detail::AsyncOp<bufferlist>;
+  using Signature = typename Op::Signature;
+  boost::asio::async_completion<CompletionToken, Signature> init(token);
+  auto p = Op::create(ctx.get_executor(), init.completion_handler);
+  auto& op = p->user_data;
+
+  int ret = io.aio_notify(oid, op.aio_completion.get(),
+                          bl, timeout_ms, &op.result);
+  if (ret < 0) {
+    auto ec = boost::system::error_code{-ret, boost::system::system_category()};
+    ceph::async::post(std::move(p), ec, bufferlist{});
+  } else {
+    p.release(); // release ownership until completion
+  }
+  return init.result.get();
+}
+
 } // namespace librados
 
 #endif // LIBRADOS_ASIO_H