From 017829458b8bba07fd3c2674e42d2a9de8a271fe Mon Sep 17 00:00:00 2001 From: wokron Date: Tue, 7 Jul 2026 15:47:39 +0800 Subject: [PATCH 1/3] move SwitchAwaiter to detail --- include/condy/detail/task.hpp | 13 +++++++++++++ include/condy/task.hpp | 17 ----------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/include/condy/detail/task.hpp b/include/condy/detail/task.hpp index a795b555..23fc3a47 100644 --- a/include/condy/detail/task.hpp +++ b/include/condy/detail/task.hpp @@ -181,5 +181,18 @@ inline auto TaskBase::operator co_await() noexcept { Context::current().runtime()); } +struct [[nodiscard]] SwitchAwaiter { + bool await_ready() const noexcept { return false; } + + template + void await_suspend(std::coroutine_handle handle) noexcept { + runtime_->schedule_internal(&handle.promise()); + } + + void await_resume() const noexcept {} + + Runtime *runtime_; +}; + } // namespace detail } // namespace condy \ No newline at end of file diff --git a/include/condy/task.hpp b/include/condy/task.hpp index 79d82a9d..273e697b 100644 --- a/include/condy/task.hpp +++ b/include/condy/task.hpp @@ -125,23 +125,6 @@ inline Task co_spawn(Coro coro) { return co_spawn(*runtime, std::move(coro)); } -namespace detail { - -struct [[nodiscard]] SwitchAwaiter { - bool await_ready() const noexcept { return false; } - - template - void await_suspend(std::coroutine_handle handle) noexcept { - runtime_->schedule_internal(&handle.promise()); - } - - void await_resume() const noexcept {} - - Runtime *runtime_; -}; - -} // namespace detail - /** * @brief Switch current coroutine task to the given runtime. * @param runtime The runtime to switch to. From e3d6c8402bd44a92288cfecd3e5a5648b97d632b Mon Sep 17 00:00:00 2001 From: wokron Date: Tue, 7 Jul 2026 15:50:29 +0800 Subject: [PATCH 2/3] move check_cqe32 to detail --- include/condy/cqe_handler.hpp | 31 ++++++++----------------------- include/condy/detail/ring.hpp | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/include/condy/cqe_handler.hpp b/include/condy/cqe_handler.hpp index 13f64a9e..af1bbec1 100644 --- a/include/condy/cqe_handler.hpp +++ b/include/condy/cqe_handler.hpp @@ -17,25 +17,6 @@ namespace condy { -namespace detail { - -// Just for debugging, check if the CQE is big as expected -inline bool check_cqe32([[maybe_unused]] io_uring_cqe *cqe) { - auto &ring = detail::Context::current().runtime()->ring_internal(); - auto ring_flags = ring.ring()->flags; - if (ring_flags & IORING_SETUP_CQE32) { - return true; - } -#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13 - if (ring_flags & IORING_SETUP_CQE_MIXED) { - return cqe->flags & IORING_CQE_F_32; - } -#endif - return false; -} - -} // namespace detail - /** * @brief A simple CQE handler that extracts the result from the CQE without any * additional processing. @@ -76,8 +57,10 @@ class SelectBufferCQEHandler { */ struct NVMePassthruCQEHandler { std::pair operator()(io_uring_cqe *cqe) noexcept { - assert(detail::check_cqe32(cqe) && - "Expected big CQE for NVMe passthrough"); + assert( + detail::check_cqe32( + detail::Context::current().runtime()->ring_internal(), cqe) && + "Expected big CQE for NVMe passthrough"); return {cqe->res, cqe->big_cqe[0]}; } }; @@ -114,8 +97,10 @@ struct TxTimestampResult { struct TxTimestampCQEHandler { std::pair operator()(io_uring_cqe *cqe) noexcept { - assert(detail::check_cqe32(cqe) && - "Expected big CQE for TX timestamp operations"); + assert( + detail::check_cqe32( + detail::Context::current().runtime()->ring_internal(), cqe) && + "Expected big CQE for TX timestamp operations"); TxTimestampResult result; result.tstype = static_cast(cqe->flags >> IORING_TIMESTAMP_TYPE_SHIFT); diff --git a/include/condy/detail/ring.hpp b/include/condy/detail/ring.hpp index a891b34c..26034030 100644 --- a/include/condy/detail/ring.hpp +++ b/include/condy/detail/ring.hpp @@ -158,5 +158,19 @@ class Ring { size_t maybe_submit_count_ = 0; }; +// Just for debugging, check if the CQE is big as expected +inline bool check_cqe32(Ring &ring, [[maybe_unused]] io_uring_cqe *cqe) { + auto ring_flags = ring.ring()->flags; + if (ring_flags & IORING_SETUP_CQE32) { + return true; + } +#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13 + if (ring_flags & IORING_SETUP_CQE_MIXED) { + return cqe->flags & IORING_CQE_F_32; + } +#endif + return false; +} + } // namespace detail } // namespace condy \ No newline at end of file From 8e1ac10a894e8f2e9bd70edc537b5593e715518d Mon Sep 17 00:00:00 2001 From: wokron Date: Tue, 7 Jul 2026 15:53:02 +0800 Subject: [PATCH 3/3] zcrx check cqe32 --- include/condy/cqe_handler.hpp | 8 ++++---- include/condy/detail/ring.hpp | 27 +++++++++++++-------------- include/condy/zcrx.hpp | 3 +++ 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/include/condy/cqe_handler.hpp b/include/condy/cqe_handler.hpp index af1bbec1..053c6fa1 100644 --- a/include/condy/cqe_handler.hpp +++ b/include/condy/cqe_handler.hpp @@ -58,8 +58,8 @@ class SelectBufferCQEHandler { struct NVMePassthruCQEHandler { std::pair operator()(io_uring_cqe *cqe) noexcept { assert( - detail::check_cqe32( - detail::Context::current().runtime()->ring_internal(), cqe) && + detail::Context::current().runtime()->ring_internal().check_cqe32( + cqe) && "Expected big CQE for NVMe passthrough"); return {cqe->res, cqe->big_cqe[0]}; } @@ -98,8 +98,8 @@ struct TxTimestampCQEHandler { std::pair operator()(io_uring_cqe *cqe) noexcept { assert( - detail::check_cqe32( - detail::Context::current().runtime()->ring_internal(), cqe) && + detail::Context::current().runtime()->ring_internal().check_cqe32( + cqe) && "Expected big CQE for TX timestamp operations"); TxTimestampResult result; result.tstype = diff --git a/include/condy/detail/ring.hpp b/include/condy/detail/ring.hpp index 26034030..2ab45876 100644 --- a/include/condy/detail/ring.hpp +++ b/include/condy/detail/ring.hpp @@ -133,6 +133,19 @@ class Ring { } #endif + bool check_cqe32([[maybe_unused]] io_uring_cqe *cqe) const noexcept { + auto ring_flags = ring_.flags; + if (ring_flags & IORING_SETUP_CQE32) { + return true; + } +#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13 + if (ring_flags & IORING_SETUP_CQE_MIXED) { + return cqe->flags & IORING_CQE_F_32; + } +#endif + return false; + } + private: template io_uring_sqe *get_sqe_() noexcept { @@ -158,19 +171,5 @@ class Ring { size_t maybe_submit_count_ = 0; }; -// Just for debugging, check if the CQE is big as expected -inline bool check_cqe32(Ring &ring, [[maybe_unused]] io_uring_cqe *cqe) { - auto ring_flags = ring.ring()->flags; - if (ring_flags & IORING_SETUP_CQE32) { - return true; - } -#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13 - if (ring_flags & IORING_SETUP_CQE_MIXED) { - return cqe->flags & IORING_CQE_F_32; - } -#endif - return false; -} - } // namespace detail } // namespace condy \ No newline at end of file diff --git a/include/condy/zcrx.hpp b/include/condy/zcrx.hpp index ba018463..9768fde7 100644 --- a/include/condy/zcrx.hpp +++ b/include/condy/zcrx.hpp @@ -2,6 +2,7 @@ #include "condy/detail/buffers.hpp" #include "condy/detail/context.hpp" +#include "condy/detail/ring.hpp" #include "condy/detail/utils.hpp" #include "condy/runtime.hpp" #include @@ -190,6 +191,8 @@ class ZeroCopyRxBufferPool { uint32_t zcrx_id() const noexcept { return zcrx_id_; } ZeroCopyRxBuffer handle_finish(io_uring_cqe *cqe) noexcept { + assert(ring_->check_cqe32(cqe) && "Expected big CQE for ZeroCopyRx"); + if (cqe->res < 0) { return ZeroCopyRxBuffer(); }