Skip to content

Commit 50470ef

Browse files
authored
feat(driver): add Extra::needs_polling (#857)
1 parent 8dff845 commit 50470ef

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

compio-driver/src/sys/extra.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,36 @@ impl Extra {
9696
))
9797
}
9898
}
99+
100+
/// Checks whether the underlying socket has more data to be read.
101+
///
102+
/// # Behaviour
103+
///
104+
/// This method must be used only on the flags for any of the `receive`
105+
/// variants supported by `IO_URING`.
106+
/// The driver will try to check whether the `IORING_CQE_F_SOCK_NONEMPTY`
107+
/// flag was set by the kernel for the CQE. On other platforms, this will
108+
/// always return the [`Unsupported`] error.
109+
///
110+
/// [`Unsupported`]: io::ErrorKind::Unsupported
111+
pub fn sock_nonempty(&self) -> io::Result<bool> {
112+
#[cfg(io_uring)]
113+
{
114+
if let Some(extra) = self.try_as_iour() {
115+
Ok(extra.sock_nonempty())
116+
} else {
117+
Err(io::Error::new(
118+
io::ErrorKind::Unsupported,
119+
"IORING_CQE_F_SOCK_NONEMPTY flag is available only on the io_uring driver",
120+
))
121+
}
122+
}
123+
#[cfg(not(io_uring))]
124+
{
125+
Err(io::Error::new(
126+
io::ErrorKind::Unsupported,
127+
"IORING_CQE_F_SOCK_NONEMPTY flag is available only on the io_uring driver",
128+
))
129+
}
130+
}
99131
}

compio-driver/src/sys/iour/extra.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ impl Extra {
2424
pub fn buffer_id(&self) -> Option<u16> {
2525
io_uring::cqueue::buffer_select(self.flags)
2626
}
27+
28+
pub fn sock_nonempty(&self) -> bool {
29+
io_uring::cqueue::sock_nonempty(self.flags)
30+
}
2731
}
2832

2933
#[allow(dead_code)]

0 commit comments

Comments
 (0)