Skip to content
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

Support vectored I/O #26

Merged
merged 13 commits into from
Jan 22, 2023
Prev Previous commit
Next Next commit
Add BufMutSlice trait
Mixure of BufMut and BufSlice, in other words read buffer for vectored
I/O.
  • Loading branch information
Thomasdezeeuw committed Jan 22, 2023
commit e935d3bbe020a7918461765cc76550cc7f63884f
30 changes: 30 additions & 0 deletions src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,36 @@ unsafe impl BufMut for Vec<u8> {
}
}

/// Trait that defines the behaviour of buffers used in reading using vectored
/// I/O, which requires mutable access.
///
/// # Safety
///
/// This has the same safety requirements as [`BufMut`], but then for all
/// buffers used.
pub unsafe trait BufMutSlice<const N: usize>: 'static {
/// Returns the reabable buffer as `iovec` structures.
///
/// # Safety
///
/// This has the same safety requirements as [`BufMut::parts`], but then for
/// all buffers used.
unsafe fn as_iovec(&mut self) -> [libc::iovec; N];

/// Mark `n` bytes as initialised.
///
/// # Safety
///
/// The caller must ensure that `n` bytes are initialised in the vectors
/// return by [`BufMutSlice::as_iovec`].
///
/// The implementation must ensure that that proper buffer(s) are
/// initialised. For example when this is called with `n = 10` with two
/// buffers of size `8` the implementation should initialise the first
/// buffer with `n = 8` and the second with `n = 10 - 8 = 2`.
unsafe fn set_init(&mut self, n: usize);
}

/// Trait that defines the behaviour of buffers used in writing, which requires
/// read only access.
///
Expand Down