Skip to content

Commit

Permalink
docs: add some doc
Browse files Browse the repository at this point in the history
Signed-off-by: lzzzt <[email protected]>
  • Loading branch information
Lzzzzzt committed Sep 21, 2024
1 parent da39670 commit e15bb1d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion monoio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ poll-io = ["tokio", "mio"]
# signal enables setting ctrl_c handler
signal = ["ctrlc", "sync"]
signal-termination = ["signal", "ctrlc/termination"]
# asyncify-op will run fs related task in blocking_thread_pool
# asyncify-op will run fs related task in blocking_thread_pool,
# this feature does not take effect when `iouring` is enabled.
asyncify-op = ["sync", "legacy"]
# by default both iouring and legacy are enabled
default = ["async-cancel", "bytes", "iouring", "legacy", "macros", "utils"]
Expand Down
17 changes: 11 additions & 6 deletions monoio/src/driver/op/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ use std::os::unix::prelude::AsRawFd;
pub(crate) use impls::*;
#[cfg(all(target_os = "linux", feature = "iouring"))]
use io_uring::{opcode, types};
#[cfg(all(windows, any(feature = "legacy", feature = "poll-io")))]
use {
std::ffi::c_void,
windows_sys::Win32::{Foundation::TRUE, Storage::FileSystem::ReadFile},
};

use super::{super::shared_fd::SharedFd, Op, OpAble};
#[cfg(any(feature = "legacy", feature = "poll-io"))]
Expand Down Expand Up @@ -315,21 +310,25 @@ pub(crate) mod impls {
use super::*;
use crate::syscall_u32;

/// A wrapper for [`libc::read`]
pub(crate) fn read(fd: i32, buf: *mut u8, len: usize) -> io::Result<u32> {
syscall_u32!(read(fd, buf as _, len))
}

/// A wrapper of [`libc::pread`]
pub(crate) fn read_at(fd: i32, buf: *mut u8, len: usize, offset: u64) -> io::Result<u32> {
let offset = libc::off_t::try_from(offset)
.map_err(|_| io::Error::new(io::ErrorKind::Other, "offset too big"))?;

syscall_u32!(pread(fd, buf as _, len, offset))
}

/// A wrapper of [`libc::readv`]
pub(crate) fn read_vectored(fd: i32, buf_vec: *mut iovec, len: usize) -> io::Result<u32> {
syscall_u32!(readv(fd, buf_vec as _, len as _))
}

/// A wrapper of [`libc::preadv`]
pub(crate) fn read_vectored_at(
fd: i32,
buf_vec: *mut iovec,
Expand All @@ -345,13 +344,17 @@ pub(crate) mod impls {

#[cfg(all(any(feature = "legacy", feature = "poll-io"), windows))]
pub(crate) mod impls {
use std::ffi::c_void;

use windows_sys::Win32::{
Foundation::{GetLastError, ERROR_HANDLE_EOF},
Foundation::{GetLastError, ERROR_HANDLE_EOF, TRUE},
Storage::FileSystem::ReadFile,
System::IO::OVERLAPPED,
};

use super::*;

/// A wrapper of [`windows_sys::Win32::Storage::FileSystem::ReadFile`]
pub(crate) fn read(handle: isize, buf: *mut u8, len: usize) -> io::Result<u32> {
let mut bytes_read = 0;
let ret = unsafe {
Expand All @@ -374,6 +377,8 @@ pub(crate) mod impls {
}
}

/// A wrapper of [`windows_sys::Win32::Storage::FileSystem::ReadFile`] and using the
/// [`windows_sys::Win32::System::IO::OVERLAPPED`] to read at specific position.
pub(crate) fn read_at(handle: isize, buf: *mut u8, len: usize, offset: u64) -> io::Result<u32> {
let mut bytes_read = 0;
let ret = unsafe {
Expand Down
5 changes: 5 additions & 0 deletions monoio/src/fs/file/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ mod asyncified {
asyncify_op!(read<IoBufMut>(read::read, IoBufMut::write_ptr, IoBufMut::bytes_total));
asyncify_op!(read_at<IoBufMut>(read::read_at, IoBufMut::write_ptr, IoBufMut::bytes_total, pos: u64));

/// The `readv` implement on windows.
///
/// Due to windows does not have syscall like `readv`, so we need to simulate it by ourself.
///
/// This function is just to fill each buffer by calling the `read` function.
pub(crate) async fn read_vectored<T: IoVecBufMut>(
fd: SharedFd,
mut buf_vec: T,
Expand Down

0 comments on commit e15bb1d

Please sign in to comment.