pub struct Fd(/* private fields */);Expand description
An owned file descriptor that closes on drop.
Fd is move-only. Constructing one from a raw descriptor transfers close
ownership to Fd; do not also close the raw descriptor elsewhere.
Implementations§
Source§impl Fd
impl Fd
Sourcepub unsafe fn from_owned_raw_fd(
fd: RawFd,
op: &'static str,
) -> Result<Self, CoreError>
pub unsafe fn from_owned_raw_fd( fd: RawFd, op: &'static str, ) -> Result<Self, CoreError>
Wrap an owned raw file descriptor.
§Safety
The caller must guarantee fd is valid, open, and uniquely owned by the
returned Fd. Passing a borrowed fd, or closing fd after this call,
can cause double-close or use-after-close bugs.
Sourcepub fn timerfd() -> Result<Self, CoreError>
pub fn timerfd() -> Result<Self, CoreError>
Create a non-blocking timerfd using CLOCK_MONOTONIC.
Sourcepub fn set_nonblock(&self) -> Result<(), CoreError>
pub fn set_nonblock(&self) -> Result<(), CoreError>
Set the O_NONBLOCK flag on the descriptor.
Sourcepub fn set_cloexec(&self) -> Result<(), CoreError>
pub fn set_cloexec(&self) -> Result<(), CoreError>
Set the FD_CLOEXEC flag on the descriptor.
Sourcepub fn read_slice(&self, buf: &mut [u8]) -> Result<Option<usize>, CoreError>
pub fn read_slice(&self, buf: &mut [u8]) -> Result<Option<usize>, CoreError>
Read bytes into a mutable slice.
Returns Ok(None) if the operation would block (EAGAIN).
Sourcepub fn write_slice(&self, buf: &[u8]) -> Result<Option<usize>, CoreError>
pub fn write_slice(&self, buf: &[u8]) -> Result<Option<usize>, CoreError>
Write bytes from a slice.
Returns Ok(None) if the operation would block (EAGAIN).
Sourcepub fn read_u64(&self) -> Result<Option<u64>, CoreError>
pub fn read_u64(&self) -> Result<Option<u64>, CoreError>
Read a native-endian u64.
Returns Ok(None) if the operation would block (EAGAIN).