compio_driver/sys/op/general/
iour.rs1use io_uring::{opcode, types::Fd};
2
3use crate::{IourOpCode as OpCode, OpEntry, sys::op::*};
4
5unsafe impl<T: IoVectoredBufMut, S: AsFd> OpCode for ReadVectoredAt<T, S> {
6 type Control = VectoredControl;
7
8 unsafe fn init(&mut self, ctrl: &mut Self::Control) {
9 ctrl.slices = self.buffer.sys_slices_mut();
10 }
11
12 fn create_entry(&mut self, control: &mut Self::Control) -> OpEntry {
13 opcode::Readv::new(
14 Fd(self.fd.as_fd().as_raw_fd()),
15 control.slices.as_ptr() as _,
16 control.slices.len().try_into().unwrap_or(u32::MAX),
17 )
18 .offset(self.offset)
19 .build()
20 .into()
21 }
22}
23
24unsafe impl<T: IoBuf, S: AsFd> OpCode for WriteAt<T, S> {
25 type Control = ();
26
27 fn create_entry(&mut self, _: &mut Self::Control) -> OpEntry {
28 let slice = self.buffer.as_init();
29 opcode::Write::new(
30 Fd(self.fd.as_fd().as_raw_fd()),
31 slice.as_ptr(),
32 slice.len().try_into().unwrap_or(u32::MAX),
33 )
34 .offset(self.offset)
35 .build()
36 .into()
37 }
38}
39
40unsafe impl<T: IoVectoredBuf, S: AsFd> OpCode for WriteVectoredAt<T, S> {
41 type Control = VectoredControl;
42
43 unsafe fn init(&mut self, ctrl: &mut Self::Control) {
44 ctrl.slices = self.buffer.sys_slices();
45 }
46
47 fn create_entry(&mut self, control: &mut Self::Control) -> OpEntry {
48 opcode::Writev::new(
49 Fd(self.fd.as_fd().as_raw_fd()),
50 control.slices.as_ptr() as _,
51 control.slices.len().try_into().unwrap_or(u32::MAX),
52 )
53 .offset(self.offset)
54 .build()
55 .into()
56 }
57}
58
59unsafe impl<T: IoBufMut, S: AsFd> OpCode for Read<T, S> {
60 type Control = ();
61
62 fn create_entry(&mut self, _: &mut Self::Control) -> OpEntry {
63 let fd = self.fd.as_fd().as_raw_fd();
64 let slice = self.buffer.sys_slice_mut();
65 opcode::Read::new(
66 Fd(fd),
67 slice.ptr() as _,
68 slice.len().try_into().unwrap_or(u32::MAX),
69 )
70 .offset(u64::MAX)
71 .build()
72 .into()
73 }
74}
75
76unsafe impl<T: IoBufMut, S: AsFd> OpCode for ReadAt<T, S> {
77 type Control = ();
78
79 fn create_entry(&mut self, _: &mut Self::Control) -> OpEntry {
80 let fd = Fd(self.fd.as_fd().as_raw_fd());
81 let slice = self.buffer.sys_slice_mut();
82 opcode::Read::new(
83 fd,
84 slice.ptr() as _,
85 slice.len().try_into().unwrap_or(u32::MAX),
86 )
87 .offset(self.offset)
88 .build()
89 .into()
90 }
91}
92
93unsafe impl<T: IoVectoredBufMut, S: AsFd> OpCode for ReadVectored<T, S> {
94 type Control = VectoredControl;
95
96 unsafe fn init(&mut self, ctrl: &mut Self::Control) {
97 ctrl.slices = self.buffer.sys_slices_mut();
98 }
99
100 fn create_entry(&mut self, control: &mut Self::Control) -> OpEntry {
101 opcode::Readv::new(
102 Fd(self.fd.as_fd().as_raw_fd()),
103 control.slices.as_ptr() as _,
104 control.slices.len().try_into().unwrap_or(u32::MAX),
105 )
106 .offset(u64::MAX)
107 .build()
108 .into()
109 }
110}
111
112unsafe impl<T: IoBuf, S: AsFd> OpCode for Write<T, S> {
113 type Control = ();
114
115 fn create_entry(&mut self, _: &mut Self::Control) -> OpEntry {
116 let slice = self.buffer.as_init();
117 opcode::Write::new(
118 Fd(self.fd.as_fd().as_raw_fd()),
119 slice.as_ptr(),
120 slice.len().try_into().unwrap_or(u32::MAX),
121 )
122 .offset(u64::MAX)
123 .build()
124 .into()
125 }
126}
127
128unsafe impl<T: IoVectoredBuf, S: AsFd> OpCode for WriteVectored<T, S> {
129 type Control = VectoredControl;
130
131 unsafe fn init(&mut self, ctrl: &mut Self::Control) {
132 ctrl.slices = self.buffer.sys_slices();
133 }
134
135 fn create_entry(&mut self, control: &mut Self::Control) -> OpEntry {
136 opcode::Writev::new(
137 Fd(self.fd.as_fd().as_raw_fd()),
138 control.slices.as_ptr() as _,
139 control.slices.len().try_into().unwrap_or(u32::MAX),
140 )
141 .offset(u64::MAX)
142 .build()
143 .into()
144 }
145}
146
147unsafe impl<S: AsFd> OpCode for PollOnce<S> {
148 type Control = ();
149
150 fn create_entry(&mut self, _: &mut Self::Control) -> OpEntry {
151 let flags = match self.interest {
152 Interest::Readable => libc::POLLIN,
153 Interest::Writable => libc::POLLOUT,
154 };
155 opcode::PollAdd::new(Fd(self.fd.as_fd().as_raw_fd()), flags as _)
156 .build()
157 .into()
158 }
159}
160
161unsafe impl OpCode for Pipe {
162 type Control = ();
163
164 fn create_entry(&mut self, _: &mut Self::Control) -> OpEntry {
165 opcode::Pipe::new(self.fds.as_mut_ptr().cast())
166 .flags(libc::O_CLOEXEC as _)
167 .build()
168 .into()
169 }
170
171 fn call_blocking(&mut self, _: &mut Self::Control) -> io::Result<usize> {
172 self.call()
173 }
174}