tokio-rs / io-uring

The `io_uring` library for Rust
Apache License 2.0
1.19k stars 131 forks source link

Make `Submitter::register_buffers` to accept `IoSlice{Mut}` #259

Open sanmai-NL opened 8 months ago

sanmai-NL commented 8 months ago

IoSlice and IoSliceMut are in the standard library. See: https://github.com/nix-rust/nix/pull/1643 for some background.

io-uring's Submitter::register_buffers uses a libc::iovec.

I propose to adopt the standard library type in order to increase API compatibility.

quininer commented 8 months ago

Welcome PR.

connortsui20 commented 6 months ago

I'm willing to make this PR and do some testing.

But which of IoSlice and IoSliceMut should replace libc::iovec? Or should both be supported? The more obvious answer to me is only accepting IoSliceMut since if we want to share these buffers with the kernel we probably can't easily make the guarantee that there are no shared references to the underlying slice. On the other hand, this is marked unsafe so it could be okay?

connortsui20 commented 6 months ago

All that needs to change is this if we only accept IoSliceMut:

pub unsafe fn register_buffers(&self, bufs: &[libc::iovec]) -> io::Result<()> {
// into
pub unsafe fn register_buffers(&self, bufs: &[IoSliceMut<'_>]) -> io::Result<()> {

Simply doing that and converting the iovec into IoSliceMut in the test_tcp_zero_copy_send_fixed test (plus the test that I wrote in #278) passes. Though to be clear those are the only tests that test register_buffers.