From: Casey Bodley Date: Sat, 24 Nov 2018 00:27:30 +0000 (-0500) Subject: librados/asio: add async_notify() to wrap aio_notify() X-Git-Tag: v15.0.0~26^2~7 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=0f5065d2a46cdd9d2be01d3b4bca75c774443b78;p=ceph-ci.git librados/asio: add async_notify() to wrap aio_notify() Signed-off-by: Casey Bodley --- 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