Condy v1.6.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/ring.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().ring();
25 assert(ring != nullptr);
26 auto ring_flags = ring->ring()->flags;
27 if (ring_flags & IORING_SETUP_CQE32) {
28 return true;
29 }
30#if !IO_URING_CHECK_VERSION(2, 13) // >= 2.13
31 if (ring_flags & IORING_SETUP_CQE_MIXED) {
32 return cqe->flags & IORING_CQE_F_32;
33 }
34#endif
35 return false;
36}
37
38} // namespace detail
39
47 int32_t operator()(io_uring_cqe *cqe) noexcept { return cqe->res; }
48};
49
58template <BufferRingLike Br> class SelectBufferCQEHandler {
59public:
60 SelectBufferCQEHandler(Br *buffers) : buffers_(buffers) {}
61
62 auto operator()(io_uring_cqe *cqe) noexcept {
63 return std::make_pair(cqe->res, buffers_->handle_finish(cqe));
64 }
65
66private:
67 Br *buffers_;
68};
69
77 std::pair<int32_t, uint64_t> operator()(io_uring_cqe *cqe) noexcept {
78 assert(detail::check_cqe32(cqe) &&
79 "Expected big CQE for NVMe passthrough");
80 return {cqe->res, cqe->big_cqe[0]};
81 }
82};
83
84#if !IO_URING_CHECK_VERSION(2, 12) // >= 2.12
94 int tstype; // cqe->flags >> IORING_TIMESTAMP_TYPE_SHIFT
95
99 bool hwts; // cqe->flags & IORING_CQE_F_TSTAMP_HW
100
104 io_timespec ts; // *(io_timespec *)(cqe + 1)
105};
106
114 std::pair<int32_t, TxTimestampResult>
115 operator()(io_uring_cqe *cqe) noexcept {
116 assert(detail::check_cqe32(cqe) &&
117 "Expected big CQE for TX timestamp operations");
118 TxTimestampResult result;
119 result.tstype =
120 static_cast<int>(cqe->flags >> IORING_TIMESTAMP_TYPE_SHIFT);
121 result.hwts = cqe->flags & IORING_CQE_F_TSTAMP_HW;
122 result.ts = *reinterpret_cast<io_timespec *>(cqe + 1);
123 return {cqe->res, result};
124 }
125};
126#endif
127
128} // namespace condy
The main namespace for the Condy library.
Definition condy.hpp:30
Wrapper classes for liburing interfaces.
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.