close() fds that have nothing more to read

This commit is contained in:
Qyriad 2026-03-19 21:39:11 +01:00
parent b11627d030
commit 16f2649334
3 changed files with 108 additions and 67 deletions

View file

@ -67,6 +67,10 @@ impl FdInfo {
self.name.get().unwrap_or_else(|| unreachable!())
}
pub fn display(&self) -> FdInfoDisplay<'_> {
FdInfoDisplay { inner: self }
}
}
impl IdOrdItem for FdInfo {
@ -79,6 +83,27 @@ impl IdOrdItem for FdInfo {
iddqd::id_upcast!();
}
#[derive(Debug)]
pub struct FdInfoDisplay<'a> {
inner: &'a FdInfo,
}
impl<'a> Display for FdInfoDisplay<'a> {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(
f,
"{} fd {} ({})",
self.inner.kind.name_str(),
self.inner.fd,
self.inner.name().to_string_lossy(),
)?;
if !self.inner.error_buffer.is_empty() {
write!(f, "; with errors: {}", self.inner.error_buffer.len())?;
}
Ok(())
}
}
#[derive(Copy)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive]