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();
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 .build()
71 .into()
72 }
73}
74
75unsafe impl<T: IoBufMut, S: AsFd> OpCode for ReadAt<T, S> {
76 type Control = ();
77
78 fn create_entry(&mut self, _: &mut Self::Control) -> OpEntry {
79 let fd = Fd(self.fd.as_fd().as_raw_fd());
80 let slice = self.buffer.sys_slice_mut();
81 opcode::Read::new(
82 fd,
83 slice.ptr() as _,
84 slice.len().try_into().unwrap_or(u32::MAX),
85 )
86 .offset(self.offset)
87 .build()
88 .into()
89 }
90}
91
92unsafe impl<T: IoVectoredBufMut, S: AsFd> OpCode for ReadVectored<T, S> {
93 type Control = VectoredControl;
94
95 unsafe fn init(&mut self, ctrl: &mut Self::Control) {
96 ctrl.slices = self.buffer.sys_slices();
97 }
98
99 fn create_entry(&mut self, control: &mut Self::Control) -> OpEntry {
100 opcode::Readv::new(
101 Fd(self.fd.as_fd().as_raw_fd()),
102 control.slices.as_ptr() as _,
103 control.slices.len().try_into().unwrap_or(u32::MAX),
104 )
105 .build()
106 .into()
107 }
108}
109
110unsafe impl<T: IoBuf, S: AsFd> OpCode for Write<T, S> {
111 type Control = ();
112
113 fn create_entry(&mut self, _: &mut Self::Control) -> OpEntry {
114 let slice = self.buffer.as_init();
115 opcode::Write::new(
116 Fd(self.fd.as_fd().as_raw_fd()),
117 slice.as_ptr(),
118 slice.len().try_into().unwrap_or(u32::MAX),
119 )
120 .build()
121 .into()
122 }
123}
124
125unsafe impl<T: IoVectoredBuf, S: AsFd> OpCode for WriteVectored<T, S> {
126 type Control = VectoredControl;
127
128 unsafe fn init(&mut self, ctrl: &mut Self::Control) {
129 ctrl.slices = self.buffer.sys_slices();
130 }
131
132 fn create_entry(&mut self, control: &mut Self::Control) -> OpEntry {
133 opcode::Writev::new(
134 Fd(self.fd.as_fd().as_raw_fd()),
135 control.slices.as_ptr() as _,
136 control.slices.len().try_into().unwrap_or(u32::MAX),
137 )
138 .build()
139 .into()
140 }
141}
142
143unsafe impl<S: AsFd> OpCode for PollOnce<S> {
144 type Control = ();
145
146 fn create_entry(&mut self, _: &mut Self::Control) -> OpEntry {
147 let flags = match self.interest {
148 Interest::Readable => libc::POLLIN,
149 Interest::Writable => libc::POLLOUT,
150 };
151 opcode::PollAdd::new(Fd(self.fd.as_fd().as_raw_fd()), flags as _)
152 .build()
153 .into()
154 }
155}
156
157unsafe impl OpCode for Pipe {
158 type Control = ();
159
160 fn create_entry(&mut self, _: &mut Self::Control) -> OpEntry {
161 opcode::Pipe::new(self.fds.as_mut_ptr().cast())
162 .flags(libc::O_CLOEXEC as _)
163 .build()
164 .into()
165 }
166
167 fn call_blocking(&mut self, _: &mut Self::Control) -> io::Result<usize> {
168 self.call()
169 }
170}