]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/async/librados_completion.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2020 Red Hat
7 * Author: Adam C. Emerson <aemerson@redhat.com>
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
16 #ifndef CEPH_COMMON_ASYNC_LIBRADOS_COMPLETION_H
17 #define CEPH_COMMON_ASYNC_LIBRADOS_COMPLETION_H
20 #include <condition_variable>
23 #include <type_traits>
25 #include <boost/asio/async_result.hpp>
27 #include <boost/system/error_code.hpp>
28 #include <boost/system/system_error.hpp>
30 #include "include/rados/librados.hpp"
31 #include "librados/AioCompletionImpl.h"
33 // Allow librados::AioCompletion to be provided as a completion
34 // handler. This is only allowed with a signature of
35 // (boost::system::error_code) or (). On completion the AioCompletion
36 // is completed with the error_code converted to an int with
37 // ceph::from_error_code.
39 // async_result::return_type is void.
41 namespace ceph::async
{
43 namespace bs
= boost::system
;
44 namespace lr
= librados
;
48 struct librados_handler
{
49 lr::AioCompletionImpl
* pc
;
51 explicit librados_handler(lr::AioCompletion
* c
) : pc(c
->pc
) {
61 librados_handler(const librados_handler
&) = delete;
62 librados_handler
& operator =(const librados_handler
&) = delete;
63 librados_handler(librados_handler
&& rhs
) {
68 void operator()(bs::error_code ec
) {
70 pc
->rval
= ceph::from_error_code(ec
);
74 auto cb_complete
= pc
->callback_complete
;
75 auto cb_complete_arg
= pc
->callback_complete_arg
;
77 cb_complete(pc
, cb_complete_arg
);
79 auto cb_safe
= pc
->callback_safe
;
80 auto cb_safe_arg
= pc
->callback_safe_arg
;
82 cb_safe(pc
, cb_safe_arg
);
85 pc
->callback_complete
= NULL
;
86 pc
->callback_safe
= NULL
;
87 pc
->cond
.notify_all();
93 (*this)(bs::error_code
{});
97 } // namespace ceph::async
100 namespace boost::asio
{
101 template<typename ReturnType
>
102 class async_result
<librados::AioCompletion
*, ReturnType()> {
104 using completion_handler_type
= ceph::async::detail::librados_handler
;
105 explicit async_result(completion_handler_type
&) {};
106 using return_type
= void;
112 template<typename ReturnType
>
113 class async_result
<librados::AioCompletion
*,
114 ReturnType(boost::system::error_code
)> {
116 using completion_handler_type
= ceph::async::detail::librados_handler
;
117 explicit async_result(completion_handler_type
&) {};
118 using return_type
= void;
125 #endif // !CEPH_COMMON_ASYNC_LIBRADOS_COMPLETION_H