From 0f5065d2a46cdd9d2be01d3b4bca75c774443b78 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Fri, 23 Nov 2018 19:27:30 -0500 Subject: [PATCH] librados/asio: add async_notify() to wrap aio_notify() Signed-off-by: Casey Bodley --- src/librados/librados_asio.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/librados/librados_asio.h b/src/librados/librados_asio.h index 3ddc1972c7c..6ff00e3d0e6 100644 --- a/src/librados/librados_asio.h +++ b/src/librados/librados_asio.h @@ -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 +auto async_notify(ExecutionContext& ctx, IoCtx& io, const std::string& oid, + bufferlist& bl, uint64_t timeout_ms, CompletionToken &&token) +{ + using Op = detail::AsyncOp; + using Signature = typename Op::Signature; + boost::asio::async_completion 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 -- 2.39.5