Skip to content

chore: Update dependencies and fix clippy warnings #327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ keywords = ["async", "fs", "io-uring"]
tokio = { version = "1.2", features = ["net", "rt", "sync"] }
slab = "0.4.2"
libc = "0.2.80"
io-uring = "0.6.0"
socket2 = { version = "0.4.4", features = ["all"] }
io-uring = "0.7"
socket2 = { version = "0.5", features = ["all"] }
bytes = { version = "1.0", optional = true }
futures-util = { version = "0.3.26", default-features = false, features = ["std"] }

[dev-dependencies]
tempfile = "3.2.0"
tokio-test = "0.4.2"
iai = "0.1.1"
criterion = "0.4.0"
criterion = "0.5"
# we use joinset in our tests
tokio = "1.21.2"
nix = "0.26.1"
nix = "0.30"

[package.metadata.docs.rs]
all-features = true
Expand Down
19 changes: 13 additions & 6 deletions benches/lai/no_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use tokio::task::JoinSet;
#[derive(Clone)]
struct Options {
iterations: usize,
#[allow(dead_code)]
concurrency: usize,
sq_size: usize,
cq_size: usize,
Expand Down Expand Up @@ -60,20 +61,26 @@ fn no_op_x1() -> Result<(), Box<dyn std::error::Error>> {
}

fn no_op_x32() -> Result<(), Box<dyn std::error::Error>> {
let mut opts = Options::default();
opts.concurrency = 32;
let opts = Options {
concurrency: 32,
..Options::default()
};
run_no_ops(black_box(opts))
}

fn no_op_x64() -> Result<(), Box<dyn std::error::Error>> {
let mut opts = Options::default();
opts.concurrency = 64;
let opts = Options {
concurrency: 64,
..Options::default()
};
run_no_ops(black_box(opts))
}

fn no_op_x256() -> Result<(), Box<dyn std::error::Error>> {
let mut opts = Options::default();
opts.concurrency = 256;
let opts = Options {
concurrency: 256,
..Options::default()
};
run_no_ops(black_box(opts))
}

Expand Down
6 changes: 3 additions & 3 deletions examples/tcp_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() {

use tokio_uring::buf::BoundedBuf; // for slice()

println!("{} connected", socket_addr);
println!("{socket_addr} connected");
let mut n = 0;

let mut buf = vec![0u8; 4096];
Expand All @@ -33,14 +33,14 @@ fn main() {
buf = nbuf;
let read = result.unwrap();
if read == 0 {
println!("{} closed, {} total ping-ponged", socket_addr, n);
println!("{socket_addr} closed, {n} total ping-ponged");
break;
}

let (res, slice) = stream.write_all(buf.slice(..read)).await;
res.unwrap();
buf = slice.into_inner();
println!("{} all {} bytes ping-ponged", socket_addr, read);
println!("{socket_addr} all {read} bytes ping-ponged");
n += read;
}
});
Expand Down
10 changes: 5 additions & 5 deletions examples/tcp_listener_fixed_buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn accept_loop(listen_addr: SocketAddr) {
);

// Other iterators may be passed to FixedBufRegistry::new also.
let registry = FixedBufRegistry::new(iter::repeat(vec![0; 4096]).take(POOL_SIZE));
let registry = FixedBufRegistry::new(iter::repeat_n(vec![0; 4096], POOL_SIZE));

// Register the buffers with the kernel, asserting the syscall passed.

