compio_driver/sys/op/asyncify/
iour.rs1use super::*;
2use crate::{IourOpCode as OpCode, OpEntry};
3
4unsafe impl<D, F> OpCode for Asyncify<F, D>
5where
6 D: std::marker::Send + 'static,
7 F: (FnOnce() -> BufResult<usize, D>) + std::marker::Send + 'static,
8{
9 type Control = ();
10
11 fn create_entry(&mut self, _control: &mut Self::Control) -> OpEntry {
12 OpEntry::Blocking
13 }
14
15 fn call_blocking(&mut self, _control: &mut Self::Control) -> std::io::Result<usize> {
16 let f = self
17 .f
18 .take()
19 .expect("the operate method could only be called once");
20 let BufResult(res, data) = f();
21 self.data = Some(data);
22 res
23 }
24}
25
26unsafe impl<S, D, F> OpCode for AsyncifyFd<S, F, D>
27where
28 S: std::marker::Sync,
29 D: std::marker::Send + 'static,
30 F: (FnOnce(&S) -> BufResult<usize, D>) + std::marker::Send + 'static,
31{
32 type Control = ();
33
34 fn create_entry(&mut self, _control: &mut Self::Control) -> OpEntry {
35 OpEntry::Blocking
36 }
37
38 fn call_blocking(&mut self, _control: &mut Self::Control) -> std::io::Result<usize> {
39 let f = self
40 .f
41 .take()
42 .expect("the operate method could only be called once");
43 let BufResult(res, data) = f(&self.fd);
44 self.data = Some(data);
45 res
46 }
47}
48
49unsafe impl<S1, S2, D, F> OpCode for AsyncifyFd2<S1, S2, F, D>
50where
51 S1: std::marker::Sync,
52 S2: std::marker::Sync,
53 D: std::marker::Send + 'static,
54 F: (FnOnce(&S1, &S2) -> BufResult<usize, D>) + std::marker::Send + 'static,
55{
56 type Control = ();
57
58 fn create_entry(&mut self, _control: &mut Self::Control) -> OpEntry {
59 OpEntry::Blocking
60 }
61
62 fn call_blocking(&mut self, _control: &mut Self::Control) -> std::io::Result<usize> {
63 let f = self
64 .f
65 .take()
66 .expect("the operate method could only be called once");
67 let BufResult(res, data) = f(&self.fd1, &self.fd2);
68 self.data = Some(data);
69 res
70 }
71}