Condy v1.7.0
C++ Asynchronous System Call Layer for Linux
Loading...
Searching...
No Matches
cqe_handler.hpp
Go to the documentation of this file.
1
7
8#pragma once
9
10#include "condy/concepts.hpp"
11#include "condy/context.hpp"
12#include "condy/runtime.hpp"
13#include <cassert>
14#include <cerrno>
15#include <cstdint>
16#include <utility>
17
18namespace condy {
19
20namespace detail {
21
22// Just for debugging, check if the CQE is big as expected
23inline bool check_cqe32([[maybe_unused]] io_uring_cqe *cqe) {
24 auto &ring = detail::Context::current().runtime()->ring();
25 auto ring_flags = ring.ring()->flags;
26 if (ring_flags & IORING_SETUP_CQE32) {
27 return true;
28 }
29#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13
30 if (ring_flags & IORING_SETUP_CQE_MIXED) {
31 return cqe->flags & IORING_CQE_F_32;
32 }
33#endif
34 return false;
35}
36
37} // namespace detail
38
46 int32_t operator()(io_uring_cqe *cqe) noexcept { return cqe->res; }
47};
48
57template <BufferRingLike Br> class SelectBufferCQEHandler {
58public:
59 SelectBufferCQEHandler(Br *buffers) : buffers_(buffers) {}
60
61 auto operator()(io_uring_cqe *cqe) noexcept {
62 return std::make_pair(cqe->res, buffers_->handle_finish(cqe));
63 }
64
65private:
66 Br *buffers_;
67};
68
76 std::pair<int32_t, uint64_t> operator()(io_uring_cqe *cqe) noexcept {
77 assert(detail::check_cqe32(cqe) &&
78 "Expected big CQE for NVMe passthrough");
79 return {cqe->res, cqe->big_cqe[0]};
80 }
81};
82
83#if !IO_URING_CHECK_VERSION(2, 12) // >= 2.12
93 int tstype; // cqe->flags >> IORING_TIMESTAMP_TYPE_SHIFT
94
98 bool hwts; // cqe->flags & IORING_CQE_F_TSTAMP_HW
99
103 io_timespec ts; // *(io_timespec *)(cqe + 1)
104};
105
113 std::pair<int32_t, TxTimestampResult>
114 operator()(io_uring_cqe *cqe) noexcept {
115 assert(detail::check_cqe32(cqe) &&
116 "Expected big CQE for TX timestamp operations");
117 TxTimestampResult result;
118 result.tstype =
119 static_cast<int>(cqe->flags >> IORING_TIMESTAMP_TYPE_SHIFT);
120 result.hwts = cqe->flags & IORING_CQE_F_TSTAMP_HW;
121 result.ts = *reinterpret_cast<io_timespec *>(cqe + 1);
122 return {cqe->res, result};
123 }
124};
125#endif
126
127} // namespace condy
The main namespace for the Condy library.
Definition condy.hpp:31
Runtime type for running the io_uring event loop.
A CQE handler for NVMe passthrough commands that extracts the status and result from the CQE.
A simple CQE handler that extracts the result from the CQE without any additional processing.
A CQE handler for TX timestamp operations that extracts timestamp information from the CQE.
Result for TX timestamp operations, containing timestamp information from the socket error queue.
int tstype
The timestamp type, could be SCM_TSTAMP_SND, SCM_TSTAMP_SCHED, SCM_TSTAMP_ACK, etc.
io_timespec ts
The timestamp value.
bool hwts
Whether this timestamp is a hardware timestamp.