Expand All @@ -55,7 +55,7 @@ async fn echo_handler<T: IoBufMut>(
peer: SocketAddr,
registry: FixedBufRegistry<T>,
) {
println!("peer {} connected", peer);
println!("peer {peer} connected");

// Get one of the two fixed buffers.
// If neither is unavailable, print reason and return immediately, dropping this connection;
Expand All @@ -68,7 +68,7 @@ async fn echo_handler<T: IoBufMut>(
};
if fbuf.is_none() {
let _ = stream.shutdown(std::net::Shutdown::Write);
println!("peer {} closed, no fixed buffers available", peer);
println!("peer {peer} closed, no fixed buffers available");
return;
};

Expand All @@ -90,13 +90,13 @@ async fn echo_handler<T: IoBufMut>(
let (res, nslice) = stream.write_fixed_all(fbuf1.slice(..read)).await;

res.unwrap();
println!("peer {} all {} bytes ping-ponged", peer, read);
println!("peer {peer} all {read} bytes ping-ponged");
n += read;

// Important. One of the points of this example.
nslice.into_inner() // Return the buffer we started with.
};
}
let _ = stream.shutdown(std::net::Shutdown::Write);
println!("peer {} closed, {} total ping-ponged", peer, n);
println!("peer {peer} closed, {n} total ping-ponged");
}
26 changes: 9 additions & 17 deletions examples/test_create_dir_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@ async fn main1() -> io::Result<()> {
if unexpected == 0 {
Ok(())
} else {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!("{unexpected} unexpected result(s)"),
))
Err(std::io::Error::other(format!(
"{unexpected} unexpected result(s)"
)))
}
}

Expand Down Expand Up @@ -208,10 +207,9 @@ async fn matches_mode<P: AsRef<Path>>(path: P, want_mode: u16) -> io::Result<()>
if want_mode == got_mode {
Ok(())
} else {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
format!("want mode {want_mode:#o}, got mode {got_mode:#o}"),
))
Err(std::io::Error::other(format!(
"want mode {want_mode:#o}, got mode {got_mode:#o}"
)))
}
}

Expand All @@ -231,10 +229,7 @@ async fn is_regfile<P: AsRef<Path>>(path: P) -> io::Result<()> {
if is_regfile {
Ok(())
} else {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
"not regular file",
))
Err(std::io::Error::other("not regular file"))
}
}

Expand All @@ -244,17 +239,14 @@ async fn is_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
if is_dir {
Ok(())
} else {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
"not directory",
))
Err(std::io::Error::other("not directory"))
}
}

