Condy v1.5.0
C++ Asynchronous System Call Layer for Linux
Loading...
Searching...
No Matches
cqe_handler.hpp
Go to the documentation of this file.
1
9
10#pragma once
11
12#include "condy/concepts.hpp"
13#include "condy/context.hpp"
14#include "condy/ring.hpp"
15#include <cassert>
16#include <cerrno>
17#include <cstdint>
18#include <utility>
19
20namespace condy {
21
22namespace detail {
23
24// Just for debugging, check if the CQE is big as expected
25inline bool check_cqe32([[maybe_unused]] io_uring_cqe *cqe) {
26 auto *ring = detail::Context::current().ring();
27 assert(ring != nullptr);
28 auto ring_flags = ring->ring()->flags;
29 if (ring_flags & IORING_SETUP_CQE32) {
30 return true;
31 }
32#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13
33 if (ring_flags & IORING_SETUP_CQE_MIXED) {
34 return cqe->flags & IORING_CQE_F_32;
35 }
36#endif
37 return false;
38}
39
40} // namespace detail
41
49public:
50 using ReturnType = int32_t;
51
52 void handle_cqe(io_uring_cqe *cqe) { res_ = cqe->res; }
53
54 ReturnType extract_result() { return res_; }
55
56private:
57 int32_t res_ = -ENOTRECOVERABLE; // Internal error if not set
58};
59
67template <BufferRingLike Br> class SelectBufferCQEHandler {
68public:
69 using ReturnType = std::pair<int, typename Br::ReturnType>;
70
71 SelectBufferCQEHandler(Br *buffers) : buffers_(buffers) {}
72
73 void handle_cqe(io_uring_cqe *cqe) {
74 res_ = cqe->res;
75 flags_ = cqe->flags;
76 }
77
78 ReturnType extract_result() {
79 return std::make_pair(res_, buffers_->handle_finish(res_, flags_));
80 }
81
82private:
83 int32_t res_ = -ENOTRECOVERABLE; // Internal error if not set
84 uint32_t flags_ = 0;
85 Br *buffers_;
86};
87
92struct NVMeResult {
97 int status;
98
103 uint64_t result;
104};
105
112public:
113 using ReturnType = NVMeResult;
114
115 void handle_cqe(io_uring_cqe *cqe) {
116 assert(detail::check_cqe32(cqe) &&
117 "Expected big CQE for NVMe passthrough");
118 result_.status = cqe->res;
119 result_.result = cqe->big_cqe[0];
120 }
121
122 ReturnType extract_result() { return result_; }
123
124private:
125 NVMeResult result_;
126};
127
128#if !IO_URING_CHECK_VERSION(2, 12) // >= 2.12
138 int tskey; // cqe->res
139
144 int tstype; // cqe->flags >> IORING_TIMESTAMP_TYPE_SHIFT
145
149 io_timespec ts; // *(io_timespec *)(cqe + 1)
150
154 bool hwts; // cqe->flags & IORING_CQE_F_TSTAMP_HW
155};
156
163public:
164 using ReturnType = TxTimestampResult;
165
166 void handle_cqe(io_uring_cqe *cqe) {
167 assert(detail::check_cqe32(cqe) &&
168 "Expected big CQE for TX timestamp operations");
169 result_.tskey = cqe->res;
170 result_.tstype =
171 static_cast<int>(cqe->flags >> IORING_TIMESTAMP_TYPE_SHIFT);
172 result_.ts = *reinterpret_cast<io_timespec *>(cqe + 1);
173 result_.hwts = cqe->flags & IORING_CQE_F_TSTAMP_HW;
174 }
175
176 ReturnType extract_result() { return result_; }
177
178private:
179 TxTimestampResult result_;
180};
181#endif
182
183} // namespace condy
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.
The main namespace for the Condy library.
Definition condy.hpp:28
Wrapper classes for liburing interfaces.
Result for NVMe passthrough commands, containing the status and result of the command.
uint64_t result
Result of this NVMe command, is the value of cqe->big_cqe[0] for the corresponding CQE.
int status
Status of this NVMe command, is the value of cqe->res for the corresponding 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.
int tskey
The timestamp key if successful, which is the value of cqe->res for the corresponding CQE.
bool hwts
Whether this timestamp is a hardware timestamp.