#[deprecated(since = "0.2.0", note = "Use IoUringReactor instead")]
pub type UringReactor = super::IoUringReactor;
#[must_use]
pub fn is_available() -> bool {
#[cfg(not(target_os = "linux"))]
{
false
}
#[cfg(target_os = "linux")]
{
linux_kernel_supports_uring() && !linux_io_uring_disabled()
}
}
#[cfg(target_os = "linux")]
fn linux_kernel_supports_uring() -> bool {
let Ok(release) = std::fs::read_to_string("/proc/sys/kernel/osrelease") else {
return false;
};
let mut parts = release
.trim()
.split(|c: char| !(c.is_ascii_digit() || c == '.'))
.next()
.unwrap_or_default()
.split('.');
let major = parts
.next()
.and_then(|v| v.parse::<u32>().ok())
.unwrap_or(0);
let minor = parts
.next()
.and_then(|v| v.parse::<u32>().ok())
.unwrap_or(0);
major > 5 || (major == 5 && minor >= 1)
}
#[cfg(target_os = "linux")]
fn linux_io_uring_disabled() -> bool {
match std::fs::read_to_string("/proc/sys/kernel/io_uring_disabled") {
Ok(raw) => raw.trim().parse::<u32>().is_ok_and(|flag| flag > 0),
Err(_) => false,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_is_available_platform_contract() {
#[cfg(not(target_os = "linux"))]
assert!(!is_available());
#[cfg(target_os = "linux")]
{
let _ = is_available();
}
}
#[allow(deprecated)]
#[test]
fn test_deprecated_type_alias_exists() {
fn _assert_alias_compiles(_: Option<UringReactor>) {}
}
}