workflow_core/
fd.rs

1//! Module for the file descriptor limit management.
2
3///
4#[cfg(not(target_arch = "wasm32"))]
5pub fn try_set_fd_limit(limit: u64) -> std::io::Result<u64> {
6    cfg_if::cfg_if! {
7        if #[cfg(target_os = "windows")] {
8                rlimit::setmaxstdio(limit as u32).map(|v| v as u64)
9        } else if #[cfg(unix)] {
10            rlimit::increase_nofile_limit(limit)
11        }
12    }
13}
14
15pub fn limit() -> std::io::Result<i32> {
16    cfg_if::cfg_if! {
17        if #[cfg(target_os = "windows")] {
18            Ok(rlimit::getmaxstdio() as i32)
19        }
20        else if #[cfg(unix)] {
21            Ok(rlimit::getrlimit(rlimit::Resource::NOFILE).unwrap().0 as i32)
22        }
23        else {
24            Err(std::io::Error::new(std::io::ErrorKind::Other, "Unsupported platform: file descriptor limit is not available"))
25        }
26    }
27}