Condy v1.9
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"
12#include "condy/runtime.hpp"
13#include <cassert>
14#include <cerrno>
15#include <cstdint>
16#include <utility>
17
18namespace condy {
19
27 int32_t operator()(io_uring_cqe *cqe) noexcept { return cqe->res; }
28};
29
38template <typename Br>
39 requires(requires(Br *br, io_uring_cqe *cqe) { br->handle_finish(cqe); })
40class SelectBufferCQEHandler {
41public:
42 SelectBufferCQEHandler(Br *buffers) : buffers_(buffers) {}
43
44 auto operator()(io_uring_cqe *cqe) noexcept {
45 return std::make_pair(cqe->res, buffers_->handle_finish(cqe));
46 }
47
48private:
49 Br *buffers_;
50};
51
59 std::pair<int32_t, uint64_t> operator()(io_uring_cqe *cqe) noexcept {
60 return {cqe->res, cqe->big_cqe[0]};
61 }
62};
63
71 uint64_t res2;
72
74 uint8_t device_status() noexcept { return res2 & 0xff; }
75
77 uint8_t driver_status() noexcept { return (res2 >> 8) & 0xff; }
78
80 uint8_t host_status() noexcept { return (res2 >> 16) & 0xff; }
81
83 uint8_t sense_len() noexcept { return (res2 >> 24) & 0xff; }
84
86 uint32_t resid_len() noexcept { return res2 >> 32; }
87};
88
96 std::pair<int32_t, SCSIBsgResult> operator()(io_uring_cqe *cqe) noexcept {
97 return {cqe->res, SCSIBsgResult{cqe->big_cqe[0]}};
98 }
99};
100
101#if CONDY_URING_VERSION_GE(2, 12) // >= 2.12
106struct TxTimestampResult {
111 int tstype; // cqe->flags >> IORING_TIMESTAMP_TYPE_SHIFT
112
116 bool hwts; // cqe->flags & IORING_CQE_F_TSTAMP_HW
117
121 io_timespec ts; // *(io_timespec *)(cqe->big_cqe)
122};
123
130struct TxTimestampCQEHandler {
131 std::pair<int32_t, TxTimestampResult>
132 operator()(io_uring_cqe *cqe) noexcept {
133 TxTimestampResult result;
134 result.tstype =
135 static_cast<int>(cqe->flags >> IORING_TIMESTAMP_TYPE_SHIFT);
136 result.hwts = cqe->flags & IORING_CQE_F_TSTAMP_HW;
137 result.ts = reinterpret_cast<io_timespec &>(cqe->big_cqe);
138 return {cqe->res, result};
139 }
140};
141#endif
142
143} // namespace condy
The main namespace for the Condy library.
Definition condy.hpp:38
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 CQE handler for SCSI BSG passthrough commands that extracts the SCSI status and result from the CQE...
Result for SCSI BSG passthrough commands.
uint8_t host_status() noexcept
Extract host status.
uint8_t driver_status() noexcept
Extract driver status.
uint8_t device_status() noexcept
Extract SCSI device status byte.
uint8_t sense_len() noexcept
Extract sense data length.
uint64_t res2
Raw res2 from the CQE.
uint32_t resid_len() noexcept
Extract residual transfer length.
A simple CQE handler that extracts the result from the CQE without any additional processing.