1 #ifndef IO_URING_ENGINE_H
2 #define IO_URING_ENGINE_H 1
11 #include <sys/socket.h>
15 IOUringEngine(size_t slop_bytes);
16 void submit_read(int fd, size_t len, off_t offset, std::function<void(std::string_view)> cb);
18 size_t get_waiting_reads() const { return pending_reads + queued_reads.size(); }
22 void submit_read_internal(io_uring_sqe *sqe, int fd, size_t len, off_t offset, std::function<void(std::string_view)> cb);
26 size_t pending_reads = 0; // Number of requests we have going in the ring.
28 const size_t slop_bytes;
34 std::function<void(std::string_view)> cb;
36 std::queue<QueuedRead> queued_reads;
41 std::function<void(std::string_view)> cb;
49 // 256 simultaneous requests should be ample, for slow and fast media alike.
50 static constexpr size_t queue_depth = 256;
53 // A wrapper around pread() that returns an incomplete read.
54 // Always synchronous (no io_uring).
55 void complete_pread(int fd, void *ptr, size_t len, off_t offset);
57 #endif // !defined(IO_URING_ENGINE_H)