use std::ffi::CString;
use std::os::fd::RawFd;
use wireshift_core::op::OpDescriptor;
pub(crate) enum InflightData {
None,
Path(CString),
Statx {
path: CString,
statx_buf: Box<libc::statx>,
},
Iovec(Vec<libc::iovec>),
Sockaddr {
socket_fd: RawFd,
#[allow(dead_code)]
storage: Box<libc::sockaddr_storage>,
#[allow(dead_code)]
addr_len: libc::socklen_t,
},
Linked(Vec<InflightData>),
}
impl std::fmt::Debug for InflightData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::None => write!(f, "None"),
Self::Path(p) => write!(f, "Path({p:?})"),
Self::Statx { path, .. } => write!(f, "Statx({path:?})"),
Self::Iovec(v) => write!(f, "Iovec(len={})", v.len()),
Self::Sockaddr { socket_fd, .. } => write!(f, "Sockaddr(fd={socket_fd})"),
Self::Linked(items) => write!(f, "Linked(len={})", items.len()),
}
}
}
impl Drop for InflightData {
fn drop(&mut self) {
if let Self::Sockaddr { socket_fd, .. } = self {
if *socket_fd >= 0 {
unsafe {
libc::close(*socket_fd);
}
}
}
}
}
#[derive(Debug)]
pub(crate) struct Inflight {
pub id: u64,
pub descriptor: OpDescriptor,
pub pinned: InflightData,
pub expected_cqes: usize,
pub results: Vec<i32>,
}