1 #ifndef IO_URING_ENGINE_H
2 #define IO_URING_ENGINE_H 1
8 #include <sys/socket.h>
18 IOUringEngine(size_t slop_bytes);
19 void submit_read(int fd, size_t len, off_t offset, std::function<void(std::string_view)> cb);
21 // NOTE: We just do the stat() to get the data into the dentry cache for fast access,
22 // or to check whether the file exists. Thus, the callback has only an OK/not OK boolean.
23 void submit_stat(const char *path, std::function<void(bool ok)> cb);
24 bool get_supports_stat() { return supports_stat; }
27 size_t get_waiting_reads() const { return pending_reads + queued_reads.size(); }
31 void submit_read_internal(io_uring_sqe *sqe, int fd, size_t len, off_t offset, std::function<void(std::string_view)> cb);
32 void submit_stat_internal(io_uring_sqe *sqe, char *path, std::function<void(bool)> cb);
36 size_t pending_reads = 0; // Number of requests we have going in the ring.
37 bool using_uring, supports_stat = false;
38 const size_t slop_bytes;
44 std::function<void(std::string_view)> cb;
46 std::queue<QueuedRead> queued_reads;
49 char *pathname; // Owned by us.
50 std::function<void(bool)> cb;
52 std::queue<QueuedStat> queued_stats;
60 std::function<void(std::string_view)> read_cb;
61 std::function<void(bool)> stat_cb;
80 // 256 simultaneous requests should be ample, for slow and fast media alike.
81 static constexpr size_t queue_depth = 256;
84 #endif // !defined(IO_URING_ENGINE_H)