24template <CQEHandlerLike CQEHandler,
typename Receiver>
25class OpFinishHandle :
public OpFinishHandleBase {
27 OpFinishHandle(CQEHandler cqe_handler, Receiver receiver)
28 : cqe_handler_(std::move(cqe_handler)), receiver_(std::move(receiver)) {
29 this->handle_func_ = handle_static_;
32 CONDY_DELETE_COPY_MOVE(OpFinishHandle);
35 void maybe_set_cancel(Runtime *runtime)
noexcept {
36 auto stop_token = receiver_.get_stop_token();
37 if (stop_token.stop_possible()) {
38 stop_callback_.emplace(std::move(stop_token),
39 Cancellation{
this, runtime});
44 static bool handle_static_(
void *data, io_uring_cqe *cqe)
noexcept {
45 auto *self =
static_cast<OpFinishHandle *
>(data);
46 return self->handle_impl_(cqe);
49 bool handle_impl_(io_uring_cqe *cqe)
noexcept {
57 void operator()() noexcept {
58 runtime->cancel_internal(encode_work(self, WorkType::Common));
62 using StopCallbackType =
63 stop_callback_t<stop_token_t<Receiver>, Cancellation>;
66 void finish_(io_uring_cqe *cqe)
noexcept {
67 stop_callback_.reset();
68 std::move(receiver_)(cqe_handler_(cqe));
71 CQEHandler cqe_handler_;
73 std::optional<StopCallbackType> stop_callback_;
76template <CQEHandlerLike CQEHandler,
typename Func,
typename Receiver>
77class MultiShotOpFinishHandle :
public OpFinishHandle<CQEHandler, Receiver> {
79 MultiShotOpFinishHandle(CQEHandler cqe_handler, Receiver receiver,
81 : OpFinishHandle<CQEHandler, Receiver>(std::move(cqe_handler),
83 func_(std::move(func)) {
84 this->handle_func_ = handle_static_;
88 static bool handle_static_(
void *data, io_uring_cqe *cqe)
noexcept {
89 auto *self =
static_cast<MultiShotOpFinishHandle *
>(data);
90 return self->handle_impl_(cqe);
93 bool handle_impl_(io_uring_cqe *cqe)
noexcept
95 if (cqe->flags & IORING_CQE_F_MORE) {
96 func_(this->cqe_handler_(cqe));
108template <CQEHandlerLike CQEHandler,
typename Func,
typename Receiver>
109class ZeroCopyOpFinishHandle :
public OpFinishHandle<CQEHandler, Receiver> {
111 ZeroCopyOpFinishHandle(CQEHandler cqe_handler, Receiver receiver, Func func)
112 : OpFinishHandle<CQEHandler, Receiver>(std::move(cqe_handler),
113 std::move(receiver)),
114 free_func_(std::move(func)) {
115 this->handle_func_ = handle_static_;
119 static bool handle_static_(
void *data, io_uring_cqe *cqe)
noexcept {
120 auto *self =
static_cast<ZeroCopyOpFinishHandle *
>(data);
121 return self->handle_impl_(cqe);
124 bool handle_impl_(io_uring_cqe *cqe)
noexcept
126 if (cqe->flags & IORING_CQE_F_MORE) {
130 if (cqe->flags & IORING_CQE_F_NOTIF) {
144 void notify_(int32_t res)
noexcept {
153template <
typename Handle>
class HandleBox {
155 template <
typename... Args>
156 HandleBox(Args &&...args) : handle_(std::forward<Args>(args)...) {}
158 CONDY_DELETE_COPY_MOVE(HandleBox);
161 Handle &get() noexcept {
return handle_; }
167template <CQEHandlerLike CQEHandler,
typename Func,
typename Receiver>
168class HandleBox<ZeroCopyOpFinishHandle<CQEHandler, Func, Receiver>> {
170 using Handle = ZeroCopyOpFinishHandle<CQEHandler, Func, Receiver>;
172 template <
typename... Args>
173 HandleBox(Args &&...args)
174 : handle_ptr_(new Handle(std::forward<Args>(args)...)) {}
176 CONDY_DELETE_COPY_MOVE(HandleBox);
179 Handle &get() noexcept {
return *handle_ptr_; }
The main namespace for the Condy library.
Runtime type for running the io_uring event loop.
Internal utility classes and functions used by Condy.