Skip to content

Commit 118bcc2

Browse files
committed
doc fixes, tests, & clippy
1 parent 8ef6b99 commit 118bcc2

File tree

7 files changed

+41
-36
lines changed

7 files changed

+41
-36
lines changed

examples/readme.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
use io_uring::{opcode, types, IoUring};
21
use std::os::unix::io::AsRawFd;
32
use std::{fs, io};
43

4+
use io_uring::types::{Fd, IoringUserData};
5+
use io_uring::{opcode, IoUring};
6+
57
fn main() -> io::Result<()> {
68
let mut ring = IoUring::new(8)?;
79

810
let fd = fs::File::open("README.md")?;
911
let mut buf = vec![0; 1024];
1012

11-
let read_e = opcode::Read::new(types::Fd(fd.as_raw_fd()), buf.as_mut_ptr(), buf.len() as _)
13+
let read_e = opcode::Read::new(Fd(fd.as_raw_fd()), buf.as_mut_ptr(), buf.len() as _)
1214
.build()
13-
.user_data(types::io_uring_user_data { u64_: 0x42 });
15+
.user_data(IoringUserData { u64_: 0x42 });
1416

1517
// Note that the developer needs to ensure
1618
// that the entry pushed into submission queue is valid (e.g. fd, buffer).

examples/tcp_echo.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::net::TcpListener;
33
use std::os::unix::io::{AsRawFd, RawFd};
44
use std::{io, ptr};
55

6-
use io_uring::{opcode, squeue, types, IoUring, SubmissionQueue};
6+
use io_uring::types::{Errno, Fd, IoringUserData};
7+
use io_uring::{opcode, squeue, IoUring, SubmissionQueue};
78
use slab::Slab;
89

910
#[derive(Clone, Debug)]
@@ -32,9 +33,9 @@ pub struct AcceptCount {
3233
impl AcceptCount {
3334
fn new(fd: RawFd, token: usize, count: usize) -> AcceptCount {
3435
AcceptCount {
35-
entry: opcode::Accept::new(types::Fd(fd), ptr::null_mut(), ptr::null_mut())
36+
entry: opcode::Accept::new(Fd(fd), ptr::null_mut(), ptr::null_mut())
3637
.build()
37-
.user_data(types::io_uring_user_data { u64_: token as _ }),
38+
.user_data(IoringUserData { u64_: token as _ }),
3839
count,
3940
}
4041
}
@@ -73,7 +74,7 @@ fn main() -> anyhow::Result<()> {
7374
loop {
7475
match submitter.submit_and_wait(1) {
7576
Ok(_) => (),
76-
Err(err) if err == types::Errno::BUSY => (),
77+
Err(err) if err == Errno::BUSY => (),
7778
Err(err) => return Err(err.into()),
7879
}
7980
cq.sync();
@@ -83,7 +84,7 @@ fn main() -> anyhow::Result<()> {
8384
if sq.is_full() {
8485
match submitter.submit() {
8586
Ok(_) => (),
86-
Err(err) if err == types::Errno::BUSY => break,
87+
Err(err) if err == Errno::BUSY => break,
8788
Err(err) => return Err(err.into()),
8889
}
8990
}
@@ -122,9 +123,9 @@ fn main() -> anyhow::Result<()> {
122123
let fd = ret;
123124
let poll_token = token_alloc.insert(Token::Poll { fd });
124125

125-
let poll_e = opcode::PollAdd::new(types::Fd(fd), libc::POLLIN as _)
126+
let poll_e = opcode::PollAdd::new(Fd(fd), libc::POLLIN as _)
126127
.build()
127-
.user_data(types::io_uring_user_data {
128+
.user_data(IoringUserData {
128129
u64_: poll_token as _,
129130
});
130131

@@ -147,9 +148,9 @@ fn main() -> anyhow::Result<()> {
147148

148149
*token = Token::Read { fd, buf_index };
149150

150-
let read_e = opcode::Recv::new(types::Fd(fd), buf.as_mut_ptr(), buf.len() as _)
151+
let read_e = opcode::Recv::new(Fd(fd), buf.as_mut_ptr(), buf.len() as _)
151152
.build()
152-
.user_data(types::io_uring_user_data {
153+
.user_data(IoringUserData {
153154
u64_: token_index as _,
154155
});
155156

@@ -180,9 +181,9 @@ fn main() -> anyhow::Result<()> {
180181
offset: 0,
181182
};
182183

183-
let write_e = opcode::Send::new(types::Fd(fd), buf.as_ptr(), len as _)
184+
let write_e = opcode::Send::new(Fd(fd), buf.as_ptr(), len as _)
184185
.build()
185-
.user_data(types::io_uring_user_data {
186+
.user_data(IoringUserData {
186187
u64_: token_index as _,
187188
});
188189

@@ -206,9 +207,9 @@ fn main() -> anyhow::Result<()> {
206207

207208
*token = Token::Poll { fd };
208209

209-
opcode::PollAdd::new(types::Fd(fd), libc::POLLIN as _)
210+
opcode::PollAdd::new(Fd(fd), libc::POLLIN as _)
210211
.build()
211-
.user_data(types::io_uring_user_data {
212+
.user_data(IoringUserData {
212213
u64_: token_index as _,
213214
})
214215
} else {
@@ -224,9 +225,9 @@ fn main() -> anyhow::Result<()> {
224225
len,
225226
};
226227

227-
opcode::Write::new(types::Fd(fd), buf.as_ptr(), len as _)
228+
opcode::Write::new(Fd(fd), buf.as_ptr(), len as _)
228229
.build()
229-
.user_data(types::io_uring_user_data {
230+
.user_data(IoringUserData {
230231
u64_: token_index as _,
231232
})
232233
};

src/cqueue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ impl Entry {
221221
///
222222
/// This is currently used for:
223223
/// - Storing the selected buffer ID, if one was selected. See
224-
/// [`BUFFER_SELECT`](crate::squeue::Flags::BUFFER_SELECT) for more info.
224+
/// [`BUFFER_SELECT`](crate::types::IoringSqeFlags::BUFFER_SELECT) for more info.
225225
#[inline]
226226
pub fn flags(&self) -> IoringCqeFlags {
227227
self.0.flags
@@ -270,7 +270,7 @@ impl Entry32 {
270270
///
271271
/// This is currently used for:
272272
/// - Storing the selected buffer ID, if one was selected. See
273-
/// [`BUFFER_SELECT`](crate::squeue::Flags::BUFFER_SELECT) for more info.
273+
/// [`BUFFER_SELECT`](crate::types::IoringSqeFlags::BUFFER_SELECT) for more info.
274274
#[inline]
275275
pub fn flags(&self) -> IoringCqeFlags {
276276
self.0 .0.flags

src/opcode.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ opcode!(
238238
fd: { impl sealed::UseFixed },
239239
;;
240240
/// The `flags` bit mask may contain either 0, for a normal file integrity sync,
241-
/// or [types::FsyncFlags::DATASYNC] to provide data sync only semantics.
241+
/// or [crate::types::IoringFsyncFlags::DATASYNC] to provide data sync only semantics.
242242
/// See the descriptions of `O_SYNC` and `O_DSYNC` in the `open(2)` manual page for more information.
243243
flags: IoringFsyncFlags = IoringFsyncFlags::empty()
244244
}
@@ -428,7 +428,7 @@ opcode!(
428428
let mut sqe = sqe_zeroed();
429429
sqe.opcode = Self::CODE;
430430
sqe.fd = -1;
431-
sqe.addr_or_splice_off_in.user_data = user_data.into();
431+
sqe.addr_or_splice_off_in.user_data = user_data;
432432
Entry(sqe)
433433
}
434434
);
@@ -538,7 +538,7 @@ opcode!(
538538
/// fields are relevant.
539539
/// buf_group: The id of the provided buffer pool to use for each received message.
540540
///
541-
/// See also the description of [`SendMsg`] and [`types::RecvMsgOut`].
541+
/// See also the description of [`SendMsg`] and [`crate::types::RecvMsgOut`].
542542
///
543543
/// The multishot version allows the application to issue a single receive request, which
544544
/// repeatedly posts a CQE when data is available. It requires the MSG_WAITALL flag is not set.
@@ -549,7 +549,7 @@ opcode!(
549549
///
550550
/// Unlike [`RecvMsg`], this multishot recvmsg will prepend a struct which describes the layout
551551
/// of the rest of the buffer in combination with the initial msghdr structure submitted with
552-
/// the request. Use [`types::RecvMsgOut`] to parse the data received and access its
552+
/// the request. Use [`crate::types::RecvMsgOut`] to parse the data received and access its
553553
/// components.
554554
///
555555
/// The recvmsg multishot variant is available since kernel 6.0.
@@ -598,7 +598,7 @@ opcode!(
598598
/// `count` may contain a completion event count.
599599
count: u32 = 0,
600600

601-
/// `flags` may contain [types::TimeoutFlags::ABS] for an absolute timeout value, or 0 for a relative timeout.
601+
/// `flags` may contain [crate::types::IoringTimeoutFlags::ABS] for an absolute timeout value, or 0 for a relative timeout.
602602
flags: IoringTimeoutFlags = IoringTimeoutFlags::empty()
603603
}
604604

@@ -636,7 +636,7 @@ opcode!(
636636
let mut sqe = sqe_zeroed();
637637
sqe.opcode = Self::CODE;
638638
sqe.fd = -1;
639-
sqe.addr_or_splice_off_in.user_data = user_data.into();
639+
sqe.addr_or_splice_off_in.user_data = user_data;
640640
sqe.op_flags.timeout_flags = flags;
641641
Entry(sqe)
642642
}
@@ -719,14 +719,14 @@ opcode!(
719719
sqe.opcode = Self::CODE;
720720
sqe.fd = -1;
721721
sqe.op_flags.cancel_flags = flags;
722-
sqe.addr_or_splice_off_in.user_data = user_data.into();
722+
sqe.addr_or_splice_off_in.user_data = user_data;
723723
Entry(sqe)
724724
}
725725
);
726726

727727
opcode!(
728728
/// This request must be linked with another request through
729-
/// [`Flags::IO_LINK`](crate::squeue::Flags::IO_LINK) which is described below.
729+
/// [`Flags::IO_LINK`](crate::types::IoringSqeFlags::IO_LINK) which is described below.
730730
/// Unlike [`Timeout`], [`LinkTimeout`] acts on the linked request, not the completion queue.
731731
pub struct LinkTimeout {
732732
timespec: { *const Timespec },
@@ -1310,7 +1310,7 @@ opcode!(
13101310
opcode!(
13111311
/// Register `nbufs` buffers that each have the length `len` with ids starting from `big` in the
13121312
/// group `bgid` that can be used for any request. See
1313-
/// [`BUFFER_SELECT`](crate::squeue::Flags::BUFFER_SELECT) for more info.
1313+
/// [`BUFFER_SELECT`](crate::types::IoringSqeFlags::BUFFER_SELECT) for more info.
13141314
pub struct ProvideBuffers {
13151315
addr: { *mut u8 },
13161316
len: { i32 },
@@ -1338,7 +1338,7 @@ opcode!(
13381338

13391339
opcode!(
13401340
/// Remove some number of buffers from a buffer group. See
1341-
/// [`BUFFER_SELECT`](crate::squeue::Flags::BUFFER_SELECT) for more info.
1341+
/// [`BUFFER_SELECT`](crate::types::IoringSqeFlags::BUFFER_SELECT) for more info.
13421342
pub struct RemoveBuffers {
13431343
nbufs: { u16 },
13441344
bgid: { u16 }
@@ -1567,7 +1567,7 @@ opcode!(
15671567
sqe.addr_or_splice_off_in.msgring_cmd = IoringMsgringCmds::Data;
15681568
sqe.fd = ring_fd;
15691569
sqe.len.len = result as u32;
1570-
sqe.off_or_addr2.user_data = user_data.into();
1570+
sqe.off_or_addr2.user_data = user_data;
15711571
sqe.op_flags.msg_ring_flags = opcode_flags;
15721572
if let Some(_flags) = user_flags {
15731573
// TODO(lucab): add IORING_MSG_RING_FLAGS_PASS support (in v6.3):

src/register.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@ impl Restriction {
138138
Restriction(res)
139139
}
140140

141-
/// Allow the given [submission queue event flags](crate::squeue::Flags).
141+
/// Allow the given [submission queue event flags](crate::types::IoringSqeFlags).
142142
pub fn sqe_flags_allowed(flags: IoringSqeFlags) -> Restriction {
143143
let mut res = res_zeroed();
144144
res.opcode = IoringRestrictionOp::SqeFlagsAllowed as _;
145145
res.register_or_sqe_op_or_sqe_flags.sqe_flags = flags;
146146
Restriction(res)
147147
}
148148

149-
/// Require the given [submission queue event flags](crate::squeue::Flags). These flags must be
149+
/// Require the given [submission queue event flags](crate::types::IoringSqeFlags). These flags must be
150150
/// set on every submission.
151151
pub fn sqe_flags_required(flags: IoringSqeFlags) -> Restriction {
152152
let mut res = res_zeroed();

src/squeue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ impl<E: EntryMarker> Drop for SubmissionQueue<'_, E> {
236236
}
237237

238238
impl Entry {
239-
/// Set the submission event's [flags](Flags).
239+
/// Set the submission event's [flags](crate::types::IoringSqeFlags).
240240
#[inline]
241241
pub fn flags(mut self, flags: IoringSqeFlags) -> Entry {
242242
self.0.flags |= flags;
@@ -283,7 +283,7 @@ impl Debug for Entry {
283283
}
284284

285285
impl Entry128 {
286-
/// Set the submission event's [flags](Flags).
286+
/// Set the submission event's [flags](crate::types::IoringSqeFlags).
287287
#[inline]
288288
pub fn flags(mut self, flags: IoringSqeFlags) -> Entry128 {
289289
self.0 .0.flags |= flags;

src/types.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub struct Fixed(pub u32);
8484
/// let mut args = SubmitArgs::new();
8585
///
8686
/// {
87-
/// let ts = Timespec::new();
87+
/// let ts = Timespec { tv_sec: 1, tv_nsec: 0 };
8888
/// args = args.timespec(&ts);
8989
/// args = args.sigmask(&sigmask);
9090
/// }
@@ -313,6 +313,8 @@ impl<'buf> RecvMsgOut<'buf> {
313313
/// `buffer` is the whole buffer previously provided to the ring, while `msghdr`
314314
/// is the same content provided as input to the corresponding SQE
315315
/// (only `msg_namelen` and `msg_controllen` fields are relevant).
316+
// TODO: ignore clippy lint
317+
#[allow(clippy::result_unit_err)]
316318
pub fn parse(buffer: &'buf [u8], msghdr: &libc::msghdr) -> Result<Self, ()> {
317319
if buffer.len() < core::mem::size_of::<io_uring::io_uring_recvmsg_out>() {
318320
return Err(());

0 commit comments

Comments
 (0)