Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod file;
pub use file::remove_file;
pub use file::rename;
pub use file::File;
pub use file::OpFlags;

mod open_options;
pub use open_options::OpenOptions;
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ pub mod fs;
pub mod net;

pub use io::write::*;
pub use runtime::driver::op::{InFlightOneshot, OneshotOutputTransform, UnsubmittedOneshot};
pub use runtime::driver::op::{
InFlightOneshot, OneshotOutputTransform, OpFlags, UnsubmittedOneshot,
};
pub use runtime::spawn;
pub use runtime::Runtime;

Expand Down
45 changes: 45 additions & 0 deletions src/runtime/driver/op/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ impl<D, T: OneshotOutputTransform<StoredData = D>> UnsubmittedOneshot<D, T> {

InFlightOneshot { inner: Some(inner) }
}

pub unsafe fn set_flags(&mut self, flags: OpFlags) {
self.sqe.flags(flags.into());
}
}

/// An in-progress oneshot operation which can be polled for completion.
Expand Down Expand Up @@ -316,3 +320,44 @@ impl Lifecycle {
}
}
}

/// A set of flags to pass to `io_uring` along with the operation
///
/// For each flag, there are `with_FLAG`, `no_FLAG` and `is_FLAG` methods
/// for setting, clearing and checking the flag respectively.
///
/// The flags are:
///
/// * `async` - corresponds to `IOSQE_ASYNC` flag of `io_uring_enter`.
/// See `io_uring_enter(2)` man page for details.
#[derive(Clone, Copy, Default)]
pub struct OpFlags(u8);

impl OpFlags {
const ASYNC: u8 = 1;

/// Sets async flag on the object and returns it
pub fn with_async(self) -> Self {
Self(self.0 | Self::ASYNC)
}

/// Clears async flag on the object and returns it
pub fn no_async(self) -> Self {
Self(self.0 & !Self::ASYNC)
}

/// Checks if the object has async flag set
pub fn is_async(&self) -> bool {
self.0 & Self::ASYNC != 0
}
}

impl From<OpFlags> for io_uring::squeue::Flags {
fn from(value: OpFlags) -> Self {
let mut flags = Self::empty();
if value.is_async() {
flags |= Self::ASYNC;
}
flags
}
}