1
0
Fork 0
forked from wry/wry
wry/src/utils/nonblock.rs
2024-10-19 08:58:29 +02:00

13 lines
361 B
Rust

use {crate::utils::oserror::OsError, uapi::c};
pub fn set_nonblock(fd: c::c_int) -> Result<(), OsError> {
let fl = uapi::fcntl_getfl(fd)?;
uapi::fcntl_setfl(fd, fl | c::O_NONBLOCK)?;
Ok(())
}
pub fn set_block(fd: c::c_int) -> Result<(), OsError> {
let fl = uapi::fcntl_getfl(fd)?;
uapi::fcntl_setfl(fd, fl & !c::O_NONBLOCK)?;
Ok(())
}