]> git.proxmox.com Git - proxmox-backup.git/blob - qemu-io/src/util.rs
src/backup/dynamic_index.rs: add chunk_info method
[proxmox-backup.git] / qemu-io / src / util.rs
1 //! Some types used by both our internal testing AioContext implementation as well as our
2 //! WithAioContext wrapper.
3
4 /// An Aio Callback. Qemu's AioContext actually uses a void function taking an opaque pointer.
5 /// For simplicity we stick to closures for now.
6 pub type AioCb = std::sync::Arc<dyn Fn() + Send + Sync>;
7
8 /// This keeps track of our poll state (whether we wait to be notified for read or write
9 /// readiness.)
10 #[derive(Default)]
11 pub struct AioHandlerState {
12 pub read: Option<AioCb>,
13 pub write: Option<AioCb>,
14 }
15
16 impl AioHandlerState {
17 /// Get an mio::Ready with readable set if `read` is `Some`, and writable
18 /// set if `write` is `Some`.
19 pub fn mio_ready(&self) -> mio::Ready {
20 use mio::Ready;
21
22 let mut ready = Ready::empty();
23 if self.read.is_some() {
24 ready |= Ready::readable();
25 }
26
27 if self.write.is_some() {
28 ready |= Ready::writable();
29 }
30
31 ready
32 }
33
34 /// Shortcut
35 pub fn clear(&mut self) {
36 self.read = None;
37 self.write = None;
38 }
39 }