Skip to content

Commit

Permalink
feat & refactor(!): Change Default Blocking Handle Behavior & Add Bas…
Browse files Browse the repository at this point in the history
…ic Read Op (#305)

* feat: finish basic read op

Signed-off-by: lzzzt <[email protected]>

ci: enable CI run test with legacy + sync

Signed-off-by: lzzzt <[email protected]>

* docs: add some doc

Signed-off-by: lzzzt <[email protected]>

* feat: Add baisc write op

Signed-off-by: Lzzzt <[email protected]>

* refactor: make clippy happy

Signed-off-by: Lzzzt <[email protected]>

---------

Signed-off-by: lzzzt <[email protected]>
Signed-off-by: Lzzzt <[email protected]>
  • Loading branch information
Lzzzzzt authored Oct 15, 2024
1 parent 687f921 commit 9bd5935
Show file tree
Hide file tree
Showing 18 changed files with 1,227 additions and 521 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ if [ "${NO_RUN}" != "1" ] && [ "${NO_RUN}" != "true" ]; then
"${CARGO}" test --target "${TARGET}" --no-default-features --features "async-cancel,bytes,legacy,macros,utils"
"${CARGO}" test --target "${TARGET}" --no-default-features --features "async-cancel,bytes,legacy,macros,utils" --release

# enable legacy and sync
"${CARGO}" test --target "${TARGET}" --no-default-features --features "async-cancel,bytes,legacy,macros,utils,sync"
"${CARGO}" test --target "${TARGET}" --no-default-features --features "async-cancel,bytes,legacy,macros,utils,sync" --release

if [ "${TARGET}" = "x86_64-unknown-linux-gnu" ] || [ "${TARGET}" = "i686-unknown-linux-gnu" ]; then
# only enabled uring driver
"${CARGO}" test --target "${TARGET}" --no-default-features --features "async-cancel,bytes,iouring,macros,utils"
Expand Down
2 changes: 1 addition & 1 deletion monoio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ windows-sys = { version = "0.48.0", features = [
"Win32_Networking_WinSock",
"Win32_System_IO",
"Win32_Storage_FileSystem",
"Win32_Security"
"Win32_Security",
] }

# unix dependencies
Expand Down
21 changes: 17 additions & 4 deletions monoio/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,29 @@ pub struct RuntimeBuilder<D> {
scoped_thread_local!(pub(crate) static BUILD_THREAD_ID: usize);

impl<T> Default for RuntimeBuilder<T> {
/// Create a default runtime builder
/// Create a default runtime builder.
///
/// # Note
///
/// When the sync feature is enabled, the default behavior of
/// [monoio::blocking::BlockingStrategy] is to execute tasks on the local thread. In other
/// words, there is no thread pool involved—all blocking I/O operations and heavy computations
/// will block the current thread.
#[must_use]
fn default() -> Self {
RuntimeBuilder::<T>::new()
}
}

impl<T> RuntimeBuilder<T> {
/// Create a default runtime builder
/// Create a default runtime builder.
///
/// # Note
///
/// When the sync feature is enabled, the default behavior of
/// [monoio::blocking::BlockingStrategy] is to execute tasks on the local thread. In other
/// words, there is no thread pool involved—all blocking I/O operations and heavy computations
/// will block the current thread.
#[must_use]
pub fn new() -> Self {
Self {
Expand All @@ -50,7 +64,7 @@ impl<T> RuntimeBuilder<T> {
urb: io_uring::IoUring::builder(),

#[cfg(feature = "sync")]
blocking_handle: crate::blocking::BlockingStrategy::Panic.into(),
blocking_handle: crate::blocking::BlockingStrategy::ExecuteLocal.into(),
_mark: PhantomData,
}
}
Expand Down Expand Up @@ -148,7 +162,6 @@ impl<D> RuntimeBuilder<D> {
/// inner `io_uring` API.
///
/// Refer to the [`io_uring::Builder`] documentation for all the supported methods.
#[cfg(all(target_os = "linux", feature = "iouring"))]
#[must_use]
pub fn uring_builder(mut self, urb: io_uring::Builder) -> Self {
Expand Down
5 changes: 2 additions & 3 deletions monoio/src/driver/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ use std::{
use crate::driver;

pub(crate) mod close;
pub(crate) mod read;
pub(crate) mod write;

mod accept;
mod connect;
mod fsync;
mod open;
mod poll;
mod read;
mod recv;
mod send;
mod write;

#[cfg(unix)]
mod statx;

Expand Down
Loading

0 comments on commit 9bd5935

Please sign in to comment.