Skip to main content

compio_driver\sys\op\managed/
iocp.rs

1use windows_sys::Win32::System::IO::OVERLAPPED;
2
3use crate::{OpCode, sys::op::*};
4
5unsafe impl<S: AsFd> OpCode for ReadManagedAt<S> {
6    type Control = ();
7
8    unsafe fn operate(
9        &mut self,
10        control: &mut Self::Control,
11        optr: *mut OVERLAPPED,
12    ) -> Poll<io::Result<usize>> {
13        unsafe { self.op.operate(control, optr) }
14    }
15
16    fn cancel(&mut self, control: &mut Self::Control, optr: *mut OVERLAPPED) -> io::Result<()> {
17        self.op.cancel(control, optr)
18    }
19}
20
21unsafe impl<S: AsFd> OpCode for ReadManaged<S> {
22    type Control = ();
23
24    unsafe fn operate(
25        &mut self,
26        control: &mut (),
27        optr: *mut OVERLAPPED,
28    ) -> Poll<io::Result<usize>> {
29        unsafe { self.op.operate(control, optr) }
30    }
31
32    fn cancel(&mut self, control: &mut (), optr: *mut OVERLAPPED) -> io::Result<()> {
33        self.op.cancel(control, optr)
34    }
35}
36
37unsafe impl<S: AsFd> OpCode for RecvManaged<S> {
38    type Control = RecvControl;
39
40    unsafe fn init(&mut self, ctrl: &mut Self::Control) {
41        unsafe { self.op.init(ctrl) }
42    }
43
44    unsafe fn operate(
45        &mut self,
46        control: &mut Self::Control,
47        optr: *mut OVERLAPPED,
48    ) -> Poll<io::Result<usize>> {
49        unsafe { self.op.operate(control, optr) }
50    }
51
52    fn cancel(&mut self, control: &mut Self::Control, optr: *mut OVERLAPPED) -> io::Result<()> {
53        self.op.cancel(control, optr)
54    }
55}
56
57unsafe impl<S: AsFd> OpCode for RecvFromManaged<S> {
58    type Control = RecvFromControl;
59
60    unsafe fn init(&mut self, ctrl: &mut Self::Control) {
61        unsafe { self.op.init(ctrl) }
62    }
63
64    unsafe fn operate(
65        &mut self,
66        control: &mut Self::Control,
67        optr: *mut OVERLAPPED,
68    ) -> Poll<io::Result<usize>> {
69        unsafe { self.op.operate(control, optr) }
70    }
71
72    fn cancel(&mut self, control: &mut Self::Control, optr: *mut OVERLAPPED) -> io::Result<()> {
73        self.op.cancel(control, optr)
74    }
75}
76
77unsafe impl<S: AsFd> OpCode for RecvFromMulti<S> {
78    type Control = RecvFromControl;
79
80    unsafe fn init(&mut self, ctrl: &mut Self::Control) {
81        unsafe { self.op.init(ctrl) }
82    }
83
84    unsafe fn operate(
85        &mut self,
86        control: &mut Self::Control,
87        optr: *mut OVERLAPPED,
88    ) -> Poll<io::Result<usize>> {
89        unsafe { self.op.operate(control, optr) }
90    }
91
92    fn cancel(&mut self, control: &mut Self::Control, optr: *mut OVERLAPPED) -> io::Result<()> {
93        self.op.cancel(control, optr)
94    }
95
96    unsafe fn set_result(
97        &mut self,
98        _: &mut Self::Control,
99        result: &io::Result<usize>,
100        _: &crate::Extra,
101    ) {
102        if let Ok(result) = result {
103            self.len = *result;
104        }
105    }
106}
107
108unsafe impl<C: IoBufMut, S: AsFd> OpCode for RecvMsgManaged<C, S> {
109    type Control = RecvMsgControl;
110
111    unsafe fn init(&mut self, ctrl: &mut Self::Control) {
112        unsafe { self.op.init(ctrl) }
113    }
114
115    unsafe fn operate(
116        &mut self,
117        control: &mut Self::Control,
118        optr: *mut OVERLAPPED,
119    ) -> Poll<io::Result<usize>> {
120        unsafe { self.op.operate(control, optr) }
121    }
122
123    fn cancel(&mut self, control: &mut Self::Control, optr: *mut OVERLAPPED) -> io::Result<()> {
124        self.op.cancel(control, optr)
125    }
126
127    unsafe fn set_result(
128        &mut self,
129        control: &mut Self::Control,
130        res: &io::Result<usize>,
131        extra: &crate::Extra,
132    ) {
133        unsafe { self.op.set_result(control, res, extra) }
134    }
135}
136
137unsafe impl<S: AsFd> OpCode for RecvMsgMulti<S> {
138    type Control = RecvMsgControl;
139
140    unsafe fn init(&mut self, ctrl: &mut Self::Control) {
141        unsafe { self.op.init(ctrl) }
142    }
143
144    unsafe fn operate(
145        &mut self,
146        control: &mut Self::Control,
147        optr: *mut OVERLAPPED,
148    ) -> Poll<io::Result<usize>> {
149        unsafe { self.op.operate(control, optr) }
150    }
151
152    fn cancel(&mut self, control: &mut Self::Control, optr: *mut OVERLAPPED) -> io::Result<()> {
153        self.op.cancel(control, optr)
154    }
155
156    unsafe fn set_result(
157        &mut self,
158        control: &mut Self::Control,
159        res: &io::Result<usize>,
160        extra: &crate::Extra,
161    ) {
162        unsafe { self.op.set_result(control, res, extra) };
163        if let Ok(res) = res {
164            self.len = *res;
165        }
166    }
167}