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