fn main() {
tokio_uring::start(async {
if let Err(e) = main1().await {
println!("error: {}", e);
println!("error: {e}");
}
});
}
2 changes: 1 addition & 1 deletion examples/wrk-bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn main() -> io::Result<()> {
let (result, _) = stream.write(RESPONSE).submit().await;

if let Err(err) = result {
eprintln!("Client connection failed: {}", err);
eprintln!("Client connection failed: {err}");
}
});
}
Expand Down
7 changes: 2 additions & 5 deletions src/fs/create_dir_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl DirBuilder {
// recursion when only the first level of the directory needs to be built. For now, this serves
// its purpose.

fn recurse_create_dir_all<'a>(&'a self, path: &'a Path) -> LocalBoxFuture<io::Result<()>> {
fn recurse_create_dir_all<'a>(&'a self, path: &'a Path) -> LocalBoxFuture<'a, io::Result<()>> {
Box::pin(async move {
if path == Path::new("") {
return Ok(());
Expand All @@ -139,10 +139,7 @@ impl DirBuilder {
match path.parent() {
Some(p) => self.recurse_create_dir_all(p).await?,
None => {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
"failed to create whole tree",
));
return Err(std::io::Error::other("failed to create whole tree"));
/* TODO build own allocation free error some day like the std library does.
return Err(io::const_io_error!(
io::ErrorKind::Uncategorized,
Expand Down
2 changes: 1 addition & 1 deletion src/io/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl Completable for Accept {
let fd = SharedFd::new(fd as i32);
let socket = Socket { fd };
let (_, addr) = unsafe {
socket2::SockAddr::init(move |addr_storage, len| {
socket2::SockAddr::try_init(move |addr_storage, len| {
self.socketaddr.0.clone_into(&mut *addr_storage);
*len = self.socketaddr.1;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/io/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod test {
use crate as tokio_uring;

#[test]
fn perform_no_op() -> () {
fn perform_no_op() {
tokio_uring::start(async {
tokio_uring::no_op().await.unwrap();
})
Expand Down
2 changes: 1 addition & 1 deletion src/io/recv_from.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<T: BoundedBufMut> Op<RecvFrom<T>> {
std::slice::from_raw_parts_mut(buf.stable_mut_ptr(), buf.bytes_total())
})];

let socket_addr = Box::new(unsafe { SockAddr::init(|_, _| Ok(()))?.1 });
let socket_addr = Box::new(unsafe { SockAddr::try_init(|_, _| Ok(()))?.1 });

let mut msghdr: Box<libc::msghdr> = Box::new(unsafe { std::mem::zeroed() });
msghdr.msg_iov = io_slices.as_mut_ptr().cast();
Expand Down
2 changes: 1 addition & 1 deletion src/io/recvmsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<T: BoundedBufMut> Op<RecvMsg<T>> {
}));
}

let socket_addr = Box::new(unsafe { SockAddr::init(|_, _| Ok(()))?.1 });
let socket_addr = Box::new(unsafe { SockAddr::try_init(|_, _| Ok(()))?.1 });

let mut msghdr: Box<libc::msghdr> = Box::new(unsafe { std::mem::zeroed() });
msghdr.msg_iov = io_slices.as_mut_ptr().cast();
Expand Down
8 changes: 7 additions & 1 deletion src/io/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
use std::{
io,
net::SocketAddr,
os::unix::io::{AsRawFd, IntoRawFd, RawFd},
os::unix::io::{AsFd, AsRawFd, BorrowedFd, IntoRawFd, RawFd},
path::Path,
};

Expand Down Expand Up @@ -285,3 +285,9 @@ impl AsRawFd for Socket {
self.fd.raw_fd()
}
}

impl AsFd for Socket {
fn as_fd(&self) -> BorrowedFd<'_> {
unsafe { BorrowedFd::borrow_raw(self.fd.raw_fd()) }
}
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
//! call `close()`.

#![warn(missing_docs)]
#![allow(clippy::thread_local_initializer_can_be_made_const)]
#![allow(clippy::missing_const_for_thread_local)]

macro_rules! syscall {
($fn: ident ( $($arg: expr),* $(,)* ) ) => {{
Expand Down
5 changes: 2 additions & 3 deletions src/net/tcp/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,8 @@ impl TcpListener {
pub async fn accept(&self) -> io::Result<(TcpStream, SocketAddr)> {
let (socket, socket_addr) = self.inner.accept().await?;
let stream = TcpStream { inner: socket };
let socket_addr = socket_addr.ok_or_else(|| {
io::Error::new(io::ErrorKind::Other, "Could not get socket IP address")
})?;
let socket_addr =
socket_addr.ok_or_else(|| io::Error::other("Could not get socket IP address"))?;
Ok((stream, socket_addr))
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/runtime/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,7 @@ impl Driver {
return Ok(());
}
}
Err(io::Error::new(
io::ErrorKind::Other,
Err(io::Error::other(
"fixed buffers are not currently registered",
))
}
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/driver/op/slab_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<'a, T> SlabList<'a, T> {
}
}

impl<'a, T> Drop for SlabList<'a, T> {
impl<T> Drop for SlabList<'_, T> {
fn drop(&mut self) {
while !self.is_empty() {
let removed = self.slab.remove(self.index.start);
Expand All @@ -120,7 +120,7 @@ impl<'a, T> Drop for SlabList<'a, T> {
}
}

impl<'a, T> Iterator for SlabList<'a, T> {
impl<T> Iterator for SlabList<'_, T> {
type Item = T;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ mod test {
#[test]
fn block_on() {
let rt = Runtime::new(&builder()).unwrap();
rt.block_on(async move { () });
rt.block_on(async move {});
}

#[test]
fn block_on_twice() {
let rt = Runtime::new(&builder()).unwrap();
rt.block_on(async move { () });
rt.block_on(async move { () });
rt.block_on(async move {});
rt.block_on(async move {});
}
}
2 changes: 1 addition & 1 deletion tests/fixed_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ fn pool_next_as_concurrency_limit() {
mem::drop(file);
let mut content = String::new();
tempfile.read_to_string(&mut content).unwrap();
println!("{}", content);
println!("{content}");
})
}

Expand Down
Loading