Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions compio-driver/src/sys/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,36 @@ impl Extra {
))
}
}

/// Checks whether the underlying socket has more data to be read.
///
/// # Behaviour
///
/// This method must be used only on the flags for any of the `receive`
/// variants supported by `IO_URING`.
/// The driver will try to check whether the `IORING_CQE_F_SOCK_NONEMPTY`
/// flag was set by the kernel for the CQE. On other platforms, this will
/// always return the [`Unsupported`] error.
///
/// [`Unsupported`]: io::ErrorKind::Unsupported
pub fn sock_nonempty(&self) -> io::Result<bool> {
#[cfg(io_uring)]
{
if let Some(extra) = self.try_as_iour() {
Ok(extra.sock_nonempty())
} else {
Err(io::Error::new(
io::ErrorKind::Unsupported,
"IORING_CQE_F_SOCK_NONEMPTY flag is available only on the io_uring driver",
))
}
}
#[cfg(not(io_uring))]
{
Err(io::Error::new(
io::ErrorKind::Unsupported,
"IORING_CQE_F_SOCK_NONEMPTY flag is available only on the io_uring driver",
))
}
}
}
4 changes: 4 additions & 0 deletions compio-driver/src/sys/iour/extra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl Extra {
pub fn buffer_id(&self) -> Option<u16> {
io_uring::cqueue::buffer_select(self.flags)
}

pub fn sock_nonempty(&self) -> bool {
io_uring::cqueue::sock_nonempty(self.flags)
}
}

#[allow(dead_code)]
Expand Down