Skip to content

Commit 37780fa

Browse files
committed
examples,README: Expect cqueue::Entry::result() to be Result<u32>
1 parent 726fb98 commit 37780fa

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn main() -> io::Result<()> {
4747
let cqe = ring.completion().next().expect("completion queue is empty");
4848

4949
assert_eq!(cqe.user_data(), 0x42);
50-
assert!(cqe.result() >= 0, "read error: {}", cqe.result());
50+
let _bytes_read = cqe.result().expect("read error");
5151

5252
Ok(())
5353
}

examples/readme.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn main() -> io::Result<()> {
2525
let cqe = ring.completion().next().expect("completion queue is empty");
2626

2727
assert_eq!(cqe.user_data(), 0x42);
28-
assert!(cqe.result() >= 0, "read error: {}", cqe.result());
28+
let _bytes_read = cqe.result().expect("read error");
2929

3030
Ok(())
3131
}

examples/tcp_echo.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::collections::VecDeque;
22
use std::net::TcpListener;
33
use std::os::unix::io::{AsRawFd, RawFd};
4-
use std::{io, ptr};
4+
use std::ptr;
55

66
use io_uring::{opcode, squeue, types, IoUring, SubmissionQueue};
77
use slab::Slab;
@@ -100,17 +100,15 @@ fn main() -> anyhow::Result<()> {
100100
accept.push_to(&mut sq);
101101

102102
for cqe in &mut cq {
103-
let ret = cqe.result();
104103
let token_index = cqe.user_data() as usize;
105104

106-
if ret < 0 {
107-
eprintln!(
108-
"token {:?} error: {:?}",
109-
token_alloc.get(token_index),
110-
io::Error::from_raw_os_error(-ret)
111-
);
112-
continue;
113-
}
105+
let ret = match cqe.result() {
106+
Ok(x) => x,
107+
Err(e) => {
108+
eprintln!("token {:?} error: {e:?}", token_alloc.get(token_index),);
109+
continue;
110+
}
111+
};
114112

115113
let token = &mut token_alloc[token_index];
116114
match token.clone() {
@@ -119,7 +117,7 @@ fn main() -> anyhow::Result<()> {
119117

120118
accept.count += 1;
121119

122-
let fd = ret;
120+
let fd = ret as i32;
123121
let poll_token = token_alloc.insert(Token::Poll { fd });
124122

125123
let poll_e = opcode::PollAdd::new(types::Fd(fd), libc::POLLIN as _)

0 commit comments

Comments
 (0)