@@ -268,6 +268,65 @@ auto async_operate(IoExecutor ex, IoCtx& io, const std::string& oid,
268268 }, token, ex, io, oid, std::move (write_op), flags, trace_ctx);
269269}
270270
271+ // / Calls IoCtx::aio_watch2() and arranges for the AioCompletion to call a
272+ // / given handler with signature (error_code, version_t).
273+ // /
274+ // / The given IoCtx reference is not required to remain valid, but some IoCtx
275+ // / instance must preserve its underlying implementation until completion.
276+ template <boost::asio::execution::executor IoExecutor, typename CompletionToken>
277+ auto async_watch (IoExecutor ex, IoCtx& io, const std::string& oid,
278+ uint64_t * handle, librados::WatchCtx2* ctx,
279+ uint32_t timeout_ms, CompletionToken &&token)
280+ {
281+ using Op = detail::AsyncOp<void >;
282+ using Signature = typename Op::Signature;
283+ return boost::asio::async_initiate<CompletionToken, Signature>(
284+ [] (auto handler, IoExecutor ex, const IoCtx& i, const std::string& oid,
285+ uint64_t * handle, librados::WatchCtx2* ctx, uint32_t timeout_ms) {
286+ constexpr bool is_read = false ;
287+ auto p = Op::create (ex, is_read, std::move (handler));
288+ auto & op = p->user_data ;
289+
290+ IoCtx& io = const_cast <IoCtx&>(i);
291+ int ret = io.aio_watch2 (oid, op.aio_completion .get (),
292+ handle, ctx, timeout_ms);
293+ if (ret < 0 ) {
294+ auto ec = boost::system::error_code{-ret, librados::detail::err_category ()};
295+ ceph::async::post (std::move (p), ec, 0 );
296+ } else {
297+ p.release (); // release ownership until completion
298+ }
299+ }, token, ex, io, oid, handle, ctx, timeout_ms);
300+ }
301+
302+ // / Calls IoCtx::aio_unwatch() and arranges for the AioCompletion to call a
303+ // / given handler with signature (error_code, version_t).
304+ // /
305+ // / The given IoCtx reference is not required to remain valid, but some IoCtx
306+ // / instance must preserve its underlying implementation until completion.
307+ template <boost::asio::execution::executor IoExecutor, typename CompletionToken>
308+ auto async_unwatch (IoExecutor ex, IoCtx& io, uint64_t handle,
309+ CompletionToken &&token)
310+ {
311+ using Op = detail::AsyncOp<void >;
312+ using Signature = typename Op::Signature;
313+ return boost::asio::async_initiate<CompletionToken, Signature>(
314+ [] (auto handler, IoExecutor ex, const IoCtx& i, uint64_t handle) {
315+ constexpr bool is_read = false ;
316+ auto p = Op::create (ex, is_read, std::move (handler));
317+ auto & op = p->user_data ;
318+
319+ IoCtx& io = const_cast <IoCtx&>(i);
320+ int ret = io.aio_unwatch (handle, op.aio_completion .get ());
321+ if (ret < 0 ) {
322+ auto ec = boost::system::error_code{-ret, librados::detail::err_category ()};
323+ ceph::async::post (std::move (p), ec, 0 );
324+ } else {
325+ p.release (); // release ownership until completion
326+ }
327+ }, token, ex, io, handle);
328+ }
329+
271330// / Calls IoCtx::aio_notify() and arranges for the AioCompletion to call a
272331// / given handler with signature (error_code, version_t, bufferlist).
273332// /
0 commit comments