diff --git a/include/condy/cqe_handler.hpp b/include/condy/cqe_handler.hpp index 13f64a9e..053c6fa1 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::Context::current().runtime()->ring_internal().check_cqe32( + 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::Context::current().runtime()->ring_internal().check_cqe32( + 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..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 { 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. 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(); }